/// <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(); } }
/// <summary> /// Inserts this selection into the document. /// </summary> /// <param name="textArea">The text area into which to insert the selection.</param> /// <param name="ch">The character that was used to choose this completion selection.</param> /// <returns><lang cref="true"/> if the insertion of <paramref name="p_chrKey"/> was handled; /// <lang cref="false"/> otherwise.</returns> public override bool InsertAction(TextArea textArea, char ch) { switch (m_actCompletionType) { case AutoCompleteType.Attribute: case AutoCompleteType.AttributeValues: textArea.InsertString(Text); return false; case AutoCompleteType.Element: if (Text.EndsWith("[")) { Caret crtCaret = textArea.Caret; textArea.InsertString(String.Concat(Text, "]]>")); crtCaret.Position = textArea.Document.OffsetToPosition(crtCaret.Offset - 3); return false; } break; } return base.InsertAction(textArea, ch); }
/// <summary> /// Insert the element represented by the completion data into the text /// editor. /// </summary> /// <param name="textArea">TextArea to insert the completion data in.</param> /// <param name="ch">Character that should be inserted after the completion data. /// \0 when no character should be inserted.</param> /// <returns>Returns true when the insert action has processed the character /// <paramref name="ch"/>; false when the character was not processed.</returns> public override bool InsertAction(TextArea textArea, char ch) { string insertString; if (this.outputVisitor != null) { PrimitiveExpression pre = new PrimitiveExpression(this.Text, this.Text); pre.AcceptVisitor(this.outputVisitor, null); insertString = this.outputVisitor.Text; } else { insertString = this.Text; } textArea.InsertString(insertString); if (ch == insertString[insertString.Length - 1]) { return true; } return false; }
public virtual bool InsertAction(TextArea textArea, char ch) { textArea.InsertString(this.text); return false; }
public bool InsertAction(ICompletionData data, TextArea textArea, int insertionOffset, char key) { textArea.InsertString(data.Text); return true; }
public bool InsertAction(TextArea textArea, char ch) { textArea.InsertString(text); return false; }
/// <summary> /// Execute the Insert Matching action /// </summary> /// <param name="textArea">The text area in which to perform the /// action</param> public override void Execute(TextArea textArea) { int col = textArea.Caret.Column; textArea.InsertString(matchedChars); textArea.Caret.Column = col + 1; }
public static void GenerateMethodImplementationHeaders(TextArea textArea) { try { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return; ccp = new CodeCompletionProvider(); Position pos = new Position(); //string text = "procedure Test(a : integer);\n begin \n x := 1; \n end;";//ccp.GetRealizationTextToAdd(out pos); string text = ccp.GetMethodImplementationTextToAdd(textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column, ref pos, textArea); if (!string.IsNullOrEmpty(text) && pos.file_name != null) { textArea.Caret.Line = pos.line - 1; textArea.Caret.Column = 0; textArea.InsertString(text); textArea.Caret.Line = pos.line - 1; textArea.Caret.Column = 0; } } catch (System.Exception e) { } }
public override bool InsertAction(TextArea textArea, char ch) { textArea.InsertString(_insertText + _appendText); return false; }
public bool InsertAction(TextArea textArea, char ch) { if ((dataType == DataType.XmlElement) || (dataType == DataType.XmlAttributeValue)) { textArea.InsertString(text); } else if (dataType == DataType.NamespaceUri) { textArea.InsertString(String.Concat("\"", text, "\"")); } else { // Insert an attribute. Caret caret = textArea.Caret; textArea.InsertString(String.Concat(text, "=\"\"")); // Move caret into the middle of the attribute quotes. caret.Position = textArea.Document.OffsetToPosition(caret.Offset - 1); } return false; }
private void listBox1_MouseDoubleClick_1(object sender, MouseEventArgs e) { if (listBox1.SelectedItems == null) { return; } var s = listBox1.SelectedItems[0].Text; ICSharpCode.TextEditor.TextArea ta = MainForm.CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.TextArea; ta.Focus(); var full = schoolManager.ht.Keys.FirstOrDefault(st => st.StartsWith(s)); //if (schoolManager.ht.Keys.Select(st=>st.Substring(0,s.IndexOf('/'))).Contains(s)) if (full != null) { // Если шаблон начинается с begin и предыдущая конструкция с начала строки - управляющий оператор, то сдвинуть курсор, выровняв по предыдущей конструкции if (s.StartsWith("begin … end")) { var Prev = GetPrevLine(ta.Caret.Line); Match m = null; if (Prev != null) { m = Regex.Match(Prev, @"^\s*(loop|for|while|if|else)", RegexOptions.IgnoreCase); if (m.Groups[1].Value.Length > 0) { var Curr = GetLine(ta.Caret.Line); if (Curr.Length > m.Groups[1].Index) { ta.Caret.Column = Curr.Length; ta.InsertString(new string(' ', Curr.Length - m.Groups[1].Index)); } ta.Caret.Column = m.Groups[1].Index; var doc = ta.Document; var tl_beg = new TextLocation(ta.Caret.Column, ta.Caret.Line); int offset = doc.PositionToOffset(tl_beg); if (Curr.Length > ta.Caret.Column && Curr.Substring(ta.Caret.Column).TrimEnd().Length == 0) { doc.Remove(offset, Curr.Length - ta.Caret.Column); } } } var Next = GetNextLine(ta.Caret.Line); if (m != null && m.Groups[1].Value.ToLower().Equals("if") && Next != null && Next.TrimStart().ToLower().StartsWith("else")) { CodeCompletionActionsManager.GenerateTemplate(s, ta, schoolManager, false, str => str.Remove(str.Length - 1)); // Удалить ; в begin end перед else } else { CodeCompletionActionsManager.GenerateTemplate(s, ta, schoolManager, false); } } else { CodeCompletionActionsManager.GenerateTemplate(s, ta, schoolManager, false); } } else { ta.InsertString(s); } ta.Focus(); }
public static bool GenerateCommentTemplate(TextArea textArea) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return false; ccp = new CodeCompletionProvider(); //if (!should_insert_comment(textArea)) // return false; string lineText = get_next_line(textArea); string addit = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.GetDocumentTemplate( lineText, textArea.Document.TextContent, textArea.Caret.Line, textArea.Caret.Column, textArea.Caret.Offset); if (addit == null) return false; int col = textArea.Caret.Column; int line = textArea.Caret.Line; int len; string desc = get_possible_description(textArea, out len); StringBuilder sb = new StringBuilder(); sb.AppendLine(" <summary>"); for (int i = 0; i < col - 3; i++) sb.Append(' '); sb.Append("/// "); if (desc != null) sb.Append(desc); sb.AppendLine(); for (int i = 0; i < col - 3; i++) sb.Append(' '); sb.Append("/// </summary>"); if (addit != "") { sb.Append(addit); } if (desc == null) textArea.InsertString(sb.ToString()); else { IDocument doc = textArea.Document; TextLocation tl_beg = new TextLocation(col, line); //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column); int offset = doc.PositionToOffset(tl_beg); doc.Replace(offset, len, ""); doc.CommitUpdate(); textArea.InsertString(sb.ToString()); } textArea.Caret.Line = line + 1; textArea.Caret.Column = col + 1; return true; }
public static void GenerateTemplate(string pattern, TextArea textArea) { try { StringBuilder sb = new StringBuilder(); IDocument doc = textArea.Document; int line = textArea.Caret.Line; int col = textArea.Caret.Column; string name = templateManager.GetTemplateHeader(pattern); if (name == null) return; string templ = templateManager.GetTemplate(name); int ind = pattern.Length; int cline; int ccol; find_cursor_pos(templ, out cline, out ccol); sb.Append(templ); int cur_ind = templ.IndexOf('|'); if (cur_ind != -1) sb = sb.Remove(cur_ind, 1); sb = sb.Replace("<filename>", Path.GetFileNameWithoutExtension(textArea.MotherTextEditorControl.FileName)); templ = sb.ToString(); int i = 0; i = templ.IndexOf('\n', i); while (i != -1) { if (i + 1 < sb.Length) sb.Insert(i + 1, " ", col - ind); i = sb.ToString().IndexOf('\n', i + 1); } TextLocation tl_beg = new TextLocation(col - ind, line); int offset = doc.PositionToOffset(tl_beg); doc.Replace(offset, ind, ""); doc.CommitUpdate(); textArea.Caret.Column = col - ind; textArea.InsertString(sb.ToString()); textArea.Caret.Line = line + cline; textArea.Caret.Column = col - ind + ccol; } catch (Exception e) { } }
public static void GenerateClassOrMethodRealization(TextArea textArea) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return; ccp = new CodeCompletionProvider(); Position pos = new Position(); //string text = "procedure Test(a : integer);\n begin \n x := 1; \n end;";//ccp.GetRealizationTextToAdd(out pos); string text = ccp.GetRealizationTextToAdd(textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column, ref pos, textArea); if (text != null && pos.file_name != null) { textArea.Caret.Line = pos.line - 1; textArea.Caret.Column = pos.column - 1; textArea.InsertString(text); textArea.Caret.Line = pos.line + 4 - 1; textArea.Caret.Column = VisualPABCSingleton.MainForm.UserOptions.CursorTabCount + 1; } }
public bool InsertAction(TextArea textArea, char ch) { if ((dataType == DataType.XmlElement)) { textArea.InsertString(text); } else if (dataType == DataType.XmlAttributeValue) { if( XmlParser.IsInsideAttributeValue(textArea.Document.TextContent,textArea.Caret.Offset)) { int first, last; XmlParser.GetCurrentAttributeValueSpan(textArea.Document.TextContent, textArea.Caret.Offset, out first, out last); if (last > first && last > 0) { textArea.SelectionManager.SetSelection(textArea.Document.OffsetToPosition(first) , textArea.Document.OffsetToPosition(last) ); textArea.SelectionManager.RemoveSelectedText(); } } textArea.InsertString(text); Caret caret = textArea.Caret; // Move caret outside of the attribute quotes. caret.Position = textArea.Document.OffsetToPosition(caret.Offset + 1); } else if (dataType == DataType.NamespaceUri) { textArea.InsertString(String.Concat("\"", text, "\"")); } else { // Insert an attribute. Caret caret = textArea.Caret; textArea.InsertString(String.Concat(text, "=\"")); // Move caret into the middle of the attribute quotes. caret.Position = textArea.Document.OffsetToPosition(caret.Offset - 1); textArea.SimulateKeyPress('\"'); } return false; }
public virtual bool InsertAction(TextArea textArea, char ch) { textArea.InsertString(description); return false; }
public void Paste(object sender, EventArgs e) { if (!textArea.EnableCutOrPaste) { return; } // Clipboard.GetDataObject may throw an exception... for (var i = 0;; i++) { try { var data = Clipboard.GetDataObject(); if (data == null) { return; } var fullLine = data.GetDataPresent(LineSelectedType); if (data.GetDataPresent(DataFormats.UnicodeText)) { var text = (string)data.GetData(DataFormats.UnicodeText); // we got NullReferenceExceptions here, apparently the clipboard can contain null strings if (!string.IsNullOrEmpty(text)) { textArea.Document.UndoStack.StartUndoGroup(); try { if (textArea.SelectionManager.HasSomethingSelected) { textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[index : 0].StartPosition; textArea.SelectionManager.RemoveSelectedText(); } if (fullLine) { var col = textArea.Caret.Column; textArea.Caret.Column = 0; if (!textArea.IsReadOnly(textArea.Caret.Offset)) { textArea.InsertString(text); } textArea.Caret.Column = col; } else { // textArea.EnableCutOrPaste already checked readonly for this case textArea.InsertString(text); } } finally { textArea.Document.UndoStack.EndUndoGroup(); } } } return; } catch (ExternalException) { // GetDataObject does not provide RetryTimes parameter if (i > 5) { throw; } } } }
public bool InsertAction(TextArea textArea, char ch) { if (dotnetName != null) { CodeCompletionDataUsageCache.IncrementUsage(dotnetName); } if (c != null && text.Length > c.Name.Length) { textArea.InsertString(text.Substring(0, c.Name.Length + 1)); Point start = textArea.Caret.Position; Point end; int pos = text.IndexOf(','); if (pos < 0) { textArea.InsertString(text.Substring(c.Name.Length + 1)); end = textArea.Caret.Position; end.X -= 1; } else { textArea.InsertString(text.Substring(c.Name.Length + 1, pos - c.Name.Length - 1)); end = textArea.Caret.Position; textArea.InsertString(text.Substring(pos)); } textArea.Caret.Position = start; textArea.SelectionManager.SetSelection(start, end); if (!char.IsLetterOrDigit(ch)) { return true; } } else { textArea.InsertString(text); } return false; }
public bool InsertAction(ICompletionData data, TextArea textArea, int insertionOffset, char key) { textArea.InsertString(data.Text); return false; //throw new Exception("The method or operation is not implemented."); }