/// <summary> /// Inserts the PInvoke signature at the current cursor position. /// </summary> /// <param name="textArea">The text editor.</param> /// <param name="signature">A PInvoke signature string.</param> public void Generate(TextArea textArea, string signature) { IndentStyle oldIndentStyle = textArea.TextEditorProperties.IndentStyle; bool oldEnableEndConstructs = PropertyService.Get("VBBinding.TextEditor.EnableEndConstructs", true); try { textArea.BeginUpdate(); textArea.Document.UndoStack.StartUndoGroup(); textArea.TextEditorProperties.IndentStyle = IndentStyle.Smart; PropertyService.Set("VBBinding.TextEditor.EnableEndConstructs", false); string[] lines = signature.Replace("\r\n", "\n").Split('\n'); for (int i = 0; i < lines.Length; ++i) { textArea.InsertString(lines[i]); // Insert new line if not the last line. if ( i < (lines.Length - 1)) { Return(textArea); } } } finally { textArea.Document.UndoStack.EndUndoGroup(); textArea.TextEditorProperties.IndentStyle = oldIndentStyle; PropertyService.Set("VBBinding.TextEditor.EnableEndConstructs", oldEnableEndConstructs); textArea.EndUpdate(); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); textArea.Document.CommitUpdate(); } }
protected void OnDragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(string))) { textArea.BeginUpdate(); textArea.Document.UndoStack.StartUndoGroup(); try { int offset = textArea.Caret.Offset; if (textArea.IsReadOnly(offset)) { // prevent dragging text into readonly section return; } if (e.Data.GetDataPresent(typeof(DefaultSelection))) { ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection)); if (sel.ContainsPosition(textArea.Caret.Position)) { return; } if (GetDragDropEffect(e) == DragDropEffects.Move) { if (SelectionManager.SelectionIsReadOnly(textArea.Document, sel)) { // prevent dragging text out of readonly section return; } int len = sel.Length; textArea.Document.Remove(sel.Offset, len); if (sel.Offset < offset) { offset -= len; } } } textArea.SelectionManager.ClearSelection(); InsertString(offset, (string)e.Data.GetData(typeof(string))); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); } finally { textArea.Document.UndoStack.EndUndoGroup(); textArea.EndUpdate(); } } }
protected void OnDragDrop(object sender, DragEventArgs e) { Point p = textArea.PointToClient(new Point(e.X, e.Y)); if (e.Data.GetDataPresent(typeof(string))) { bool two = false; textArea.BeginUpdate(); try { int offset = textArea.Caret.Offset; if (textArea.TextEditorProperties.UseCustomLine && textArea.Document.CustomLineManager.IsReadOnly(textArea.Caret.Line, false)) { // prevent dragging text into readonly section return; } if (e.Data.GetDataPresent(typeof(DefaultSelection))) { ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection)); if (sel.ContainsPosition(textArea.Caret.Position)) { return; } if (GetDragDropEffect(e) == DragDropEffects.Move) { if (textArea.TextEditorProperties.UseCustomLine && textArea.Document.CustomLineManager.IsReadOnly(sel, false)) { // prevent dragging text out of readonly section return; } int len = sel.Length; textArea.Document.Remove(sel.Offset, len); if (sel.Offset < offset) { offset -= len; } } two = true; } textArea.SelectionManager.ClearSelection(); InsertString(offset, (string)e.Data.GetData(typeof(string))); if (two) { textArea.Document.UndoStack.CombineLast(2); } textArea.Document.UpdateQueue.Clear(); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); } finally { textArea.EndUpdate(); } } }
public void Cut(object sender, EventArgs e) { if (textArea.SelectionManager.HasSomethingSelected) { if (CopyTextToClipboard(textArea.SelectionManager.SelectedText)) { if (textArea.SelectionManager.SelectionIsReadonly) { return; } // Remove text textArea.BeginUpdate(); textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition; textArea.SelectionManager.RemoveSelectedText(); textArea.EndUpdate(); } } else if (textArea.Document.TextEditorProperties.CutCopyWholeLine) { // No text was selected, select and cut the entire line int curLineNr = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset); LineSegment lineWhereCaretIs = textArea.Document.GetLineSegment(curLineNr); string caretLineText = textArea.Document.GetText(lineWhereCaretIs.Offset, lineWhereCaretIs.TotalLength); textArea.SelectionManager.SetSelection(textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset), textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset + lineWhereCaretIs.TotalLength)); if (CopyTextToClipboard(caretLineText, true)) { if (textArea.SelectionManager.SelectionIsReadonly) { return; } // remove line textArea.BeginUpdate(); textArea.Caret.Position = textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset); textArea.SelectionManager.RemoveSelectedText(); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.PositionToEnd, new TextLocation(0, curLineNr))); textArea.EndUpdate(); } } }
private void templateEditor_DragDrop(object sender, DragEventArgs e) { TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode)); ICSharpCode.TextEditor.TextArea textArea = (ICSharpCode.TextEditor.TextArea)sender; try { Hashtable idPack = node.Tag as Hashtable; switch (idPack["Type"] as string) { case "promptgroup": return; case "prompt": break; } //Build the variable to insert here Prompt prompt = idPack["Data"] as Prompt; Point p = textArea.PointToClient(new Point(e.X, e.Y)); textArea.BeginUpdate(); textArea.Document.UndoStack.StartUndoGroup(); int offset = textArea.Caret.Offset; if (e.Data.GetDataPresent(typeof(DefaultSelection))) { ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection)); if (sel.ContainsPosition(textArea.Caret.Position)) { return; } int len = sel.Length; textArea.Document.Remove(sel.Offset, len); if (sel.Offset < offset) { offset -= len; } } insertIntoTemplateEditor(textArea, offset, prompt.VariableName); } finally { textArea.Document.UndoStack.EndUndoGroup(); textArea.EndUpdate(); } }
protected void OnDragDrop(object sender, DragEventArgs e) { Point p = textArea.PointToClient(new Point(e.X, e.Y)); if (textArea.EnableCutOrPaste == false) { return; } if (e.Data.GetDataPresent(typeof(string))) { bool two = false; textArea.BeginUpdate(); try { int offset = textArea.Caret.Offset; if (e.Data.GetDataPresent(typeof(DefaultSelection))) { ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection)); if (sel.ContainsPosition(textArea.Caret.Position)) { return; } if (GetDragDropEffect(e) == DragDropEffects.Move) { int len = sel.Length; textArea.Document.Remove(sel.Offset, len); if (sel.Offset < offset) { offset -= len; } } two = true; } textArea.SelectionManager.ClearSelection(); InsertString(offset, (string)e.Data.GetData(typeof(string))); if (two) { textArea.Document.UndoStack.UndoLast(2); } textArea.Document.UpdateQueue.Clear(); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); } finally { textArea.EndUpdate(); } } }
public void Cut(object sender, EventArgs e) { if (textArea.SelectionManager.HasSomethingSelected) { if (CopyTextToClipboard(textArea.SelectionManager.SelectedText)) { if (textArea.SelectionManager.SelectionIsReadonly) { return; } // Remove text textArea.BeginUpdate(); textArea.Caret.Position = textArea.SelectionManager.StartPosition; textArea.SelectionManager.RemoveSelectedText(); textArea.EndUpdate(); } } }
/// <summary> /// Insert a string of text into the specified text area at the current /// cursor location. /// </summary> /// <param name="textArea">The text area to use</param> /// <param name="text">The text to insert</param> public static void InsertString(TextArea textArea, string text) { int offset = textArea.Caret.Offset; textArea.BeginUpdate(); try { textArea.Document.UndoStack.StartUndoGroup(); // If inserted in a selection, replace the selection. // Otherwise, clear it. if(textArea.SelectionManager.HasSomethingSelected) if(textArea.SelectionManager.SelectionCollection[0].ContainsOffset(offset)) { offset = textArea.SelectionManager.SelectionCollection[0].Offset; textArea.SelectionManager.RemoveSelectedText(); } else textArea.SelectionManager.ClearSelection(); textArea.Document.Insert(offset, text); textArea.Caret.Position = textArea.Document.OffsetToPosition(offset + text.Length); textArea.Refresh(); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); } finally { textArea.Document.UndoStack.EndUndoGroup(); textArea.EndUpdate(); } }
protected void OnDragDrop(object sender, DragEventArgs e) { if (!IsSupportedData(e.Data)) { return; } textArea.BeginUpdate(); textArea.Document.UndoStack.StartUndoGroup(); try { var offset = textArea.Caret.Offset; if (textArea.IsReadOnly(offset)) { return; } try { if (e.Data.GetDataPresent(typeof(DefaultSelection))) { var sel = (ISelection)e.Data.GetData(typeof(DefaultSelection)); if (sel.ContainsPosition(textArea.Caret.Position)) { return; } if (GetDragDropEffect(e) == DragDropEffects.Move) { if (SelectionManager.SelectionIsReadOnly(textArea.Document, sel)) { return; } var len = sel.Length; textArea.Document.Remove(sel.Offset, len); if (sel.Offset < offset) { offset -= len; } } } } catch (System.InvalidCastException) { /* * If GetDataPresent(typeof(DefaultSelection)) threw this * exception, then it's an interprocess DefaultSelection * COM object that is not serializable! In general, * GetDataPresent(typeof(...)) throws InvalidCastException * for drags and drops from other GitExt processes (maybe * we need to make the data objects [Serializable]?). We * can get around this exception by doing * GetDataPresent(String s) [using the string of the type * name seems to work fine!] Since it is interprocess * data, just get the string data from it - special * handling logic in try {} is only valid for selections * within the current process's text editor! */ } textArea.SelectionManager.ClearSelection(); InsertString(offset, (string)e.Data.GetData("System.String")); textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); } finally { textArea.Document.UndoStack.EndUndoGroup(); textArea.EndUpdate(); } }