10 Replies - 3852 Views - Last Post: 27 May 2012 - 02:27 PM Rate Topic: -----

#1 slagusev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-May 12

How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 04:01 AM

The problem with the editor, help a newbie in C #. I write to the editor using ScintillaNET and dockPanel. The problem with the items: save and save as. How to realize these opportunities?

Used the example of SCide, but there in the open file when you press save, save as dialog box pops up. Although the actions spelled correctly
Is This A Good Question/Topic? 0
  • +

Replies To: How Do I Save (Scintillanet And Dockpanel)

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,843
  • Joined: 02-June 10

Re: How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 06:35 AM

Are you asking "How do I save and load my document?"

If not, you need to have someone else translate your question for you because this doesn't make much sense in English.

Writing a text file tutorial.
Reading a text file tutorial.
Was This Post Helpful? 0
  • +
  • -

#3 slagusev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-May 12

Re: How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 08:47 AM

Yes, it is impossible to make saving and loading a file using a file of these components. Maybe someone knows the editors of open source where you can peep this functionality
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,843
  • Joined: 02-June 10

Re: How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 09:01 AM

A DockPanel doesn't have a document.
So that doesn't add to this description.

What exactly is the problem?

You have a document.
You feed it to the ScintillaNET component.

There seems to be plenty of documentation on the Documentation page for this component.
http://www.scintilla...intillaDoc.html

What have you tried so far? Let's see your code.
Was This Post Helpful? 0
  • +
  • -

#5 slagusev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-May 12

Re: How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 11:36 AM

Form 1
/*
 * Сделано в SharpDevelop.
 * Пользователь: GreenGoByte
 * Дата: 24.05.2012
 * Время: 23:50
 * 
 * Для изменения этого шаблона используйте Сервис | Настройка | Кодирование | Правка стандартных заголовков.
 */
using System;
using System.Globalization;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;
using System.IO;
using WeifenLuo.WinFormsUI.Docking;
using ScintillaNET;

namespace LPad
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
    /// 
	public sealed partial class MainForm : Form
	{
        private string[] _args;

        private ScriptEditor NewDocument()
        {
            ScriptEditor E = new ScriptEditor();
            E.Show(dockPanel1);
            return E;
        }

        private void OpenFile()
        {
            openFileDialog.Filter = "lua | *.lua";
            if (openFileDialog.ShowDialog() != DialogResult.OK)
                return;

            foreach (string filePath in openFileDialog.SafeFileNames)
            {
                bool isOpen = false;
                foreach (ScriptEditor E in dockPanel1.Documents)
                {
                    if (filePath.Equals(E.filePath, StringComparison.OrdinalIgnoreCase))
                    {
                        E.Select();
                        isOpen = true;
                        break;
                    }
                }
                if (!isOpen)
                    OpenFile(filePath);
            }
        }

        private ScriptEditor OpenFile(string filePath)
        {
            ScriptEditor E = new ScriptEditor();
            E.scintilla1.Text = File.ReadAllText(filePath);
            E.TabText = Path.GetFileName(filePath);
            E.scintilla1.UndoRedo.EmptyUndoBuffer();
            E.scintilla1.Modified = false;
            E.Text = Path.GetFileName(filePath);
            E.filePath = filePath;
            E.Show(dockPanel1);
            return E;
        }

        public ScriptEditor ActiveDocument
        {
            get
            {
                return dockPanel1.ActiveDocument as ScriptEditor;
            }
        }

		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		private void NewScript()
		{
		ScriptEditor E = new ScriptEditor();
		E.DockPanel = dockPanel1;
		E.Show();
		}
		
		void MainFormLoad(object sender, EventArgs e)
		{
            if (_args != null && _args.Length != 0)
            {
            FileInfo fi = new FileInfo(_args[0]);
                if (fi.Exists)
                    OpenFile(fi.FullName);
            }
            else
            {
                NewDocument();
            }
		}
		
		void ExitBtnClick(object sender, EventArgs e)
		{
			Close();
		}
		
		void RunBtnClick(object sender, EventArgs e)
		{
			
		}
		
		void BuilderBtnClick(object sender, EventArgs e)
		{
			(new Packer()).ShowDialog();
		}
		
		void NewBtnClick(object sender, EventArgs e)
		{
			NewScript();
		}
		
		void OpenBtnClick(object sender, System.EventArgs e)
		{
            OpenFile();
		}

        private void BtnUndo_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
                Activedocument.scintilla1.UndoRedo.Undo();
        }

        private void toolStripMenuItem6_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
                Activedocument.Close();
        }

        private void dockPanel1_ActiveContentChanged(object sender, EventArgs e)
        {

        }

        private void BtnRedo_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
                Activedocument.scintilla1.UndoRedo.Redo();
        }

        private void CutBtn_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
                Activedocument.scintilla1.Clipboard.Cut();
        }

        private void CopyBtn_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
                Activedocument.scintilla1.Clipboard.Copy();
        }

        private void PasteBtn_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
                Activedocument.scintilla1.Clipboard.Paste();
        }

        private void SaveBtn_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
                Activedocument.Save();
        }

        private void SaveAsBtn_Click(object sender, EventArgs e)
        {
            if (ActiveDocument != null)
                Activedocument.SaveAs();
        }

        private void MasterConfBtn_Click(object sender, EventArgs e)
        {
            (new masterConfig()).ShowDialog();
        }
		
	}
	
}



