[gnome-builder/wip/gtk4-port] libide/gui: add position when opening files



commit 72bf645cff9aa271e72ab5b5398f4ec92b9d90a4
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 7 15:02:54 2022 -0700

    libide/gui: add position when opening files
    
    Not everything will use this, but it is certainly useful to be able to
    plumb the destination position across all the workbench loading
    abstractions including addins.

 src/libide/gui/ide-workbench-addin.c                  |  4 ++++
 src/libide/gui/ide-workbench-addin.h                  |  7 +++++++
 src/libide/gui/ide-workbench.c                        | 16 +++++++++++++++-
 src/libide/gui/ide-workbench.h                        |  2 ++
 src/libide/terminal/ide-terminal.c                    |  2 +-
 src/plugins/editorui/gbp-editorui-workbench-addin.c   |  5 +++++
 .../open-with-external/gbp-owe-workbench-addin.c      |  1 +
 src/plugins/project-tree/gbp-project-tree-addin.c     |  2 +-
 .../project-tree/gbp-project-tree-pane-actions.c      | 19 ++++++++++++++++---
 src/plugins/todo/gbp-todo-panel.c                     |  2 +-
 10 files changed, 53 insertions(+), 7 deletions(-)
---
diff --git a/src/libide/gui/ide-workbench-addin.c b/src/libide/gui/ide-workbench-addin.c
index d312b86fb..e2e335c74 100644
--- a/src/libide/gui/ide-workbench-addin.c
+++ b/src/libide/gui/ide-workbench-addin.c
@@ -77,6 +77,7 @@ ide_workbench_addin_real_open_async (IdeWorkbenchAddin   *self,
                                      int                  at_line,
                                      int                  at_line_offset,
                                      IdeBufferOpenFlags   flags,
+                                     IdePanelPosition    *position,
                                      GCancellable        *cancellable,
                                      GAsyncReadyCallback  callback,
                                      gpointer             user_data)
@@ -91,6 +92,7 @@ ide_workbench_addin_real_open_async (IdeWorkbenchAddin   *self,
                                                     at_line,
                                                     at_line_offset,
                                                     flags,
+                                                    position,
                                                     cancellable,
                                                     callback,
                                                     user_data);
@@ -246,6 +248,7 @@ ide_workbench_addin_open_async (IdeWorkbenchAddin   *self,
                                 int                  at_line,
                                 int                  at_line_offset,
                                 IdeBufferOpenFlags   flags,
+                                IdePanelPosition    *position,
                                 GCancellable        *cancellable,
                                 GAsyncReadyCallback  callback,
                                 gpointer             user_data)
@@ -260,6 +263,7 @@ ide_workbench_addin_open_async (IdeWorkbenchAddin   *self,
                                                     at_line,
                                                     at_line_offset,
                                                     flags,
+                                                    position,
                                                     cancellable,
                                                     callback,
                                                     user_data);
diff --git a/src/libide/gui/ide-workbench-addin.h b/src/libide/gui/ide-workbench-addin.h
index 89d5ae601..971380058 100644
--- a/src/libide/gui/ide-workbench-addin.h
+++ b/src/libide/gui/ide-workbench-addin.h
@@ -20,6 +20,11 @@
 
 #pragma once
 
+#if !defined (IDE_GUI_INSIDE) && !defined (IDE_GUI_COMPILATION)
+# error "Only <libide-gui.h> can be included directly."
+#endif
+
+#include "ide-panel-position.h"
 #include "ide-workbench.h"
 #include "ide-workspace.h"
 
@@ -70,6 +75,7 @@ struct _IdeWorkbenchAddinInterface
                                      int                    at_line,
                                      int                    at_line_offset,
                                      IdeBufferOpenFlags     flags,
+                                     IdePanelPosition      *position,
                                      GCancellable          *cancellable,
                                      GAsyncReadyCallback    callback,
                                      gpointer               user_data);
