コード例 #1
0
 public void FindAndReplaceRegEx(string search, string replacement, RegexOptions options)
 {
     textEditorControl.BeginUpdate();
     if (FindAdReplaceByRegexps(search, replacement, options) == false)
     {
         MessageBox.Show("Exception while replacing with RegExps");
     }
     textEditorControl.EndUpdate();
 }
コード例 #2
0
 /// <summary>Performs an action encapsulated in IEditAction.</summary>
 /// <remarks>
 /// There is an implementation of IEditAction for every action that
 /// the user can invoke using a shortcut key (arrow keys, Ctrl+X, etc.)
 /// The editor control doesn't provide a public funciton to perform one
 /// of these actions directly, so I wrote DoEditAction() based on the
 /// code in TextArea.ExecuteDialogKey(). You can call ExecuteDialogKey
 /// directly, but it is more fragile because it takes a Keys value (e.g.
 /// Keys.Left) instead of the action to perform.
 /// <para/>
 /// Clipboard commands could also be done by calling methods in
 /// editor.ActiveTextAreaControl.TextArea.ClipboardHandler.
 /// </remarks>
 private void DoEditAction(TextEditorControl editor, ICSharpCode.TextEditor.Actions.IEditAction action)
 {
     if (editor != null && action != null)
     {
         var area = editor.ActiveTextAreaControl.TextArea;
         editor.BeginUpdate();
         try
         {
             lock (editor.Document)
             {
                 action.Execute(area);
                 if (area.SelectionManager.HasSomethingSelected && area.AutoClearSelection /*&& caretchanged*/)
                 {
                     if (area.Document.TextEditorProperties.DocumentSelectionMode == DocumentSelectionMode.Normal)
                     {
                         area.SelectionManager.ClearSelection();
                     }
                 }
             }
         }
         finally
         {
             editor.EndUpdate();
             area.Caret.UpdateCaretPosition();
         }
     }
 }
コード例 #3
0
        public static bool ReplaceNextInSelection(IProgressMonitor monitor)
        {
            if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null)
            {
                ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorControlProvider;
                if (provider != null)
                {
                    TextEditorControl textarea         = provider.TextEditorControl;
                    SelectionManager  selectionManager = textarea.ActiveTextAreaControl.TextArea.SelectionManager;

                    if (selectionManager.SelectionCollection.Count == 1 &&
                        selectionManager.SelectionCollection[0].Offset == lastResult.Offset &&
                        selectionManager.SelectionCollection[0].Length == lastResult.Length &&
                        lastResult.FileName == textarea.FileName)
                    {
                        string replacePattern = lastResult.TransformReplacePattern(SearchOptions.ReplacePattern);

                        textarea.BeginUpdate();
                        selectionManager.ClearSelection();
                        textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern);
                        textarea.ActiveTextAreaControl.Caret.Position = textarea.Document.OffsetToPosition(lastResult.Offset + replacePattern.Length);
                        textarea.EndUpdate();

                        textSelection.Length -= lastResult.Length - replacePattern.Length;
                    }
                }
            }
            return(FindNextInSelection(monitor));
        }
コード例 #4
0
        bool InsertSelectedItem(char ch)
        {
            _document.DocumentAboutToBeChanged -= DocumentAboutToBeChanged;
            ICompletionData data   = _completionListView.SelectedItem;
            bool            result = false;

            if (data != null)
            {
                TextEditorControl.BeginUpdate();
                try
                {
                    // Remove already typed text
                    if (_endOffset - _startOffset > 0)
                    {
                        TextEditorControl.Document.Remove(_startOffset, _endOffset - _startOffset);
                    }

                    Debug.Assert(_startOffset <= _document.TextLength);

                    // Insert text from completion data
                    result = _dataProvider.InsertAction(data, TextEditorControl.ActiveTextAreaControl.TextArea, _startOffset, ch);
                }
                finally
                {
                    TextEditorControl.EndUpdate();
                }
            }
            Close();
            return(result);
        }