Form 2 (With component ScintillaNET)
/*
 * Сделано в SharpDevelop.
 * Пользователь: GreenGoByte
 * Дата: 25.05.2012
 * Время: 12:30
 * 
 * Для изменения этого шаблона используйте Сервис | Настройка | Кодирование | Правка стандартных заголовков.
 */
using System;
using System.Globalization;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.IO;
using ScintillaNET;

namespace LPad
{
	/// <summary>
	/// Description of ScriptEditor.
	/// </summary>
    /// 
	public sealed partial class ScriptEditor : DockContent 
	{
        private string _filePath;

        public bool Save()
        {
            if (String.IsNullOrEmpty(_filePath))
            {
                return SaveAs();
            }
                return Save(_filePath);
        }

        public bool Save(string filePath)
        {
            using (FileStream fs = File.Create(filePath))
            using (BinaryWriter bw = new BinaryWriter(fs))
                bw.Write(scintilla1.RawText, 0, scintilla1.Text.Length - 1);
            scintilla1.Modified = false;
            return true;
        }

        public bool SaveAs()
        {
            saveFileDialog1.Filter = "lua | *.lua";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                _filePath = saveFileDialog1.FileName;
                return Save(_filePath);
            }
            return false;
        }

        public string filePath
        {
            get { return _filePath; }
            set { _filePath = value; }
        }

        //public Scintilla Scintilla
        //{
            //get
            //{
               // return scintilla1;
            //}
        //}
		
		void ScriptEditorLoad(object sender, EventArgs e)
		{
			scintilla1.Margins[0].Width = 20;
            scintilla1.Margins[2].Width = 20;
            scintilla1.Folding.IsEnabled = true;
            scintilla1.Folding.UseCompactFolding = true;

            scintilla1.AutoComplete.SingleLineAccept = false;
            scintilla1.AutoComplete.IsCaseSensitive = true;
            scintilla1.AutoComplete.DropRestOfWord = true;
            scintilla1.AutoComplete.AutoHide = false;
            scintilla1.AutoComplete.AutomaticLengthEntered = true;
            scintilla1.Caret.HighlightCurrentLine = true;
            //scintilla1.AutoComplete.List = new List<string>() { "function", "end" };
		}

        List<string> keywordList1 = new List<string>() ;
        List<string> keywordList2 = new List<string>() ;
        List<string> keywordListAll = new List<string>() {"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if",
        "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while", "love", "draw", "focus", "joystickpressed", "joystickreleased", "keypressed", "keyreleased", "load", "mousepressed", "mousereleased",
         "quit", "run", "update", "audio", "getNumSources", "getOrientation", "getPosition", "getVelocity", "getVolume", "newSource", "pause", "play", "resume", "rewind", "setOrientation", "setPosition", "setVelocity", "setVolume", "stop", "event", "poll", "pump", "push", "wait", "filesystem", "enumerate", "exists", "getAppdataDirectory", "getSaveDirectory", "getUserDirectory", "getWorkingDirectory", "init",
         "isDirectory", "isFile", "lines", "load", "mkdir", "newFile", "newFileData", "read", "remove", "setIdentity", "setSource", "write", "font", "newFontData", "newGlyphData", "newRasterizer", "graphics", "checkMode", "circle", "clear", "draw", "drawq", "getBackgroundColor", "getBlendMode", "getCaption", "getColor", "getColorMode", "getFont", "getHeight", "getLineStipple", "getLineStyle", "getLineWidth",
         "getMaxPointSize", "getModes", "getPointSize", "getPointStyle", "getScissor", "getWidth", "isCreated", "line", "newFont", "newFramebuffer", "newImage", "newImageFont", "newParticleSystem", "newQuad", "newScreenshot", "newSpriteBatch", "point", "polygon", "pop", "present", "print", "printf", "push", "rectangle", "reset", "rotate", "scale", "setBackgroundColor", "setBlendMode", "setCaption", "setColor", "setColorMode",
         "setFont", "setIcon", "setLine", "setLineStipple", "setLineStyle", "setLineWidth", "setMode", "setPoint", "setPointSize", "setPointStyle", "setRenderTarget", "setScissor", "toggleFullscreen", "translate", "triangle", "image", "newEncodedImageData", "newImageData", "joystick", "close", "getAxes", "getAxis", "getBall", "getHat", "getName", "getNumAxes", "getNumBalls", "getNumButtons", "getNumHats", "getNumJoysticks", "isDown", "isOpen", 
         "open", "keyboard", "getKeyRepeat", "setKeyRepeat", "mouse", "getX", "getY", "isGrabbed", "isVisible", "setGrab", "setVisible", "physics", "newBody", "newCircleShape", "newDistanceJoint", "newGearJoint", "newMouseJoint", "newPolygonShape", "newPrismaticJoint", "newPulleyJoint", "newRectangleShape", "newRevoluteJoint", "newWorld", "sound", "newDecoder", "newSoundData", "thread", "getThread", "getThreads", "newThread", "timer", "getDelta",
        "getFPS", "getMicroTime", "getTime", "sleep", "step", "Data", "Object"};

