Пример #1
0
        private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            SearchResult result = (SearchResult)((System.Windows.Controls.DataGridRow)sender).Item;

            result.Checked = true;
            FileItem fi = new FileItem {
                FileName = result.FileName, FullPath = result.FullPath, Extension = result.Extension, RelPath = result.RelPath
            };

            VertexControl sv = TreeHelpers.FindVisualParent <VertexControl>(sender as DataGridRow);

            AddFileView(fi, sv, (PocVertex)sv.Vertex, result.LineNumber);
            graph_provider.SaveGraph();
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
        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();
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        private void TestEditor_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                TextEditor editor    = TreeHelpers.FindVisualParent <TextEditor>((DependencyObject)sender);
                var        file_path = ((FileVertex)TreeHelpers.FindVisualParent <VertexControl>((DependencyObject)editor).Vertex).FilePath;

                // Ctrl+Click Go to definition
                var position = editor.GetPositionFromPoint(e.GetPosition(editor));
                if (position != null)
                {
                    var clicked_line_no = position.Value.Line;
                    var offset          = editor.Document.GetOffset(position.Value.Location);
                    var start           = TextUtilities.GetNextCaretPosition(editor.Document, offset, LogicalDirection.Backward, CaretPositioningMode.WordBorder);
                    if (start < 0)
                    {
                        return;
                    }
                    var end  = TextUtilities.GetNextCaretPosition(editor.Document, offset, LogicalDirection.Forward, CaretPositioningMode.WordBorder);
                    var word = editor.Document.GetText(start, end - start);
                    //System.Diagnostics.Debug.Print(word);

                    if (graph_provider.root_vertex.CtagsRun && graph_provider.root_vertex.CtagsMatches.ContainsKey(word))
                    {
                        Dictionary <string, List <int> > files_and_lines = new Dictionary <string, List <int> >();
                        //foreach (string line in ctags_info.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries))
                        //{
                        //System.Diagnostics.Debug.Print(line);
                        foreach (List <string> match in graph_provider.root_vertex.CtagsMatches[word])
                        {
                            int line_no = 1;
                            foreach (string field in match)
                            {
                                if (field.StartsWith("line:"))
                                {
                                    line_no = int.Parse(field.Split(new char[] { ':' })[1]);
                                }
                            }
                            var file_path_to_add = match[1];
                            if ((file_path_to_add != file_path) || ((file_path_to_add == file_path) && (line_no != clicked_line_no)))
                            {
                                if (files_and_lines.ContainsKey(file_path_to_add))
                                {
                                    files_and_lines[match[1]].Add(line_no);
                                }
                                else
                                {
                                    files_and_lines[file_path_to_add] = new List <int>();
                                    files_and_lines[file_path_to_add].Add(line_no);
                                }
                            }
                        }
                        if (files_and_lines.Count() > 0)
                        {
                            VertexControl editor_vertex = TreeHelpers.FindVisualParent <VertexControl>(editor);
                            VertexControl ctags_vertex  = AddCtagsAnchor(word, editor_vertex, (PocVertex)editor_vertex.Vertex);
                            foreach (string file in files_and_lines.Keys)
                            {
                                FileItem fi = new FileItem
                                {
                                    FileName  = Path.GetFileName(file),
                                    FullPath  = Path.Combine(graph_provider.root_dir, file),
                                    Extension = Path.GetExtension(file),
                                    RelPath   = file,
                                };
                                //if (!(Path.GetFullPath(((FileVertex)editor_vertex.Vertex).FilePath) == Path.GetFullPath(fi.FullPath) && !files_and_lines[file].Contains(position.Value.Line)))
                                //{
                                AddFileView(fi, ctags_vertex, (CtagsVertex)ctags_vertex.Vertex, files_and_lines[file]);
                                //}
                            }
                            graph_provider.SaveGraph();
                        }
                        if (files_and_lines.Count() == 0)
                        {
                            editor.TextArea.TextView.BackgroundRenderers.Add(new HighlightNotesSnippetBackgroundRenderer(editor, clicked_line_no, 1));
                        }
                    }
                }
                e.Handled = true;
            }
        }