internal FileVertex AddFileView(FileItem f, PocVertex from_vertex) { FileVertex new_vertex; FileVertex existing_file_view = (FileVertex)Graph.Vertices.Where(x => x as FileVertex != null && ((FileVertex)x).FileName == f.RelPath).FirstOrDefault(); if (existing_file_view != null) { new_vertex = new FileVertex(f.FileName, f.FullPath, root_vertex.FilePath, existing_file_view.Document); } else { new_vertex = new FileVertex(f.FileName, f.FullPath, root_vertex.FilePath); } Graph.AddVertex(new_vertex); Graph.AddEdge(new PocEdge(from_vertex, new_vertex)); return(new_vertex); }
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; } }
async private void TestEditor_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == System.Windows.Input.Key.S && !((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)) // Not doing ctrl-s to save { string selected_text = ""; TextArea textarea = e.OriginalSource as TextArea; VertexControl sv = TreeHelpers.FindVisualParent <VertexControl>(textarea); PocVertex source_vertex = (PocVertex)sv.Vertex; selected_text = textarea.Selection.GetText(); await SearchForString(selected_text, sv); } else if (e.Key == System.Windows.Input.Key.N && !((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)) // Not doing ctrl-n for new project { string selected_text = ""; string link_text = ""; TextArea textarea = e.OriginalSource as TextArea; var texteditor = Utils.TreeHelpers.FindVisualParent <TextEditor>(textarea); VertexControl sv = TreeHelpers.FindVisualParent <VertexControl>(textarea); FileVertex source_vertex = (FileVertex)sv.Vertex; selected_text = textarea.Selection.GetText(); var no_lines = 0; var start_line = ""; if (textarea.Selection.EndPosition.Line < textarea.Selection.StartPosition.Line) { no_lines = textarea.Selection.StartPosition.Line - textarea.Selection.EndPosition.Line + 1; start_line = textarea.Selection.EndPosition.Location.ToString(); } else { no_lines = textarea.Selection.EndPosition.Line - textarea.Selection.StartPosition.Line + 1; start_line = textarea.Selection.StartPosition.Location.ToString(); } link_text = source_vertex.ID.ToString() + ":" + source_vertex.FileName + ":" + start_line + ":" + no_lines.ToString(); NotesEditor.TextArea.Document.Text += "\n\n"; NotesEditor.TextArea.Document.Text += link_text + "\n"; NotesEditor.TextArea.Document.Text += selected_text; NotesEditor.TextArea.Document.Text += "\n\n"; NotesEditor.ScrollToEnd(); graph_provider.SaveNotes(); } }