コード例 #5
0
        public static void Replace(IProgressMonitor monitor)
        {
            SetSearchOptions(monitor);

            ITextEditorControlProvider provider = WorkbenchSingleton.ActiveControl as ITextEditorControlProvider;

            if (PAT.Common.Ultility.Ultility.IsUnixOS)
            {
                provider = FormMain.CurrentActiveTab;
            }
            if (lastResult != null) //&& WorkbenchSingleton.ActiveControl != null
            {
                if (provider != null)
                {
                    TextEditorControl textarea         = provider.TextEditorControl;
                    SelectionManager  selectionManager = textarea.ActiveTextAreaControl.TextArea.SelectionManager;

                    if (selectionManager.SelectionCollection.Count == 1 &&
                        selectionManager.SelectionCollection[0].Offset == lastResult.Offset &&
                        selectionManager.SelectionCollection[0].Length == lastResult.Length &&
                        lastResult.FileName == textarea.FileName)
                    {
                        string replacePattern = lastResult.TransformReplacePattern(SearchOptions.ReplacePattern);

                        textarea.BeginUpdate();
                        selectionManager.ClearSelection();
                        textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern);
                        textarea.ActiveTextAreaControl.Caret.Position =
                            textarea.Document.OffsetToPosition(lastResult.Offset + replacePattern.Length);
                        textarea.EndUpdate();
                    }
                }
            }
            FindNext(monitor);
        }
コード例 #6
0
        public override void Run()
        {
            string clipboardText = ClipboardWrapper.GetText();

            if (string.IsNullOrEmpty(clipboardText))
            {
                return;
            }

            //IViewContent viewContent = WorkbenchSingleton.Workbench.ActiveViewContent;
            ITextEditorControlProvider viewContent = WorkbenchSingleton.ActiveControl as ITextEditorControlProvider;

            if (viewContent == null || !(viewContent is ITextEditorControlProvider))
            {
                return;
            }

            TextEditorControl textEditor = ((ITextEditorControlProvider)viewContent).TextEditorControl;

            if (textEditor == null)
            {
                return;
            }

            textEditor.BeginUpdate();
            textEditor.Document.UndoStack.StartUndoGroup();
            try {
                Run(textEditor, clipboardText);
            } finally {
                textEditor.Document.UndoStack.EndUndoGroup();
                textEditor.EndUpdate();
            }
            textEditor.Refresh();
        }
コード例 #7
0
        public static void DoEditAction([NotNull] this TextEditorControl editor,
                                        [NotNull] ICSharpCode.TextEditor.Actions.IEditAction action)
        {
            if (editor == null)
            {
                throw new ArgumentNullException("editor");
            }
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            var area = editor.ActiveTextAreaControl.TextArea;

            editor.BeginUpdate();
            try
            {
                lock (editor.Document)
                {
                    action.Execute(area);
                    if (area.SelectionManager.HasSomethingSelected && area.AutoClearSelection /*&& caretchanged*/)
                    {
                        if (area.Document.TextEditorProperties.DocumentSelectionMode == DocumentSelectionMode.Normal)
                        {
                            area.SelectionManager.ClearSelection();
                        }
                    }
                }
            }
            finally
            {
                editor.EndUpdate();
                area.Caret.UpdateCaretPosition();
            }
        }