@@ -127,6 +133,7 @@ void               ide_workbench_addin_open_async            (IdeWorkbenchAddin
                                                               int                   at_line,
                                                               int                   at_line_offset,
                                                               IdeBufferOpenFlags    flags,
+                                                              IdePanelPosition     *position,
                                                               GCancellable         *cancellable,
                                                               GAsyncReadyCallback   callback,
                                                               gpointer              user_data);
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 8e4e284f1..8605e1daf 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -85,6 +85,7 @@ typedef struct
   GFile              *file;
   gchar              *hint;
   gchar              *content_type;
+  IdePanelPosition   *position;
   IdeBufferOpenFlags  flags;
   gint                at_line;
   gint                at_line_offset;
@@ -1380,7 +1381,7 @@ ide_workbench_action_open_response_cb (IdeWorkbench         *self,
 
           g_assert (G_IS_FILE (file));
 
-          ide_workbench_open_async (self, file, NULL, 0, NULL, NULL, NULL);
+          ide_workbench_open_async (self, file, NULL, 0, NULL, NULL, NULL, NULL);
         }
     }
 
@@ -1737,6 +1738,7 @@ ide_workbench_open_all_async (IdeWorkbench         *self,
                                 file,
                                 hint,
                                 IDE_BUFFER_OPEN_FLAGS_NONE,
+                                NULL,
                                 cancellable,
                                 ide_workbench_open_all_cb,
                                 g_object_ref (task));
