public static int FindWordEnd(SD.Document.IDocument document, int offset) { SD.Document.LineSegment line = document.GetLineSegmentForOffset(offset); int endPos = line.Offset + line.Length; if (offset == endPos) { return(offset); } if (IsSelectableChar(document.GetCharAt(offset))) { while (offset < endPos && IsSelectableChar(document.GetCharAt(offset))) { ++offset; } } else if (Char.IsWhiteSpace(document.GetCharAt(offset))) { if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1))) { while (offset < endPos && Char.IsWhiteSpace(document.GetCharAt(offset))) { ++offset; } } } else { return(Math.Max(0, offset + 1)); } return(offset); }
public static void ModifyDocument(List <Modification> modifications, ICSharpCode.TextEditor.Document.IDocument doc, int offset, int length, string newName) { doc.UndoStack.StartUndoGroup(); foreach (Modification m in modifications) { if (m.Document == doc) { if (m.Offset < offset) { offset += m.LengthDifference; } } } int lengthDifference = newName.Length - length; doc.Replace(offset, length, newName); if (lengthDifference != 0) { for (int i = 0; i < modifications.Count; ++i) { Modification m = modifications[i]; if (m.Document == doc) { if (m.Offset > offset) { m.Offset += lengthDifference; modifications[i] = m; // Modification is a value type } } } modifications.Add(new Modification(doc, offset, lengthDifference)); } doc.UndoStack.EndUndoGroup(); }
public void SetupDataProvider(string fileName, TextArea textArea) { try { if (setupOnlyOnce && this.textArea != null) { if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsMethodCallParameterSeparator(pressed_key)) { FindExpression(textArea.Caret.Offset, textArea.Document.TextContent.Substring(0, textArea.Caret.Offset), textArea.Caret.Line, textArea.Caret.Column); num_param++; return; } else { return; } } this.fileName = fileName; this.textArea = textArea; this.document = textArea.Document; int useOffset = (lookupOffset < 0) ? textArea.Caret.Offset : lookupOffset; initialOffset = useOffset; int i = initialOffset - 1; int off = textArea.Caret.Offset; string Text = textArea.Document.TextContent.Substring(0, textArea.Caret.Offset); int line = textArea.Caret.Line; int col = textArea.Caret.Column; string expr = FindExpression(off, Text, line, col); List <PascalABCCompiler.Errors.Error> Errors = new List <PascalABCCompiler.Errors.Error>(); PascalABCCompiler.SyntaxTree.expression e = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test.pas", expr, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>()); if (e == null || Errors.Count > 0) { return; } CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName]; string fname = fileName; if (dconv != null) { //if (pressed_key == '(' || pressed_key == ',') if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsOpenBracketForMethodCall(pressed_key) || CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsMethodCallParameterSeparator(pressed_key)) { methods = dconv.GetNameOfMethod(e, expr, line, col, num_param, ref defaultIndex, cur_param_num, out param_count); } else if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsOpenBracketForIndex(pressed_key)) { methods = dconv.GetIndex(e, line, col); } } } catch (Exception e) { } }
protected override bool IsInComment(ICSharpCode.TextEditor.Document.IDocument document, int offset) { if (offset < 0 || offset > document.TextContent.Length) { return(false); } int lineNumber = document.GetLineNumberForOffset(offset); string line = TextUtilities.GetLineAsString(document, lineNumber); return(line.StartsWith("//")); }
public void SetupDataProvider(string fileName, TextArea textArea) { try { if (setupOnlyOnce && this.textArea != null) { if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsMethodCallParameterSeparator(pressed_key)) { FindExpression(textArea.Caret.Offset,textArea.Document.TextContent.Substring(0, textArea.Caret.Offset), textArea.Caret.Line,textArea.Caret.Column); num_param++; return; } else return; } this.fileName = fileName; this.textArea = textArea; this.document = textArea.Document; int useOffset = (lookupOffset < 0) ? textArea.Caret.Offset : lookupOffset; initialOffset = useOffset; int i = initialOffset-1; int off = textArea.Caret.Offset; string Text = textArea.Document.TextContent.Substring(0, textArea.Caret.Offset); int line = textArea.Caret.Line; int col = textArea.Caret.Column; string expr = FindExpression(off, Text, line, col); List<PascalABCCompiler.Errors.Error> Errors = new List<PascalABCCompiler.Errors.Error>(); PascalABCCompiler.SyntaxTree.expression e = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test.pas", expr, Errors); if (e == null || Errors.Count > 0) return; CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName]; string fname = fileName; if (dconv != null) { //if (pressed_key == '(' || pressed_key == ',') if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsOpenBracketForMethodCall(pressed_key) || CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsMethodCallParameterSeparator(pressed_key)) methods = dconv.GetNameOfMethod(e,expr,line,col,num_param,ref defaultIndex,cur_param_num, out param_count); else if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsOpenBracketForIndex(pressed_key)) methods = dconv.GetIndex(e,line,col); } } catch(Exception e) { } }
protected override ExpressionResult GetExpression(ICSharpCode.TextEditor.TextArea textArea) { ICSharpCode.TextEditor.Document.IDocument document = textArea.Document; IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(fileName); if (expressionFinder == null) { return(new ExpressionResult(TextUtilities.GetExpressionBeforeOffset(textArea, textArea.Caret.Offset - 1))); } else { ExpressionResult res = expressionFinder.FindExpression(document.GetText(0, textArea.Caret.Offset - 1), textArea.Caret.Offset - 1); if (overrideContext != null) { res.Context = overrideContext; } return(res); } }
public static string ExtractCode(IClass c, DomRegion codeRegion, int indentationLine, out Action removeExtractedCodeAction) { ICSharpCode.TextEditor.Document.IDocument doc = GetDocument(c); if (indentationLine < 1) { indentationLine = 1; } if (indentationLine >= doc.TotalNumberOfLines) { indentationLine = doc.TotalNumberOfLines; } LineSegment segment = doc.GetLineSegment(indentationLine - 1); string mainLine = doc.GetText(segment); string indentation = mainLine.Substring(0, mainLine.Length - mainLine.TrimStart().Length); segment = doc.GetLineSegment(codeRegion.BeginLine - 1); int startOffset = segment.Offset; segment = doc.GetLineSegment(codeRegion.EndLine - 1); int endOffset = segment.Offset + segment.Length; StringReader reader = new StringReader(doc.GetText(startOffset, endOffset - startOffset)); removeExtractedCodeAction = delegate { doc.Remove(startOffset, endOffset - startOffset); doc.RequestUpdate(new ICSharpCode.TextEditor.TextAreaUpdate(ICSharpCode.TextEditor.TextAreaUpdateType.WholeTextArea)); doc.CommitUpdate(); }; // now remove indentation from extracted source code string line; StringBuilder b = new StringBuilder(); int endOfLastFilledLine = 0; while ((line = reader.ReadLine()) != null) { int startpos; for (startpos = 0; startpos < line.Length && startpos < indentation.Length; startpos++) { if (line[startpos] != indentation[startpos]) { break; } } if (startpos == line.Length) { // empty line if (b.Length > 0) { b.AppendLine(); } } else { b.Append(line, startpos, line.Length - startpos); b.AppendLine(); endOfLastFilledLine = b.Length; } } b.Length = endOfLastFilledLine; return(b.ToString()); }
public static void RenameReferences(List <Reference> list, string newName) { Dictionary <ICSharpCode.TextEditor.Document.IDocument, FileView> modifiedDocuments = new Dictionary <ICSharpCode.TextEditor.Document.IDocument, FileView>(); List <Modification> modifications = new List <Modification>(); foreach (Reference r in list) { ICSharpCode.TextEditor.Document.IDocument document = null; IViewContent viewContent = null; OpenedFile file = FileService.GetOpenedFile(r.FileName); if (file != null) { viewContent = file.CurrentView; IFileDocumentProvider p = viewContent as IFileDocumentProvider; if (p != null) { document = p.GetDocumentForFile(file); } } if (document == null) { viewContent = FileService.OpenFile(r.FileName, false); IFileDocumentProvider p = viewContent as IFileDocumentProvider; if (p != null) { file = FileService.GetOpenedFile(r.FileName); System.Diagnostics.Debug.Assert(file != null, "OpenedFile not found after opening the file."); document = p.GetDocumentForFile(file); } } if (document == null) { LoggingService.Warn("RenameReferences: Could not get document for file '" + r.FileName + "'"); continue; } if (!modifiedDocuments.ContainsKey(document)) { modifiedDocuments.Add(document, new FileView() { ViewContent = viewContent, OpenedFile = file }); document.UndoStack.StartUndoGroup(); } ModifyDocument(modifications, document, r.Offset, r.Length, newName); } foreach (KeyValuePair <ICSharpCode.TextEditor.Document.IDocument, FileView> entry in modifiedDocuments) { entry.Key.UndoStack.EndUndoGroup(); entry.Value.OpenedFile.MakeDirty(); if (entry.Value.ViewContent is IEditable) { ParserService.ParseViewContent(entry.Value.ViewContent); } else { ParserService.ParseFile(entry.Value.OpenedFile.FileName, entry.Key.TextContent, !entry.Value.OpenedFile.IsUntitled); } } }
public Modification(ICSharpCode.TextEditor.Document.IDocument document, int offset, int lengthDifference) { this.Document = document; this.Offset = offset; this.LengthDifference = lengthDifference; }
protected abstract DomRegion GetReplaceRegion(ICSharpCode.TextEditor.Document.IDocument document, IMethod method);
protected string GetIndentation(ICSharpCode.TextEditor.Document.IDocument document, int line) { string lineText = document.GetText(document.GetLineSegment(line)); return(lineText.Substring(0, lineText.Length - lineText.TrimStart().Length)); }
public ActiveMark(ICSharpCode.TextEditor.Document.IDocument d, TextLocation l) : base(d, l) { }
public NonClickableBookmark(ICSharpCode.TextEditor.Document.IDocument d, TextLocation l) : base(d, l) { }