コード例 #8
0
ファイル: Snippet.cs プロジェクト: pascalorama/MDStudio
        /// <summary>
        /// Inserts the snippet into the text editor at the current caret position.
        /// </summary>
        /// <param name="textArea">The text area.</param>
        public void Insert(TextArea textArea)
        {
            TextEditorControl textEditorControl = textArea.MotherTextEditorControl;
            IDocument         document          = textEditorControl.Document;

            document.UndoStack.StartUndoGroup();

            //string selectedText = String.Empty;
            //if (textArea.SelectionManager.HasSomethingSelected)
            //{
            //  selectedText = textArea.SelectionManager.SelectedText;
            //  textArea.Caret.Position = textArea.SelectionManager.Selections[0].StartPosition;
            //  textArea.SelectionManager.RemoveSelectedText();
            //}

            // -----
            // SharpDevelop only:
            // The following line searches for the variable "$(Selection)" in the template text.
            // The variable is then replaced by the text that was previously selected in the editor.
            //   string snippetText = StringParser.Parse(Text, new string[,] { { "Selection", selectedText } });

            // We simply ignore the line above and just copy the text:
            string snippetText = Text;
            // -----

            int finalCaretOffset = snippetText.IndexOf('|');

            if (finalCaretOffset >= 0)
            {
                snippetText = snippetText.Remove(finalCaretOffset, 1);
            }
            else
            {
                finalCaretOffset = snippetText.Length;
            }
            int caretOffset = textArea.Caret.Offset;

            textEditorControl.BeginUpdate();
            int beginLine = textArea.Caret.Line;

            document.Insert(caretOffset, snippetText);

            textArea.Caret.Position = document.OffsetToPosition(caretOffset + finalCaretOffset);
            int endLine = document.OffsetToPosition(caretOffset + snippetText.Length).Y;

            // Save old property settings
            IndentStyle save1 = textEditorControl.TextEditorProperties.IndentStyle;

            textEditorControl.TextEditorProperties.IndentStyle = IndentStyle.Smart;

            document.FormattingStrategy.IndentLines(textArea, beginLine, endLine);
            document.UndoStack.EndUndoGroup();
            textEditorControl.EndUpdate();
            document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
            document.CommitUpdate();

            // Restore old property settings
            textEditorControl.TextEditorProperties.IndentStyle = save1;
        }
コード例 #9
0
        private void DoEditAction(ICSharpCode.TextEditor.Actions.IEditAction action)
        {
            TextEditorControl editor = this.textEditorControl1;

            if (editor != null && action != null)
            {
                TextArea area = editor.ActiveTextAreaControl.TextArea;
                editor.BeginUpdate();
                try
                {
                    lock (editor.Document)
                    {
                        action.Execute(area);
                    }
                }
                finally
                {
                    editor.EndUpdate();
                    area.Caret.UpdateCaretPosition();
                }
            }
        }
コード例 #10
0
        private void ShowDiff(DiffListText source, DiffListText destination, List <DiffResultSpan> diffLines, double seconds)
        {
            _currentIndex = 0;
            _cmdDifferenceNext.Enabled     = true;
            _cmdDifferencePrevious.Enabled = true;
            _differences = new List <int>();
            _rtbSourceScript.BeginUpdate();
            _rtbDestinationScript.BeginUpdate();
            var sourceLines      = new List <KeyValuePair <string, Color> >();
            var destinationLines = new List <KeyValuePair <string, Color> >();
            int i;

            foreach (var drs in diffLines)
            {
                switch (drs.Status)
                {
                case DiffResultSpanStatus.DeleteSource:
                    _differences.Add(sourceLines.Count);
                    for (i = 0; i < drs.Length; i++)
                    {
                        sourceLines.Add(new KeyValuePair <string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Red));
                        destinationLines.Add(new KeyValuePair <string, Color>(new string(' ', ((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line.Length), Color.Blue));
                    }
                    break;

                case DiffResultSpanStatus.NoChange:
                    for (i = 0; i < drs.Length; i++)
                    {
                        sourceLines.Add(new KeyValuePair <string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Empty));
                        destinationLines.Add(new KeyValuePair <string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Empty));
                    }
                    break;

                case DiffResultSpanStatus.AddDestination:
                    _differences.Add(sourceLines.Count);
                    for (i = 0; i < drs.Length; i++)
                    {
                        sourceLines.Add(new KeyValuePair <string, Color>(new string(' ', ((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line.Length), Color.Blue));
                        destinationLines.Add(new KeyValuePair <string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Blue));
                    }
                    break;

                case DiffResultSpanStatus.Replace:
                    _differences.Add(sourceLines.Count);
                    for (i = 0; i < drs.Length; i++)
                    {
                        sourceLines.Add(new KeyValuePair <string, Color>(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line, Color.Red));
                        destinationLines.Add(new KeyValuePair <string, Color>(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line, Color.Green));
                    }
                    break;
                }
            }

            FillScript(sourceLines, _rtbSourceScript);
            FillScript(destinationLines, _rtbDestinationScript);

            _rtbSourceScript.EndUpdate();
            _rtbDestinationScript.EndUpdate();

            this.Text = _differences.Count + " differences.";
        }
コード例 #11
0
 public void EndChange()
 {
     te.EndUpdate();
 }