@@ -1749,6 +1751,7 @@ ide_workbench_open_all_async (IdeWorkbench         *self,
  * @file: a #GFile
  * @hint: (nullable): an optional hint about what addin to use
  * @flags: optional flags when opening the file
+ * @position: (nullable): a position to open the page
  * @cancellable: (nullable): a #GCancellable
  * @callback: a #GAsyncReadyCallback to execute upon completion
  * @user_data: closure data for @callback
@@ -1766,6 +1769,7 @@ ide_workbench_open_async (IdeWorkbench        *self,
                           GFile               *file,
                           const gchar         *hint,
                           IdeBufferOpenFlags   flags,
+                          IdePanelPosition    *position,
                           GCancellable        *cancellable,
                           GAsyncReadyCallback  callback,
                           gpointer             user_data)
@@ -1780,6 +1784,7 @@ ide_workbench_open_async (IdeWorkbench        *self,
                                -1,
                                -1,
                                flags,
+                               position,
                                cancellable,
                                callback,
                                user_data);
@@ -1842,6 +1847,7 @@ ide_workbench_open_cb (GObject      *object,
                                   o->at_line,
                                   o->at_line_offset,
                                   o->flags,
+                                  o->position,
                                   cancellable,
                                   ide_workbench_open_cb,
                                   g_steal_pointer (&task));
@@ -1959,6 +1965,7 @@ ide_workbench_open_query_info_cb (GObject      *object,
                                   o->at_line,
                                   o->at_line_offset,
                                   o->flags,
+                                  o->position,
                                   cancellable,
                                   ide_workbench_open_cb,
                                   g_steal_pointer (&task));
@@ -1995,10 +2002,12 @@ ide_workbench_open_at_async (IdeWorkbench        *self,
                              gint                 at_line,
                              gint                 at_line_offset,
                              IdeBufferOpenFlags   flags,
+                             IdePanelPosition    *position,
                              GCancellable        *cancellable,
                              GAsyncReadyCallback  callback,
                              gpointer             user_data)
 {
+  g_autoptr(IdePanelPosition) local_position = NULL;
   g_autoptr(IdeTask) task = NULL;
   g_autoptr(GPtrArray) addins = NULL;
   IdeWorkbench *other;
@@ -2009,6 +2018,9 @@ ide_workbench_open_at_async (IdeWorkbench        *self,
   g_return_if_fail (self->unloaded == FALSE);
   g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
+  if (position == NULL)
+    position = local_position = ide_panel_position_new ();
+
   /* Possibly re-route opening the file to another workbench if we
    * discover the file is a better fit over there.
    */
@@ -2022,6 +2034,7 @@ ide_workbench_open_at_async (IdeWorkbench        *self,
                                    at_line,
                                    at_line_offset,
                                    flags,
+                                   NULL,
                                    cancellable,
                                    callback,
                                    user_data);
@@ -2059,6 +2072,7 @@ ide_workbench_open_at_async (IdeWorkbench        *self,
   o->flags = flags;
   o->at_line = at_line;
   o->at_line_offset = at_line_offset;
+  o->position = ide_panel_position_ref (position);
   ide_task_set_task_data (task, o, open_free);
 
   g_file_query_info_async (file,
diff --git a/src/libide/gui/ide-workbench.h b/src/libide/gui/ide-workbench.h
index c18c46e19..b534049b8 100644
--- a/src/libide/gui/ide-workbench.h
+++ b/src/libide/gui/ide-workbench.h
@@ -104,6 +104,7 @@ void             ide_workbench_open_async            (IdeWorkbench         *self
                                                       GFile                *file,
                                                       const gchar          *hint,
                                                       IdeBufferOpenFlags    flags,
+                                                      IdePanelPosition     *position,
                                                       GCancellable         *cancellable,
                                                       GAsyncReadyCallback   callback,
                                                       gpointer              user_data);
@@ -114,6 +115,7 @@ void             ide_workbench_open_at_async         (IdeWorkbench         *self
                                                       gint                  at_line,
                                                       gint                  at_line_offset,
                                                       IdeBufferOpenFlags    flags,
+                                                      IdePanelPosition     *position,
                                                       GCancellable         *cancellable,
                                                       GAsyncReadyCallback   callback,
                                                       gpointer              user_data);
diff --git a/src/libide/terminal/ide-terminal.c b/src/libide/terminal/ide-terminal.c
index 5e827d90f..802771c06 100644
--- a/src/libide/terminal/ide-terminal.c
+++ b/src/libide/terminal/ide-terminal.c
@@ -334,7 +334,7 @@ ide_terminal_open_link_resolve_cb (GObject      *object,
                                  pos->line,
                                  pos->column,
                                  IDE_BUFFER_OPEN_FLAGS_NONE,
-                                 NULL, NULL, NULL);
+                                 NULL, NULL, NULL, NULL);
 
   g_slice_free (Position, pos);
 }
diff --git a/src/plugins/editorui/gbp-editorui-workbench-addin.c 
b/src/plugins/editorui/gbp-editorui-workbench-addin.c
index 1f5a43c45..b0108601e 100644
--- a/src/plugins/editorui/gbp-editorui-workbench-addin.c
+++ b/src/plugins/editorui/gbp-editorui-workbench-addin.c
@@ -36,6 +36,7 @@ struct _GbpEditoruiWorkbenchAddin
 
 typedef struct
 {
+  IdePanelPosition   *position;
   GFile              *file;
   IdeBufferOpenFlags  flags;
   gint                at_line;
@@ -50,6 +51,7 @@ open_file_task_data_free (gpointer data)
   OpenFileTaskData *td = data;
 
   g_clear_object (&td->file);
+  g_clear_pointer (&td->position, ide_panel_position_unref);
   g_slice_free (OpenFileTaskData, td);
 }
 
@@ -222,6 +224,7 @@ gbp_editorui_workbench_addin_open_async (IdeWorkbenchAddin   *addin,
                                          gint                 at_line,
                                          gint                 at_line_offset,
                                          IdeBufferOpenFlags   flags,
+                                         IdePanelPosition    *position,
                                          GCancellable        *cancellable,
                                          GAsyncReadyCallback  callback,
                                          gpointer             user_data)
@@ -236,6 +239,7 @@ gbp_editorui_workbench_addin_open_async (IdeWorkbenchAddin   *addin,
   g_assert (G_IS_FILE (file));
   g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
   g_assert (IDE_IS_WORKBENCH (self->workbench));
+  g_assert (position != NULL);
 
   task = ide_task_new (self, cancellable, callback, user_data);
   state = g_slice_new0 (OpenFileTaskData);
@@ -243,6 +247,7 @@ gbp_editorui_workbench_addin_open_async (IdeWorkbenchAddin   *addin,
   state->file = g_object_ref (file);
   state->at_line = at_line;
   state->at_line_offset = at_line_offset;
+  state->position = ide_panel_position_ref (position);
   ide_task_set_task_data (task, state, open_file_task_data_free);
 
   context = ide_workbench_get_context (self->workbench);
diff --git a/src/plugins/open-with-external/gbp-owe-workbench-addin.c 
b/src/plugins/open-with-external/gbp-owe-workbench-addin.c
index 2fa787ccb..af095e2b4 100644
--- a/src/plugins/open-with-external/gbp-owe-workbench-addin.c
+++ b/src/plugins/open-with-external/gbp-owe-workbench-addin.c
@@ -94,6 +94,7 @@ gbp_owe_workbench_addin_open_async (IdeWorkbenchAddin     *addin,
                                     int                    line,
                                     int                    line_offset,
                                     IdeBufferOpenFlags     flags,
+                                    IdePanelPosition      *position,
                                     GCancellable          *cancellable,
                                     GAsyncReadyCallback    callback,
                                     gpointer               user_data)
diff --git a/src/plugins/project-tree/gbp-project-tree-addin.c 
b/src/plugins/project-tree/gbp-project-tree-addin.c
index 7b1b98082..cf062d3ea 100644
--- a/src/plugins/project-tree/gbp-project-tree-addin.c
+++ b/src/plugins/project-tree/gbp-project-tree-addin.c
@@ -260,7 +260,7 @@ gbp_project_tree_addin_node_activated (IdeTreeAddin *addin,
       file = ide_project_file_ref_file (project_file);
       workbench = ide_widget_get_workbench (GTK_WIDGET (tree));
 
-      ide_workbench_open_async (workbench, file, NULL, 0, NULL, NULL, NULL);
+      ide_workbench_open_async (workbench, file, NULL, 0, NULL, NULL, NULL, NULL);
 
       return TRUE;
     }
diff --git a/src/plugins/project-tree/gbp-project-tree-pane-actions.c 
b/src/plugins/project-tree/gbp-project-tree-pane-actions.c
index a684acf71..3c7eb0626 100644
--- a/src/plugins/project-tree/gbp-project-tree-pane-actions.c
+++ b/src/plugins/project-tree/gbp-project-tree-pane-actions.c
@@ -76,7 +76,14 @@ new_action_completed_cb (GObject      *object,
         return;
 
       if (state->file != NULL)
-        ide_workbench_open_async (workbench, state->file, "editorui", 0, NULL, NULL, NULL);
+        ide_workbench_open_async (workbench,
+                                  state->file,
+                                  "editorui",
+                                  0,
+                                  NULL,
+                                  NULL,
+                                  NULL,
+                                  NULL);
     }
 }
 
@@ -302,7 +309,10 @@ DEFINE_ACTION_HANDLER (open, {
                             file,
                             NULL,
                             IDE_BUFFER_OPEN_FLAGS_NONE,
-                            NULL, NULL, NULL);
+                            NULL,
+                            NULL,
+                            NULL,
+                            NULL);
 });
 
 static void
@@ -464,7 +474,10 @@ DEFINE_ACTION_HANDLER (open_with_hint, {
                             file,
                             hint,
                             IDE_BUFFER_OPEN_FLAGS_NONE,
-                            NULL, NULL, NULL);
+                            NULL,
+                            NULL,
+                            NULL,
+                            NULL);
 });
 
 /* Based on gdesktopappinfo.c in GIO */
diff --git a/src/plugins/todo/gbp-todo-panel.c b/src/plugins/todo/gbp-todo-panel.c
index e0c13e4d7..391dba323 100644
--- a/src/plugins/todo/gbp-todo-panel.c
+++ b/src/plugins/todo/gbp-todo-panel.c
@@ -149,7 +149,7 @@ gbp_todo_panel_row_activated (GbpTodoPanel      *self,
                                lineno,
                                -1,
                                IDE_BUFFER_OPEN_FLAGS_NONE,
-                               NULL, NULL, NULL);
+                               NULL, NULL, NULL, NULL);
 }
 
 static gboolean


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