        public List<string> keywords1
        {
            set { this.keywordList1 = value; UpdateKeywords (); }
            get
            {
                return this.keywordList1;
            }
        }

        public List<string> keywords2
        {
            set { this.keywordList2 = value; UpdateKeywords (); }
            get
            {
                return this.keywordList2;
            }
        }

        private void UpdateKeywords()
        {
            this.keywordListAll = new List<string>(this.keywordList1);
            this.keywordListAll.AddRange(this.keywordList2);
            keywordListAll.Sort();
            scintilla1.Lexing.Keywords[0] = String.Join(" ", keywordList1.ToArray());
            scintilla1.Lexing.Keywords[1] = String.Join(" ", keywordList2.ToArray());
        }
        

            public void GotoLine(int line)
            {
                scintilla1.NativeInterface.GotoLine(Math.Max(0, line - 1)); //zero-based
            }
		
		public ScriptEditor()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}

        private void scintilla1_CharAdded(object sender, ScintillaNET.CharAddedEventArgs e)
        {
            if (e.Ch == ' ')
                return;
            int pos = scintilla1.NativeInterface.GetCurrentPos();
            string word = scintilla1.GetWordFromPosition(pos);
            if (word == string.Empty)
                return;
            List<string> list = keywordListAll.FindAll(item => item.StartsWith(word));
            if (list.Count > 0)
                scintilla1.AutoComplete.Show(list);
            else
                scintilla1.AutoComplete.Cancel();
        }

        private void scintilla1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control)
            {
                if (e.KeyCode == Keys.D1)
                    scintilla1.Snippets.ShowSnippetList();
            }
        }
		
	}
}



I do not work features: save and save as ((
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,843
  • Joined: 02-June 10

Re: How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 12:17 PM

When you said "DockPanel" I assumed you were building in WPF. I did not realize that was a GUI element from a third party vendor.

It looks like you do have a Save feature.
Attached Image


So, again, what is the problem with this feature? Are you getting an error message?
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,843
  • Joined: 02-June 10

Re: How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 12:34 PM

You probably want to use the same text property.

You are trying to save .RawText, but using the length of .Text

Attached Image



According to the documentation the text contains a lot of additional characters for formatting... So these are probably not the same length.
Was This Post Helpful? 0
  • +
  • -

#8 slagusev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-May 12

Re: How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 01:35 PM

When using the Save as:
ArgumentOutOfRangeExecption not processed. Requires a non-negative integer. Parameter name: count
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,843
  • Joined: 02-June 10

Re: How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 01:45 PM

Which line has the error?
Which variable is out of range?

I wrote an article for fixing these kinds of common errors. It should help.
What does this error mean?

View Postslagusev, on 27 May 2012 - 02:35 PM, said:

When using the Save as:
ArgumentOutOfRangeExecption not processed. Requires a non-negative integer. Parameter name: count


Again, look at your use of .Text and .RawText.
These values are of different size.
If .RawText is 200 characters, and .Text is 400 characters, you can try to send 400 characters out of .RawText because it is only 200 in size.


Make line 44 use only the .Text property - Don't use the .RawText property.
Or only use the .RawText property and not the .Text property.
But you can't use both in the one line.
Was This Post Helpful? 0
  • +
  • -

#10 slagusev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-May 12

Re: How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 02:03 PM

View PosttlhIn`toq, on 27 May 2012 - 01:45 PM, said:

Which line has the error?


On error points to a string:
bw.Write (scintilla1.RawText, 0, scintilla1.Text.Length - 1);
Was This Post Helpful? 0
  • +
  • -

#11 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,843
  • Joined: 02-June 10

Re: How Do I Save (Scintillanet And Dockpanel)

Posted 27 May 2012 - 02:27 PM

View Postslagusev, on 27 May 2012 - 03:03 PM, said:

View PosttlhIn`toq, on 27 May 2012 - 01:45 PM, said:

Which line has the error?


On error points to a string:
bw.Write (scintilla1.RawText, 0, scintilla1.Text.Length - 1);



I'm running out of ways of saying this:

These two properties have to be the same.
either both have to be .Text or both have to be .RawText.

Make it this:

bw.Write (scintilla1.RawText, 0, scintilla1.RawText.Length - 1);

This post has been edited by tlhIn`toq: 27 May 2012 - 02:28 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1