private void NotesEditor_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { // Ctrl+Click Go to notes var position = NotesEditor.GetPositionFromPoint(e.GetPosition(NotesEditor.TextArea.TextView)); if (position != null) { // Get the line clicked. var clicked_line_no = position.Value.Line; var line_offset = NotesEditor.Document.GetLineByNumber(clicked_line_no); var line = NotesEditor.Document.GetText(line_offset.Offset, line_offset.Length); // Check if there is a link in the line: check with regex if (Regex.IsMatch(line, notes_link_regex)) { // Check if click is within link (if there is one). // Parse link and move to vertex. var match_object = Regex.Match(line, notes_link_regex); var vert_id = int.Parse(match_object.Groups["vertex_id"].Value); var file_name = match_object.Groups["file_name"].Value; var line_no = int.Parse(match_object.Groups["line_no"].Value); var no_lines = int.Parse(match_object.Groups["no_lines"].Value); var vertex = graph_provider.GetVertexById(vert_id); VertexControl vc = graph_area.GetAllVertexControls().Where(x => x.Vertex == vertex).FirstOrDefault(); TextEditor te = TreeHelpers.FindVisualChild <TextEditor>((DependencyObject)vc); te.TextArea.TextView.BackgroundRenderers.Add(new HighlightNotesSnippetBackgroundRenderer(te, line_no, no_lines)); te.ScrollToLine(line_no); Expander ex = TreeHelpers.FindVisualParent <Expander>(te); if (!ex.IsExpanded) { ex.IsExpanded = true; } CenterOnVertex(vc); } } e.Handled = true; } }
private void AddFileView(FileItem file_item, VertexControl source, PocVertex source_vertex, List <int> lines = null) { if (!graph_provider.root_vertex.CtagsRun) { System.Windows.Forms.MessageBox.Show("Ctags is still running, so tags are not available.", "Ctags running", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } FileVertex new_vertex = graph_provider.AddFileView(file_item, source_vertex); VertexControl new_vertex_control = new VertexControl(new_vertex) { DataContext = new_vertex }; try { graph_area.AddVertex(new_vertex, new_vertex_control); } catch (GraphX.GX_InvalidDataException) { new_vertex_control = graph_area.GetAllVertexControls().Where(c => c.Vertex == new_vertex).First(); } PocEdge new_edge = new PocEdge(source_vertex, new_vertex); graph_area.InsertEdge(new_edge, new EdgeControl(source, new_vertex_control, new_edge)); graph_area.RelayoutGraph(true); graph_area.UpdateLayout(); centre_on_me = new_vertex_control; ICSharpCode.AvalonEdit.TextEditor editor = TreeHelpers.FindVisualChild <ICSharpCode.AvalonEdit.TextEditor>(new_vertex_control); if (editor != null && editor != NotesEditor) { editor.TextArea.TextView.MouseDown += TestEditor_MouseDown; editor.TextArea.SelectionChanged += TestEditor_SelectionChanged; if (graph_provider.root_vertex.CtagsRun) { editor.TextArea.TextView.LineTransformers.Add(new UnderlineCtagsMatches(graph_provider.root_vertex.CtagsMatches.Keys.ToList())); } if (lines != null) { editor.TextArea.TextView.BackgroundRenderers.Add(new HighlightSearchLineBackgroundRenderer(editor, lines)); editor.ScrollToLine(lines.Min()); } editor.Width = editor.ActualWidth; } }
private void ExpanderRelayout(object sender, RoutedEventArgs e) { Expander expander = e.Source as Expander; recentre = expander.IsExpanded; VertexControl parent_vertex_control = TreeHelpers.FindVisualParent <VertexControl>(e.Source as Expander); if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) { foreach (PocEdge edge in graph_area.Graph.OutEdges((PocVertex)parent_vertex_control.Vertex)) { VertexControl vc = graph_area.GetAllVertexControls().Where(x => x.Vertex == edge.Target).FirstOrDefault(); var new_expander = TreeHelpers.FindVisualChild <Expander>(vc); if (new_expander != null) { new_expander.IsExpanded = expander.IsExpanded; } } } RelayoutGraph(parent_vertex_control); }
private Task SearchForString(string selected_text, VertexControl from_vertex_control, List <string> extensions_to_search = null) { if (selected_text != null && selected_text != "") { PocVertex from_vertex = (PocVertex)from_vertex_control.Vertex; SearchResultsVertex new_search_results_vertex = graph_provider.PerformSearch(selected_text, from_vertex, extensions_to_search); VertexControl new_search_results_vertex_control = new VertexControl(new_search_results_vertex) { DataContext = new_search_results_vertex }; graph_area.AddVertex(new_search_results_vertex, new_search_results_vertex_control); PocEdge new_edge = new PocEdge((PocVertex)from_vertex_control.Vertex, new_search_results_vertex); graph_area.InsertEdge(new_edge, new EdgeControl(from_vertex_control, new_search_results_vertex_control, new_edge)); graph_area.RelayoutGraph(true); graph_area.UpdateLayout(); centre_on_me = new_search_results_vertex_control; System.Windows.Controls.DataGrid grid = TreeHelpers.FindVisualChild <System.Windows.Controls.DataGrid>(new_search_results_vertex_control); System.Windows.Controls.ProgressBar bar = TreeHelpers.FindVisualChild <System.Windows.Controls.ProgressBar>(new_search_results_vertex_control); if (still_counting) { bar.Maximum = 100; } else { bar.Maximum = directory_count; } var search_progress = new Progress <int>((int some_int) => ReportProgress(bar)); return(graph_provider.PopulateResultsAsync(selected_text, new_search_results_vertex, search_progress)); //bar.Visibility = System.Windows.Visibility.Collapsed; //grid.Visibility = System.Windows.Visibility.Visible; } return(new Task(() => { })); }