/// <summary>
        /// Executes command.
        /// </summary>
        /// <param name="document">Document insert to.</param>
        public void Execute(ITextEditorDocument document)
        {
            if (this.text.Count == 0 || document == null)
            {
                return;
            }

            this.line = document.LineNumberByIndex(this.caretIndex);
            this.position = document.CaretPositionInLineByIndex(this.caretIndex);
            this.changedDocument = document;

            if (this.line == -1)
            {
                this.line = 0;
                document.AddLine(string.Empty);
            }

            string paragraph = document.AllLines[this.line];
            string partToMove = paragraph.Substring(this.position);
            if (paragraph.Length > this.position)
            {
                paragraph = paragraph.Remove(this.position);
            }

            document.ChangeLineAtIndex(this.line, paragraph.Insert(this.position, this.text.First()));
            List<string> newLines = new List<string>(this.text);
            newLines.RemoveAt(0);
            for (int i = 0; i < newLines.Count; i++)
            {
                document.InsertLineAtIndex(this.line + i + 1, newLines[i]);
            }

            string lastLine = document.AllLines[this.line + this.text.Count - 1];
            document.ChangeLineAtIndex(this.line + this.text.Count - 1, lastLine + partToMove);
        }
Exemple #2
0
 /// <summary>
 /// Runs the macro.
 /// </summary>
 /// <param name="document">Document to execute macro.</param>
 /// <param name="caretIndex">Caret index to execute macro.</param>
 public void Run(ITextEditorDocument document, int caretIndex)
 {
     foreach (ICommand command in this.commands)
     {
         command.Execute(document, caretIndex);
     }
 }
        /// <summary>
        /// Executes command.
        /// </summary>
        /// <param name="document">Document to run command.</param>
        public void Execute(ITextEditorDocument document)
        {
            if (document == null)
            {
                return;
            }

            this.line = document.LineNumberByIndex(this.caretIndex);
            this.position = document.CaretPositionInLineByIndex(this.caretIndex);
            this.changedDocument = document;

            string paragraph = document.AllLines[this.line];
            this.changedLine = document.AllLines[this.line];

            string substringToTranslate = string.Empty;
            if (this.position < paragraph.Length)
            {
                int substringLength = paragraph.Length - this.position;
                substringToTranslate = paragraph.Substring(this.position, substringLength);
                document.ChangeLineAtIndex(this.line, paragraph.Remove(this.position, substringLength));
            }

            for (int i = 0; i < this.indentationLevel; i++)
            {
                substringToTranslate = " " + substringToTranslate;
            }

            document.InsertLineAtIndex(this.line + 1, substringToTranslate);
        }
        /// <summary>
        /// Executes command.
        /// </summary>
        /// <param name="document">Document to run command.</param>
        public void Execute(ITextEditorDocument document)
        {
            if (document == null)
            {
                return;
            }

            this.line = document.LineNumberByIndex(this.caretIndex);
            this.position = document.CaretPositionInLineByIndex(this.caretIndex);
            this.changedDocument = document;

            int endCaretIndex = this.caretIndex + this.length;
            if (endCaretIndex > document.Text.Length)
            {
                endCaretIndex = document.Text.Length;
            }

            int endPosition = document.CaretPositionInLineByIndex(endCaretIndex);
            int endLineIndex = document.LineNumberByIndex(endCaretIndex);
            this.removedLines = document.AllLines.GetRange(this.line, endLineIndex - this.line + 1);

            string paragraph = document.AllLines[this.line];
            string lineToMove = document.AllLines[endLineIndex].Substring(endPosition);
            if (paragraph.Length > this.position)
            {
                paragraph = paragraph.Remove(this.position);
            }

            document.ChangeLineAtIndex(this.line, paragraph + lineToMove);
            document.RemoveLines(this.line + 1, endLineIndex - this.line);
        }
 public void TextEditorFileManager_Save_Open()
 {
     document = fileManager.OpenFileUsingEncoding(@"Resources\DocumentExample.txt", Encoding.Default);
     Assert.IsNotNull(this.document, "FileManager couldn't open document");
     document.AddLine("Hello");
     fileManager.SaveDocument(document);
     document = fileManager.OpenFileUsingEncoding(@"Resources\DocumentExample.txt", Encoding.Default);
     Assert.IsTrue(document.AllLines[document.AllLines.Count - 1] == "Hello", "Changes to document haven't been saved by FileManager");
     document.RemoveLineAtIndex(document.AllLines.Count - 1);
     fileManager.SaveDocument(document);
 }
 public void TextEditorFileManager_OpenFileUsingEncoding()
 {
     this.document = this.fileManager.OpenFileUsingEncoding(@"Resources\DocumentExample.txt", Encoding.Default);
     Assert.IsNotNull(this.document, "FileManager couldn't open document");
     this.document = this.fileManager.OpenFileUsingEncoding(@"Resources\DocumentExample.txt", Encoding.ASCII);
     Assert.IsNotNull(this.document, "FileManager couldn't open document");
     this.document = this.fileManager.OpenFileUsingEncoding(@"Resources\DocumentExample.txt", Encoding.Unicode);
     Assert.IsNotNull(this.document, "FileManager couldn't open document");
     this.document = this.fileManager.OpenFileUsingEncoding(@"Resources\DocumentExample.txt", Encoding.UTF8);
     Assert.IsNotNull(this.document, "FileManager couldn't open document");
 }
        /// <summary>
        /// Parse document text and saves result in Tokens.
        /// </summary>
        /// <param name="document">Document to analyze.</param>
        public void Parse(ITextEditorDocument document)
        {
            if (document == null)
            {
                return;
            }

            this.Tokens.Clear();

            this.ParseKeywords(document.Text);
            this.ParseNumbers(document.Text);
            this.ParseStrings(document.Text);
            this.ParseComments(document.Text);
        }
        /// <summary>
        /// Executes command.
        /// </summary>
        /// <param name="document">Document to run command.</param>
        public void Execute(ITextEditorDocument document)
        {
            if (document == null)
            {
                return;
            }

            this.line = document.LineNumberByIndex(this.caretIndex);
            this.position = document.CaretPositionInLineByIndex(this.caretIndex);
            this.changedDocument = document;

            if (this.line == -1)
            {
                this.line = 0;
                document.AddLine(string.Empty);
            }

            string paragraph = document.AllLines[this.line];
            document.ChangeLineAtIndex(this.line, paragraph.Insert(this.position, this.text));
        }
        /// <summary>
        /// Export the data.
        /// </summary>
        public override void Execute()
        {
            Project project = App.Instance.SalesForceApp.CurrentProject;

            if (project != null)
            {
                ITextEditorDocument document = CurrentDocument;
                if (document != null)
                {
                    string name      = "file";
                    string extension = "txt";

                    if (document is ISourceFileEditorDocument)
                    {
                        name      = System.IO.Path.GetFileName((document as ISourceFileEditorDocument).File.FileName);
                        extension = System.IO.Path.GetExtension(name);
                        if (extension.StartsWith("."))
                        {
                            extension = extension.Substring(1);
                        }
                    }

                    SaveFileDialog dlg = new SaveFileDialog();
                    dlg.Title           = "Export file";
                    dlg.OverwritePrompt = true;
                    dlg.AddExtension    = true;
                    dlg.Filter          = String.Format("{0} Files|*.{1}|All Files|*.*", extension.ToUpper(), extension);
                    dlg.FileName        = name;

                    bool?result = dlg.ShowDialog();
                    if (result.HasValue && result.Value)
                    {
                        System.IO.File.WriteAllText(dlg.FileName, document.Content);
                    }
                }
            }
        }
        /// <summary>
        /// Executes command.
        /// </summary>
        /// <param name="document">Document to run command.</param>
        public void Execute(ITextEditorDocument document)
        {
            if (document == null)
            {
                return;
            }

            this.line = document.LineNumberByIndex(this.caretIndex);
            this.position = document.CaretPositionInLineByIndex(this.caretIndex);

            string paragrapgh = document.AllLines[this.line];
            int paragraphIndex = this.position;
            int length = 0;
            while (paragraphIndex < paragrapgh.Length && paragrapgh[paragraphIndex] == this.snippet.Name[length])
            {
                paragraphIndex++;
                length++;
            }

            this.removeCommand = new RemoveRangeCommand(this.caretIndex, length);
            this.removeCommand.Execute(document);
            this.insertCommand = new InsertLinesCommand(this.snippet.Content, this.caretIndex);
            this.insertCommand.Execute(document);
        }
 /// <summary>
 /// Executes command on new caretIndex.
 /// </summary>
 /// <param name="document">Document to change.</param>
 /// <param name="newCaretIndex">New caretIndex.</param>
 public void Execute(ITextEditorDocument document, int newCaretIndex)
 {
     this.caretIndex = newCaretIndex;
     this.Execute(document);
 }
 private void OpenFileMenuItem_Click(object sender, RoutedEventArgs e)
 {
     ITextEditorDocument newDocument = this.fileManager.OpenFile();
     if (newDocument != null)
     {
         this.Document = newDocument;
     }
 }
        private void EncodingMenuItem_Click(object sender, RoutedEventArgs e)
        {
            Encoding encoding;
            MenuItem senderMenuItem = sender as MenuItem;
            switch (senderMenuItem.Header.ToString())
            {
                case "Auto":
                    encoding = Encoding.Default;
                    break;
                case "UTF8":
                    encoding = Encoding.UTF8;
                    break;
                case "ASCII":
                    encoding = Encoding.ASCII;
                    break;
                case "Unicode":
                    encoding = Encoding.Unicode;
                    break;
                default:
                    throw new ArgumentException("Unknown encoding");
            }

            this.Document = this.fileManager.OpenFileUsingEncoding(this.Document.FileName, encoding);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TextEditorCommandManager"/> class.
 /// </summary>
 /// <param name="document">Document to manage.</param>
 public TextEditorCommandManager(ITextEditorDocument document)
 {
     this.document = document;
 }
        /// <summary>
        /// Shows SaveFileDialogSaves and saves document to specified location.
        /// </summary>
        /// <param name="document">Document to save.</param>
        public void SaveAsDocument(ITextEditorDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();

            if (sfd.ShowDialog() == false)
            {
                return;
            }

            document.FileName = sfd.FileName;
            this.SaveDocument(document);
        }
        /// <summary>
        /// Saves document to location specified in FileName.
        /// </summary>
        /// <param name="document">Document to save.</param>
        public void SaveDocument(ITextEditorDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            File.WriteAllLines(document.FileName, document.AllLines);
        }