TextEditorData CreateData (string content) { var data = new TextEditorData (new TextDocument (content)); data.IndentationTracker = IndentTracker; data.Options.IndentStyle = IndentStyle.Smart; return data; }
public static void Join (TextEditorData data) { int startLine, endLine, startOffset, length; if (data.IsSomethingSelected) { startLine = data.Document.OffsetToLineNumber (data.SelectionRange.Offset); endLine = data.Document.OffsetToLineNumber (data.SelectionRange.EndOffset - 1); } else { startLine = endLine = data.Caret.Line; } //single-line joins if (endLine == startLine) endLine++; if (endLine > data.Document.LineCount) return; DocumentLine seg = data.Document.GetLine (startLine); startOffset = seg.Offset; StringBuilder sb = new StringBuilder (data.Document.GetTextAt (seg).TrimEnd ()); //lastSpaceOffset = startOffset + sb.Length; for (int i = startLine + 1; i <= endLine; i++) { seg = data.Document.GetLine (i); //lastSpaceOffset = startOffset + sb.Length; sb.Append (" "); sb.Append (data.Document.GetTextAt (seg).Trim ()); } length = (seg.Offset - startOffset) + seg.Length; // TODO: handle conversion issues ? data.Replace (startOffset, length, sb.ToString ()); }
TextEditorData CreateData () { var data = new TextEditorData (); data.IndentationTracker = IndentTracker; data.Options.IndentStyle = IndentStyle.Smart; return data; }
public static TextEditorData Create (string content) { int caretIndex = content.IndexOf ("$"); if (caretIndex >= 0) content = content.Substring (0, caretIndex) + content.Substring (caretIndex + 1); int selection1 = content.IndexOf ("<-"); int selection2 = content.IndexOf ("->"); int selectionStart = 0; int selectionEnd = 0; if (0 <= selection1 && selection1 < selection2) { content = content.Substring (0, selection2) + content.Substring (selection2 + 2); content = content.Substring (0, selection1) + content.Substring (selection1 + 2); selectionStart = selection1; selectionEnd = selection2 - 2; caretIndex = selectionEnd; } var data = new TextEditorData (); data.Text = content; if (caretIndex >= 0) data.Caret.Offset = caretIndex; if (selection1 >= 0) { if (caretIndex == selectionStart) { data.SetSelection (selectionEnd, selectionStart); } else { data.SetSelection (selectionStart, selectionEnd); } } return data; }
public static string GetMarkup (string input, string syntaxMode) { var data = new TextEditorData (new TextDocument (input)); data.Document.SyntaxMode = SyntaxModeService.GetSyntaxMode (data.Document, syntaxMode); data.ColorStyle = SyntaxModeService.GetColorStyle ("TangoLight"); return data.GetMarkup (0, data.Length, false); }
public static TextEditorData CreateData (string content) { var data = new TextEditorData (new TextDocument (content)); data.IndentationTracker = SmartIndentModeTests.IndentTracker; data.Options.IndentStyle = IndentStyle.Virtual; return data; }
TextEditorData CreateData () { var data = new TextEditorData (); data.IndentationTracker = SmartIndentModeTests.IndentTracker; data.Options.IndentStyle = IndentStyle.Virtual; return data; }
public void TestBug14716 () { var data = new TextEditorData (); data.Document.Text = "using System;\nusing System.Linq;\nusing System.Collections.Generic;\n"; data.SearchEngine = new RegexSearchEngine (); data.SearchEngine.SearchRequest.SearchPattern = "u.i.g"; data.SearchReplaceAll ("bar"); Assert.AreEqual ("bar System;\nbar System.Linq;\nbar System.Collections.Generic;\n", data.Document.Text ); }
string CreateInsertionPoint (string input, string text, NewLineInsertion before, NewLineInsertion after) { int idx = input.IndexOf ('$'); Assert.Greater (idx, -1); TextEditorData data = new TextEditorData (new TextDocument (input.Substring (0, idx) + input.Substring (idx + 1))); InsertionPoint point = new InsertionPoint (data.Document.OffsetToLocation (idx), before, after); point.Insert (data, text); return data.Document.Text; }
public static void Check (TextEditorData data, string output, bool reverse) { int offset1 = output.IndexOf ('['); int offset2 = output.IndexOf (']'); string expected = output.Substring (0, offset1) + output.Substring (offset1 + 1, (offset2 - offset1) - 1) + output.Substring (offset2 + 1); offset2--; Assert.AreEqual (expected, data.Text); Assert.AreEqual (data.OffsetToLocation (reverse ? offset2 : offset1), data.MainSelection.Anchor); Assert.AreEqual (data.OffsetToLocation (reverse ? offset1 : offset2), data.MainSelection.Lead); }
public void TestSimpleYToLineNumber () { var editor = new TextEditorData (); editor.Text = "1\n2\n3\n4\n5\n6\n7"; HeightTree heightTree = new HeightTree (editor); heightTree.Rebuild (); for (int i = 1; i <= editor.LineCount; i++) { Assert.AreEqual (i, heightTree.YToLineNumber ((i - 1) * editor.LineHeight)); } }
protected override void OnRemovedFromEditor (TextEditorData data) { SetCaretMode (CaretMode.Insert, data); if (viTextEditor != null) { statusArea.RemoveFromParentAndDestroy (); statusArea = null; viTextEditor = null; } }
public void LoadMark (TextEditorData data) { int x = base.LineSegment.LineNumber; data.Caret.Line = x; int len = base.LineSegment.LengthIncludingDelimiter; if (ColumnNumber >= len) { // Check if the line has been truncated after the setting the mark data.Caret.Column = len - 1; } else { data.Caret.Column = ColumnNumber; } }
protected override void OnAddedToEditor (TextEditorData data) { ViEditor.SetMode (ViEditorMode.Normal); SetCaretMode (CaretMode.Block, data); ViActions.RetreatFromLineEnd (data); viTextEditor = data.Parent; if (viTextEditor != null) { statusArea = new ViStatusArea (viTextEditor); } }
internal static TextEditorData Create (string text) { TextEditorData result = new TextEditorData (); if (text.IndexOf ('$') >= 0) { int caretOffset = text.IndexOf ('$'); result.Document.Text = text.Remove (caretOffset, 1); result.Caret.Offset = caretOffset; } else { result.Document.Text = text; } return result; }
public static void NewLineAbove (TextEditorData data) { if (data.Caret.Line == DocumentLocation.MinLine ) { data.Caret.Offset = 0; MiscActions.InsertNewLine (data); data.Caret.Offset = 0; return; } DocumentLine currentLine = data.Document.GetLine (data.Caret.Line - 1); data.Caret.Offset = currentLine.Offset + currentLine.Length; MiscActions.InsertNewLine (data); }
public void TestYToLineNumberWithFolds () { var editor = new TextEditorData (); editor.Text = "1\n2\n3\n4\n5\n6\n7\n8\n9\n0"; HeightTree heightTree = new HeightTree (editor); heightTree.Rebuild (); heightTree.Fold (1, 2); heightTree.Fold (6, 3); heightTree.Fold (5, 5); Assert.AreEqual (1, heightTree.YToLineNumber (0 * editor.LineHeight)); Assert.AreEqual (4, heightTree.YToLineNumber (1 * editor.LineHeight)); Assert.AreEqual (5, heightTree.YToLineNumber (2 * editor.LineHeight)); }
public static void SetSelection (TextEditorData data, bool reverse) { ISegment selection = GetSelection (data, reverse); if (reverse) { data.Caret.Offset = selection.Offset; data.SelectionAnchor = selection.EndOffset; data.ExtendSelectionTo (selection.Offset); } else { data.Caret.Offset = selection.EndOffset; data.SelectionAnchor = selection.Offset; data.ExtendSelectionTo (selection.EndOffset); } }
internal static TextEditorData Create (string text) { TextEditorData result = new TextEditorData (); if (text.IndexOf ('$') >= 0) { int caretOffset = text.IndexOf ('$'); result.Document.Text = text.Remove (caretOffset, 1); result.Caret.Offset = caretOffset; } else { result.Document.Text = text; } for (int i = 1; i <= result.Document.LineCount; i++) { if (result.Document.GetLineText (i).StartsWith ("@")) result.GetLine (i).IsBookmarked = true; } return result; }
public void SaveMark (TextEditorData data) { if (base.LineSegment != null) { // Remove the marker first data.Document.RemoveMarker (this); } // Is there a better way of doing this? int lineNumber = data.IsSomethingSelected ? data.MainSelection.MinLine : data.Caret.Line; base.LineSegment = data.Document.GetLine (lineNumber); ColumnNumber = data.Caret.Column; data.Document.AddMarker(lineNumber, this); data.Document.RequestUpdate (new UpdateAll ()); data.Document.CommitDocumentUpdate (); }
public static List<List<ColoredSegment>> GetChunks (TextEditorData data, TextSegment selectedSegment) { int startLineNumber = data.OffsetToLineNumber (selectedSegment.Offset); int endLineNumber = data.OffsetToLineNumber (selectedSegment.EndOffset); var copiedColoredChunks = new List<List<ColoredSegment>> (); foreach (var line in data.Document.GetLinesBetween (startLineNumber, endLineNumber)) { copiedColoredChunks.Add ( data.GetChunks ( line, System.Math.Max (selectedSegment.Offset, line.Offset), System.Math.Max (selectedSegment.EndOffset, line.EndOffset) - line.Offset ) .Select (chunk => new ColoredSegment (chunk, data.Document)) .ToList () ); } return copiedColoredChunks; }
public static void MoveToNextEmptyLine (TextEditorData data) { if (data.Caret.Line == data.Document.LineCount) { data.Caret.Offset = data.Document.Length; return; } int line = data.Caret.Line + 1; LineSegment currentLine = data.Document.GetLine (line); while (line <= data.Document.LineCount) { line++; LineSegment nextLine = data.Document.GetLine (line); if (currentLine.EditableLength != 0 && nextLine.EditableLength == 0) { data.Caret.Offset = nextLine.Offset; return; } currentLine = nextLine; } data.Caret.Offset = currentLine.Offset; }
public static void MoveToPreviousEmptyLine (TextEditorData data) { if (data.Caret.Line == DocumentLocation.MinLine) { data.Caret.Offset = 0; return; } int line = data.Caret.Line - 1; LineSegment currentLine = data.Document.GetLine (line); while (line > DocumentLocation.MinLine) { line--; LineSegment previousLine = data.Document.GetLine (line); if (currentLine.EditableLength != 0 && previousLine.EditableLength == 0) { data.Caret.Offset = previousLine.Offset; return; } currentLine = previousLine; } data.Caret.Offset = currentLine.Offset; }
public void TestLineNumberToYWithFolds () { var editor = new TextEditorData (); editor.Text = "1\n2\n3\n4\n5\n6\n7\n8\n9\n0"; //123 //4 //5[678]90 HeightTree heightTree = new HeightTree (editor); heightTree.Rebuild (); heightTree.Fold (1, 2); heightTree.Fold (6, 3); heightTree.Fold (5, 5); Assert.AreEqual (0 * editor.LineHeight, heightTree.LineNumberToY (1)); Assert.AreEqual (0 * editor.LineHeight, heightTree.LineNumberToY (2)); Assert.AreEqual (0 * editor.LineHeight, heightTree.LineNumberToY (3)); Assert.AreEqual (1 * editor.LineHeight, heightTree.LineNumberToY (4)); for (int i = 5; i <= 10; i++) Assert.AreEqual (2 * editor.LineHeight, heightTree.LineNumberToY (i)); }
public void TestSetLineHeight () { var editor = new TextEditorData (); editor.Text = "1\n2\n3\n4\n5\n6\n7"; HeightTree heightTree = new HeightTree (editor); heightTree.Rebuild (); for (int i = 1; i <= editor.LineCount; i += 2) { heightTree.SetLineHeight (i, editor.LineHeight * 2); } double y = 0; for (int i = 1; i <= editor.LineCount; i++) { Assert.AreEqual (y, heightTree.LineNumberToY (i)); y += i % 2 == 0 ? editor.LineHeight : editor.LineHeight * 2; } y = 0; for (int i = 1; i <= editor.LineCount; i++) { Assert.AreEqual (i, heightTree.YToLineNumber (y)); y += i % 2 == 0 ? editor.LineHeight : editor.LineHeight * 2; } }
protected override void OnRemovedFromEditor(TextEditorData data) { data.Caret.Mode = CaretMode.Insert; }
protected override void OnAddedToEditor(TextEditorData data) { data.Caret.Mode = CaretMode.Block; ViActions.RetreatFromLineEnd(data); }
public ParsedDocument BuildDocument(DocumentInfo info, TextEditorData data) { var docStr = BuildDocumentString(info, data); return(Parse(info.AspNetDocument.FileName, docStr)); }
public override IEnumerable <MemberReference> FindReferences(Project project, IProjectContent content, IEnumerable <FilePath> possibleFiles, IProgressMonitor monitor, IEnumerable <object> members) { if (content == null) { throw new ArgumentNullException("content", "Project content not set."); } SetPossibleFiles(possibleFiles); SetSearchedMembers(members); var scopes = searchedMembers.Select(e => e is INamespace ? refFinder.GetSearchScopes((INamespace)e) : refFinder.GetSearchScopes((ISymbol)e)); var compilation = project != null?TypeSystemService.GetCompilation(project) : content.CreateCompilation(); List <MemberReference> refs = new List <MemberReference> (); foreach (var opendoc in openDocuments) { foreach (var newRef in FindInDocument(opendoc.Item2)) { if (newRef == null || refs.Any(r => r.FileName == newRef.FileName && r.Region == newRef.Region)) { continue; } refs.Add(newRef); } } foreach (var file in files) { if (monitor != null) { monitor.Step(1); } string text; try { if (!File.Exists(file)) { continue; } text = Mono.TextEditor.Utils.TextFileUtility.ReadAllText(file); } catch (Exception e) { LoggingService.LogError("Exception while file reading.", e); continue; } if (memberName != null && text.IndexOf(memberName, StringComparison.Ordinal) < 0 && (keywordName == null || text.IndexOf(keywordName, StringComparison.Ordinal) < 0)) { continue; } using (var editor = TextEditorData.CreateImmutable(text)) { editor.Document.FileName = file; var unit = new CSharpParser().Parse(editor); if (unit == null) { continue; } var storedFile = content.GetFile(file); var parsedFile = storedFile as CSharpUnresolvedFile; if (parsedFile == null && storedFile is ParsedDocumentDecorator) { parsedFile = ((ParsedDocumentDecorator)storedFile).ParsedFile as CSharpUnresolvedFile; } if (parsedFile == null) { // for fallback purposes - should never happen. parsedFile = unit.ToTypeSystem(); content = content.AddOrUpdateFiles(parsedFile); compilation = content.CreateCompilation(); } foreach (var scope in scopes) { refFinder.FindReferencesInFile( scope, parsedFile, unit, compilation, (astNode, result) => { var newRef = GetReference(project, result, astNode, unit, file, editor); if (newRef == null || refs.Any(r => r.FileName == newRef.FileName && r.Region == newRef.Region)) { return; } refs.Add(newRef); }, CancellationToken.None ); } } } return(refs); }
public static string GenerateRtf(TextEditorData data) { return(GenerateRtf(ColoredSegment.GetChunks(data, new TextSegment(0, data.Length)), data.ColorStyle, data.Options)); }
public FindTypeReferencesVisitor(TextEditorData data, IResolver resolver) { this.data = data; this.resolver = resolver; }
public DocGenerator(TextEditorData data) { // this.data = data; }
public static ICSharpCode.NRefactory.PlayScript.SyntaxTree Parse(this ICSharpCode.NRefactory.PlayScript.PlayScriptParser parser, TextEditorData data) { using (var stream = data.OpenStream()) { return(parser.Parse(stream, data.Document.FileName)); } }
public DomSpacingVisitor(CSharpFormattingPolicy policy, TextEditorData data) { this.policy = policy; this.data = data; AutoAcceptChanges = true; }
public JSonIndentationTracker(TextEditorData data, CacheIndentEngine stateTracker) { this.data = data; this.stateTracker = stateTracker; }
public List <ReferenceSegment> Decompile(TextEditorData data, ITreeNavigator navigator, bool publicOnly) { return(Disassemble(data, navigator)); }
TextEditorData CreateDataWithSpaces () { var data = new TextEditorData (); data.IndentationTracker = new SpacesIndentTracker (); data.Options = new TextEditorOptions () { TabsToSpaces = true, IndentStyle = IndentStyle.Virtual }; return data; }
static void SetCaretMode (CaretMode mode, TextEditorData data) { if (data.Caret.Mode == mode) return; data.Caret.Mode = mode; data.Document.RequestUpdate (new SinglePositionUpdate (data.Caret.Line, data.Caret.Column)); data.Document.CommitDocumentUpdate (); }
public void RemoveLocal(TextEditorData data) { localUpdate.Remove(data); data.Document.TextReplaced -= HandleDataDocumentTextReplaced; }
public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier) { cursorPositionBeforeKeyPress = Editor.CursorPosition; bool isSomethingSelected = Editor.SelectionEndPosition - Editor.SelectionStartPosition > 0; if (key == Gdk.Key.BackSpace && TextEditorData.Caret.Offset == lastInsertedSemicolon) { TextEditorData.Document.Undo(); lastInsertedSemicolon = -1; return(false); } lastInsertedSemicolon = -1; if (key == Gdk.Key.semicolon && !(textEditorData.CurrentMode is TextLinkEditMode) && !DoInsertTemplate() && !isSomethingSelected && PropertyService.Get("AutoInsertMatchingBracket", false) && PropertyService.Get("SmartSemicolonPlacement", false)) { bool retval = base.KeyPress(key, keyChar, modifier); LineSegment curLine = TextEditorData.Document.GetLine(TextEditorData.Caret.Line); string text = TextEditorData.Document.GetTextAt(curLine); if (text.EndsWith(";") || text.Trim().StartsWith("for")) { return(retval); } int guessedOffset = GuessSemicolonInsertionOffset(TextEditorData, curLine); if (guessedOffset != TextEditorData.Caret.Offset) { TextEditorData.Document.EndAtomicUndo(); TextEditorData.Document.BeginAtomicUndo(); TextEditorData.Remove(TextEditorData.Caret.Offset - 1, 1); TextEditorData.Caret.Offset = guessedOffset; lastInsertedSemicolon = TextEditorData.Caret.Offset + 1; retval = base.KeyPress(key, keyChar, modifier); } return(retval); } if (key == Gdk.Key.Tab && TextEditorProperties.TabIsReindent && !(textEditorData.CurrentMode is TextLinkEditMode) && !DoInsertTemplate() && !isSomethingSelected) { int cursor = Editor.CursorPosition; if (TextEditorProperties.TabIsReindent && stateTracker.Engine.IsInsideVerbatimString) { // insert normal tab inside @" ... " if (Editor.SelectionEndPosition > 0) { Editor.SelectedText = "\t"; } else { Editor.InsertText(cursor, "\t"); } } else if (TextEditorProperties.TabIsReindent && cursor >= 1) { if (Editor.CursorColumn > 2) { int delta = cursor - this.cursorPositionBeforeKeyPress; if (delta < 2 && delta > 0) { Editor.DeleteText(cursor - delta, delta); Editor.CursorPosition = cursor - delta; } } stateTracker.UpdateEngine(); DoReSmartIndent(); } return(false); } //do the smart indent if (TextEditorProperties.IndentStyle == IndentStyle.Smart) { //capture some of the current state int oldBufLen = Editor.TextLength; int oldLine = Editor.CursorLine; bool hadSelection = Editor.SelectionEndPosition != Editor.SelectionStartPosition; //pass through to the base class, which actually inserts the character //and calls HandleCodeCompletion etc to handles completion DoPreInsertionSmartIndent(key); bool retval = base.KeyPress(key, keyChar, modifier); //handle inserted characters if (Editor.CursorPosition <= 0 || Editor.SelectionStartPosition < Editor.SelectionEndPosition) { return(retval); } char lastCharInserted = TranslateKeyCharForIndenter(key, keyChar, Editor.GetCharAt(Editor.CursorPosition - 1)); if (lastCharInserted == '\0') { return(retval); } stateTracker.UpdateEngine(); bool reIndent = false; if (key == Gdk.Key.Return && modifier == Gdk.ModifierType.ControlMask) { FixLineStart(textEditorData.Caret.Line + 1); } else { if (!(oldLine == Editor.CursorLine && lastCharInserted == '\n') && (oldBufLen != Editor.TextLength || lastCharInserted != '\0')) { DoPostInsertionSmartIndent(lastCharInserted, hadSelection, out reIndent); } } //reindent the line after the insertion, if needed //N.B. if the engine says we need to reindent, make sure that it's because a char was //inserted rather than just updating the stack due to moving around stateTracker.UpdateEngine(); bool automaticReindent = (stateTracker.Engine.NeedsReindent && lastCharInserted != '\0'); if (reIndent || automaticReindent) { DoReSmartIndent(); } if (lastCharInserted == '\n') { RunFormatter(); stateTracker.UpdateEngine(); // DoReSmartIndent (); } stateTracker.UpdateEngine(); return(retval); } if (TextEditorProperties.IndentStyle == IndentStyle.Auto && TextEditorProperties.TabIsReindent && key == Gdk.Key.Tab) { bool retval = base.KeyPress(key, keyChar, modifier); DoReSmartIndent(); return(retval); } //pass through to the base class, which actually inserts the character //and calls HandleCodeCompletion etc to handles completion return(base.KeyPress(key, keyChar, modifier)); }
public static void AdvancedBackspace(TextEditorData data) { RemoveCharBeforCaret(data); //DeleteActions.Backspace (data, RemoveCharBeforCaret); }
public ChangeInsideDoubleQuotesCommand(TextEditorData editor) : base(editor) { }
static int GuessSemicolonInsertionOffset(TextEditorData data, LineSegment curLine) { int offset = data.Caret.Offset; int lastNonWsOffset = offset; int max = curLine.Offset + curLine.EditableLength; // if the line ends with ';' the line end is not the correct place for a new semicolon. if (curLine.EditableLength > 0 && data.Document.GetCharAt(max - 1) == ';') { return(offset); } bool isInString = false, isInChar = false, isVerbatimString = false; bool isInLineComment = false, isInBlockComment = false; for (int pos = offset; pos < max; pos++) { char ch = data.Document.GetCharAt(pos); switch (ch) { case '/': if (isInBlockComment) { if (pos > 0 && data.Document.GetCharAt(pos - 1) == '*') { isInBlockComment = false; } } else if (!isInString && !isInChar && pos + 1 < max) { char nextChar = data.Document.GetCharAt(pos + 1); if (nextChar == '/') { isInLineComment = true; return(lastNonWsOffset); } if (!isInLineComment && nextChar == '*') { isInBlockComment = true; return(lastNonWsOffset); } } break; case '\\': if (isInChar || (isInString && !isVerbatimString)) { pos++; } break; case '@': if (!(isInString || isInChar || isInLineComment || isInBlockComment) && pos + 1 < max && data.Document.GetCharAt(pos + 1) == '"') { isInString = true; isVerbatimString = true; pos++; } break; case '"': if (!(isInChar || isInLineComment || isInBlockComment)) { if (isInString && isVerbatimString && pos + 1 < max && data.Document.GetCharAt(pos + 1) == '"') { pos++; } else { isInString = !isInString; isVerbatimString = false; } } break; case '\'': if (!(isInString || isInLineComment || isInBlockComment)) { isInChar = !isInChar; } break; } if (!char.IsWhiteSpace(ch)) { lastNonWsOffset = pos; } } return(lastNonWsOffset); }
public static TooltipInformation CreateTooltipInformation(ICompilation compilation, CSharpUnresolvedFile file, TextEditorData textEditorData, MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy formattingPolicy, IType type, bool smartWrap, bool createFooter = false) { var tooltipInfo = new TooltipInformation(); var resolver = file != null?file.GetResolver(compilation, textEditorData.Caret.Location) : new CSharpResolver(compilation); var sig = new SignatureMarkupCreator(resolver, formattingPolicy.CreateOptions()); sig.BreakLineAfterReturnType = smartWrap; try { tooltipInfo.SignatureMarkup = sig.GetMarkup(type.IsParameterized ? type.GetDefinition() : type); } catch (Exception e) { LoggingService.LogError("Got exception while creating markup for :" + type, e); return(new TooltipInformation()); } if (type.IsParameterized) { var typeInfo = new StringBuilder(); for (int i = 0; i < type.TypeParameterCount; i++) { typeInfo.AppendLine(type.GetDefinition().TypeParameters [i].Name + " is " + sig.GetTypeReferenceString(type.TypeArguments [i])); } tooltipInfo.AddCategory("Type Parameters", typeInfo.ToString()); } var def = type.GetDefinition(); if (def != null) { if (createFooter && !string.IsNullOrEmpty(def.ParentAssembly.AssemblyName)) { tooltipInfo.FooterMarkup = "<small> From " + AmbienceService.EscapeText(def.ParentAssembly.AssemblyName) + "</small>"; } tooltipInfo.SummaryMarkup = AmbienceService.GetSummaryMarkup(def) ?? ""; } return(tooltipInfo); }
public static TextEditorData Create(string content, ITextEditorOptions options = null) { var data = new TextEditorData(); data.Options.DefaultEolMarker = eolMarker; data.Options.IndentStyle = IndentStyle.Smart; if (options != null) { data.Options = options; } var sb = new StringBuilder(); int caretIndex = -1, selectionStart = -1, selectionEnd = -1; var foldSegments = new List <FoldSegment> (); var foldStack = new Stack <FoldSegment> (); for (int i = 0; i < content.Length; i++) { var ch = content [i]; switch (ch) { case '$': caretIndex = sb.Length; break; case '<': if (i + 1 < content.Length) { if (content [i + 1] == '-') { selectionStart = sb.Length; i++; break; } } goto default; case '-': if (i + 1 < content.Length) { var next = content [i + 1]; if (next == '>') { selectionEnd = sb.Length; i++; break; } if (next == '[') { var segment = new FoldSegment(data.Document, "...", sb.Length, 0, FoldingType.None); segment.IsFolded = false; foldStack.Push(segment); i++; break; } } goto default; case '+': if (i + 1 < content.Length) { var next = content [i + 1]; if (next == '[') { var segment = new FoldSegment(data.Document, "...", sb.Length, 0, FoldingType.None); segment.IsFolded = true; foldStack.Push(segment); i++; break; } } goto default; case ']': if (foldStack.Count > 0) { FoldSegment segment = foldStack.Pop(); segment.Length = sb.Length - segment.Offset; foldSegments.Add(segment); break; } goto default; default: sb.Append(ch); break; } } data.Text = sb.ToString(); if (caretIndex >= 0) { data.Caret.Offset = caretIndex; } if (selectionStart >= 0) { if (caretIndex == selectionStart) { data.SetSelection(selectionEnd, selectionStart); } else { data.SetSelection(selectionStart, selectionEnd); if (caretIndex < 0) { data.Caret.Offset = selectionEnd; } } } if (foldSegments.Count > 0) { data.Document.UpdateFoldSegments(foldSegments); } return(data); }
public static TooltipInformation CreateTooltipInformation(ICompilation compilation, CSharpUnresolvedFile file, CSharpResolver resolver, TextEditorData textEditorData, MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy formattingPolicy, IEntity entity, bool smartWrap, bool createFooter = false) { var tooltipInfo = new TooltipInformation(); if (resolver == null) { resolver = file != null?file.GetResolver(compilation, textEditorData.Caret.Location) : new CSharpResolver(compilation); } var sig = new SignatureMarkupCreator(resolver, formattingPolicy.CreateOptions()); sig.BreakLineAfterReturnType = smartWrap; try { tooltipInfo.SignatureMarkup = sig.GetMarkup(entity); } catch (Exception e) { LoggingService.LogError("Got exception while creating markup for :" + entity, e); return(new TooltipInformation()); } tooltipInfo.SummaryMarkup = AmbienceService.GetSummaryMarkup(entity) ?? ""; if (entity is IMember) { var evt = (IMember)entity; if (evt.ReturnType.Kind == TypeKind.Delegate) { tooltipInfo.AddCategory(GettextCatalog.GetString("Delegate Info"), sig.GetDelegateInfo(evt.ReturnType)); } } if (entity is IMethod) { var method = (IMethod)entity; if (method.IsExtensionMethod) { tooltipInfo.AddCategory(GettextCatalog.GetString("Extension Method from"), method.DeclaringTypeDefinition.FullName); } } if (createFooter) { if (entity is IType) { var type = entity as IType; var def = type.GetDefinition(); if (def != null) { if (!string.IsNullOrEmpty(def.ParentAssembly.AssemblyName)) { var project = def.GetSourceProject(); if (project != null) { var relPath = FileService.AbsoluteToRelativePath(project.BaseDirectory, def.Region.FileName); tooltipInfo.FooterMarkup = "<small>" + GettextCatalog.GetString("Project:\t{0}", AmbienceService.EscapeText(def.ParentAssembly.AssemblyName)) + "</small>" + Environment.NewLine + "<small>" + GettextCatalog.GetString("File:\t\t{0} (line {1})", AmbienceService.EscapeText(relPath), def.Region.Begin.Line) + "</small>"; } } } } else if (entity.DeclaringTypeDefinition != null) { var project = entity.DeclaringTypeDefinition.GetSourceProject(); if (project != null) { var relPath = FileService.AbsoluteToRelativePath(project.BaseDirectory, entity.Region.FileName); tooltipInfo.FooterMarkup = "<small>" + GettextCatalog.GetString("Project:\t{0}", AmbienceService.EscapeText(project.Name)) + "</small>" + Environment.NewLine + "<small>" + GettextCatalog.GetString("From:\t{0}", AmbienceService.EscapeText(entity.DeclaringType.FullName)) + "</small>" + Environment.NewLine + "<small>" + GettextCatalog.GetString("File:\t\t{0} (line {1})", AmbienceService.EscapeText(relPath), entity.Region.Begin.Line) + "</small>"; } } } return(tooltipInfo); }
public static TooltipInformation CreateTooltipInformation(ICompilation compilation, CSharpUnresolvedFile file, TextEditorData textEditorData, MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy formattingPolicy, IEntity entity, bool smartWrap, bool createFooter = false) { return(CreateTooltipInformation(compilation, file, null, textEditorData, formattingPolicy, entity, smartWrap, createFooter)); }
protected override void OnRemovedFromEditor(TextEditorData data) { SetCaretMode(CaretMode.Insert, data); }
public TemplateResult FillVariables(TemplateContext context) { var expansion = CodeTemplateService.GetExpansionObject(this); var result = new TemplateResult(); var sb = new StringBuilder(); int lastOffset = 0; string code = context.Document.Editor.FormatString(context.InsertPosition, context.TemplateCode); result.TextLinks = new List <TextLink> (); foreach (Match match in variableRegEx.Matches(code)) { string name = match.Groups [1].Value; sb.Append(code.Substring(lastOffset, match.Index - lastOffset)); lastOffset = match.Index + match.Length; if (string.IsNullOrEmpty(name)) // $$ is interpreted as $ { sb.Append("$"); } else if (name == "end") { result.CaretEndOffset = sb.Length; } else if (name == "selected") { if (!string.IsNullOrEmpty(context.SelectedText)) { string indent = GetIndent(sb); string selection = Reindent(context.SelectedText, indent); sb.Append(selection); } } if (!variableDecarations.ContainsKey(name)) { continue; } TextLink link = result.TextLinks.Find(l => l.Name == name); bool isNew = link == null; if (isNew) { link = new TextLink(name); if (!string.IsNullOrEmpty(variableDecarations [name].ToolTip)) { link.Tooltip = GettextCatalog.GetString(variableDecarations [name].ToolTip); } link.Values = new CodeTemplateListDataProvider(variableDecarations [name].Values); if (!string.IsNullOrEmpty(variableDecarations [name].Function)) { link.Values = expansion.RunFunction(context, null, variableDecarations [name].Function); } result.TextLinks.Add(link); } link.IsEditable = variableDecarations [name].IsEditable; link.IsIdentifier = variableDecarations [name].IsIdentifier; if (!string.IsNullOrEmpty(variableDecarations [name].Function)) { IListDataProvider <string> functionResult = expansion.RunFunction(context, null, variableDecarations [name].Function); if (functionResult != null && functionResult.Count > 0) { string s = (string)functionResult [functionResult.Count - 1]; if (s == null) { if (variableDecarations.ContainsKey(name)) { s = variableDecarations [name].Default; } } if (s != null) { link.AddLink(new TextSegment(sb.Length, s.Length)); if (isNew) { link.GetStringFunc = delegate(Func <string, string> callback) { return(expansion.RunFunction(context, callback, variableDecarations [name].Function)); }; } sb.Append(s); } } else { AddDefaultValue(sb, link, name); } } else { AddDefaultValue(sb, link, name); } } sb.Append(code.Substring(lastOffset, code.Length - lastOffset)); // format & indent template code var data = new TextEditorData(); data.Text = sb.ToString(); data.Document.TextReplaced += delegate(object sender, DocumentChangeEventArgs e) { int delta = e.ChangeDelta; foreach (var link in result.TextLinks) { link.Links = new List <TextSegment> (link.Links.AdjustSegments(e)); } if (result.CaretEndOffset > e.Offset) { result.CaretEndOffset += delta; } }; IndentCode(data, context.LineIndent); result.Code = data.Text; data.Dispose(); return(result); }
protected override void OnAddedToEditor(TextEditorData data) { ViEditor.SetMode(ViEditorMode.Normal); SetCaretMode(CaretMode.Block, data); ViActions.RetreatFromLineEnd(data); }
public ChangeInsideBracketsCommand(TextEditorData editor) : base(editor) { }
public static CommandRange QuotedString(TextEditorData editor, char quotationChar) { var start = editor.Caret.Offset; var end = editor.Caret.Offset; var lineOffset = editor.GetLine(editor.Caret.Line).Offset; var lineEndOffset = editor.GetLine(editor.Caret.Line).EndOffset - 1; // Line includes \n if (editor.Text[start] == quotationChar) { // Check if we're on closing char start = lineOffset; var openingCandidate = -1; while (start < end) { if (editor.Text[start] == quotationChar & openingCandidate != -1) { openingCandidate = -1; } else if (editor.Text[start] == quotationChar) { openingCandidate = start; } start = start + 1; } if (openingCandidate != -1) { start = openingCandidate; } else { // not on closing char, let's find closing one start = editor.Caret.Offset; end = start + 1; while (end < lineEndOffset & editor.Text[end] != quotationChar) { end++; } } } else { while (start >= lineOffset & editor.Text[start] != quotationChar) { start--; } while (end < lineEndOffset & editor.Text[end] != quotationChar) { end++; } } if (start < 0 || end > lineEndOffset || start == end) { return(CommandRange.Empty); } var endIncludingTrailingWhiteSpace = end; var startIncludingTrailingWhiteSpace = start; // expand to include all trailing white space while (endIncludingTrailingWhiteSpace < lineEndOffset && Char.IsWhiteSpace(editor.Text[endIncludingTrailingWhiteSpace + 1])) { endIncludingTrailingWhiteSpace++; } // if there's no trailing white space then include leading if (endIncludingTrailingWhiteSpace == end) { while (startIncludingTrailingWhiteSpace > lineOffset && Char.IsWhiteSpace(editor.Text[startIncludingTrailingWhiteSpace - 1])) { startIncludingTrailingWhiteSpace--; } } return(new CommandRange(Math.Min(start, startIncludingTrailingWhiteSpace), Math.Max(end, endIncludingTrailingWhiteSpace) + 1)); }
protected override void OnRemovedFromEditor (TextEditorData data) { SetCaretMode (CaretMode.Insert, data); }
public AppendCommand(TextEditorData editor) : base(editor) { }
public DeleteInsideSingleQuotesCommand(TextEditorData editor) : base(editor) { }
public DeleteInsideBracesCommand(TextEditorData editor) : base(editor) { }
public TestViEditMode (TextEditorData data) { data.CurrentMode = this; textEditorData = data; // Currently doesn't work on my mac (test doesn't terminate with mono 2.6.7). // var f = typeof (EditMode).GetField ("textEditorData", BindingFlags.NonPublic | BindingFlags.Instance); // f.SetValue (this, data); data.Caret.PositionChanged += delegate(object sender, DocumentLocationEventArgs e) { if (!inputting) this.CaretPositionChanged (); }; data.SelectionChanged += delegate(object sender, EventArgs e) { if (!inputting) this.SelectionChanged (); }; }
public DeleteInsideParenthesesCommand(TextEditorData editor) : base(editor) { }
public static string GenerateRtf (TextEditorData data) { return GenerateRtf (data.Document, data.Document.SyntaxMode, data.ColorStyle, data.Options); }
public ClosingMenuDelegate(TextEditorData editor_data) { data = editor_data; }