[gnome-builder/wip/gtk4-port] plugins/editorui: implement jump to line:column



commit 15d6c91168b8c5cca15b4ecdd7d9814508760bc3
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 1 21:13:36 2022 -0700

    plugins/editorui: implement jump to line:column

 .../editorui/gbp-editorui-workspace-addin.c        | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
---
diff --git a/src/plugins/editorui/gbp-editorui-workspace-addin.c 
b/src/plugins/editorui/gbp-editorui-workspace-addin.c
index c5e17f671..84427a42e 100644
--- a/src/plugins/editorui/gbp-editorui-workspace-addin.c
+++ b/src/plugins/editorui/gbp-editorui-workspace-addin.c
@@ -65,6 +65,8 @@ struct _GbpEditoruiWorkspaceAddin
   GSettings                *editor_settings;
 
   guint                     queued_cursor_moved;
+
+  IdeEditorPage            *page;
 };
 
 #define clear_from_statusbar(s,w) clear_from_statusbar(s, (GtkWidget **)w)
@@ -351,6 +353,31 @@ new_file (GSimpleAction *action,
   IDE_EXIT;
 }
 
+static void
+go_to_line_activate_cb (GbpEditoruiWorkspaceAddin *self,
+                        const char                *str,
+                        IdeEntryPopover           *entry)
+{
+  int line = -1;
+  int column = -1;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_EDITORUI_WORKSPACE_ADDIN (self));
+  g_assert (IDE_IS_ENTRY_POPOVER (entry));
+
+  if (ide_str_empty0 (str) || sscanf (str, "%d:%d", &line, &column) < 1)
+    IDE_EXIT;
+
+  line--;
+  column--;
+
+  ide_editor_page_scroll_to_visual_position (self->page, MAX (0, line), MAX (0, column));
+  gtk_widget_grab_focus (GTK_WIDGET (self->page));
+
+  IDE_EXIT;
+}
+
 static gboolean
 go_to_line_insert_text_cb (GbpEditoruiWorkspaceAddin *self,
                            guint                      pos,
@@ -537,6 +564,11 @@ gbp_editorui_workspace_addin_load (IdeWorkspaceAddin *addin,
                            G_CALLBACK (go_to_line_insert_text_cb),
                            self,
                            G_CONNECT_SWAPPED);
+  g_signal_connect_object (popover,
+                           "activate",
+                           G_CALLBACK (go_to_line_activate_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
   self->position_label = g_object_new (GBP_TYPE_EDITORUI_POSITION_LABEL, NULL);
   self->position = g_object_new (GTK_TYPE_MENU_BUTTON,
                                  "direction", GTK_ARROW_UP,
@@ -615,6 +647,8 @@ gbp_editorui_workspace_addin_page_changed (IdeWorkspaceAddin *addin,
   if (!IDE_IS_EDITOR_PAGE (page))
     page = NULL;
 
+  self->page = IDE_EDITOR_PAGE (page);
+
   if (page != NULL)
     {
       g_autoptr(GPropertyAction) encoding_action = NULL;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]