private void AddTask(Task task) { if (!CheckTask(task)) { return; } ISourceEditor editor = Document as ISourceEditor; if (task.Line >= 1 && task.Line <= editor.TextEditor.LineCount) { int offset = editor.TextEditor.Document.GetOffset(new TextLocation(task.Line, task.Column)); int length = task.Length == 0 ? EditorHelper.GetWordAt(editor.TextEditor.Document, offset).Length : task.Length; if (length < 2) { // marker should be at least 2 characters long, but take care that we don't make // it longer than the document length = Math.Min(2, editor.TextEditor.Document.TextLength - offset); } ITextMarker marker = MarkerService.Create(editor, offset, length); marker.PropertyChanged += (sender, args) => { ITextMarker m = sender as ITextMarker; editor.TextEditor.TextArea.TextView.Redraw(m, DispatcherPriority.Normal); }; Color markerColor = Colors.Transparent; switch (task.TaskType) { case TaskType.Error: markerColor = Colors.Red; break; case TaskType.Message: markerColor = Colors.Blue; break; case TaskType.Warning: markerColor = Colors.Orange; break; } marker.MarkerColor = markerColor; marker.MarkerType = task.Underline ? TextMarkerType.SquigglyUnderline : TextMarkerType.None; marker.ToolTip = task.Description; marker.Tag = task; } }
public IEnumerable <ITextMarker> TextMarkers(ISourceEditor editor) { TextSegmentCollection <TextMarker> markers; if (markersMap.TryGetValue(editor.TextEditor.Document, out markers)) { return(markers); } else { return(null); } }
private void OnDoubleClick(object sender, RoutedEventArgs e) { DependencyObject dep = (DependencyObject)e.OriginalSource; while ((dep != null) && !(dep is ListViewItem)) { dep = VisualTreeHelper.GetParent(dep); } if (dep == null) { return; } object[] item = (object[])m_ListView.ItemContainerGenerator.ItemFromContainer(dep); FileName fileName = (FileName)item[3]; int line = (int)item[4]; int column = (int)item[5]; OpenedFile file = FileService.GetOpenedFile(fileName); if (file != null) { if (file.Document is ISourceEditor) { ISourceEditor sourceEditor = file.Document as ISourceEditor; var markersAtOffset = MarkerService.GetMarkersAtOffset(sourceEditor.TextEditor.Document, sourceEditor.TextEditor.Document.GetOffset(new TextLocation(line, column))); if (markersAtOffset == null) { return; } ITextMarker marker = markersAtOffset.FirstOrDefault(); if (marker == null) { return; } TextArea area = sourceEditor.TextEditor.TextArea; layoutManager.Value.ShowDocument(sourceEditor, true); area.Selection = Selection.Create(area, marker.Offset, marker.EndOffset); area.Caret.Line = line; area.Caret.Column = column; sourceEditor.TextEditor.ScrollTo(line, column); sourceEditor.TextEditor.Focus(); } } }
void file_DocumentInitialized(object sender, EventArgs ea) { OpenedFile file = sender as OpenedFile; if (file.Document is ISourceEditor) { ISourceEditor editor = (ISourceEditor)file.Document; editor.TextEditor.TextArea.Document.TextChanged += (s, e) => { Analyze(file); editor.TextEditor.Focus(); }; Analyze(file); } }
public void Analyze(OpenedFile file) { List <Task> toRemove = new List <Task>(); foreach (Task t in tasks) { if (t.FileName.Equals(file.FileName)) { TaskService.Remove(t); toRemove.Add(t); } } foreach (Task t in toRemove) { tasks.Remove(t); } ISourceEditor editor = (ISourceEditor)file.Document; string text = editor.SourceCode; StringSearch search = new StringSearch(keywords); StringSearchResult[] results = search.FindAll(text); foreach (StringSearchResult ssr in results) { DocumentLine docLine = editor.TextEditor.Document.GetLineByOffset(ssr.Index); int line = docLine.LineNumber; int column = ssr.Index - docLine.Offset + 1; int length = docLine.Length - column + 1; string description = editor.TextEditor.Document.GetText(ssr.Index, length).Remove(0, 3); Task task = new Task(file.FileName, TaskType.Message, line, column, length, description); task.Underline = false; tasks.Add(task); TaskService.Add(task); } }
public ITextMarker Create(ISourceEditor editor, int startOffset, int length) { int textLength = editor.TextEditor.Document.TextLength; if (startOffset < 0 || startOffset > textLength) { throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be between 0 and " + textLength); } if (length < 0 || startOffset + length > textLength) { throw new ArgumentOutOfRangeException("length", length, "length must not be negative and startOffset+length must not be after the end of the document"); } TextMarker m = new TextMarker(startOffset, length); if (!markersMap.ContainsKey(editor.TextEditor.Document)) { markersMap.Add(editor.TextEditor.Document, new TextSegmentCollection <TextMarker>(editor.TextEditor.Document)); } markersMap[editor.TextEditor.Document].Add(m); // no need to mark segment for redraw: the text marker is invisible until a property is set return(m); }