[gnome-builder] libide/gui: move workbench to IdeActionMixin



commit 859066b77cf00cd24bd795a1ef0d8dfe13a324c4
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 28 00:40:37 2022 -0700

    libide/gui: move workbench to IdeActionMixin
    
    Also, add our workbench action group to the context so that we can resolve
    actions for the workbench through it.
    
    The IdeActionMuxer takes a weak pointer on the instance which is nice in
    that it allows us indirection from the action group even when installing
    into the widget hierarchy. That's actually better than what we had
    previously with workbnech being *the* action-group as it can make
    lifecycle a bit annoying.

 src/libide/editor/gtk/menus.ui           |   2 +-
 src/libide/editor/ide-editor-workspace.c |   2 -
 src/libide/gui/gtk/keybindings.json      |   6 +-
 src/libide/gui/gtk/menus.ui              |   2 +-
 src/libide/gui/ide-frame.ui              |   2 +-
 src/libide/gui/ide-primary-workspace.c   |   2 -
 src/libide/gui/ide-primary-workspace.ui  |   2 +-
 src/libide/gui/ide-shortcut-bundle.c     |   2 +-
 src/libide/gui/ide-workbench.c           | 139 +++++++++++++++++++------------
 src/plugins/buildui/gtk/menus.ui         |   4 +-
 src/plugins/editorui/gtk/menus.ui        |   2 +-
 11 files changed, 95 insertions(+), 70 deletions(-)
---
diff --git a/src/libide/editor/gtk/menus.ui b/src/libide/editor/gtk/menus.ui
index f68fc92ef..64c8997bb 100644
--- a/src/libide/editor/gtk/menus.ui
+++ b/src/libide/editor/gtk/menus.ui
@@ -14,7 +14,7 @@
       <item>
         <attribute name="id">ide-editor-workspace-menu-open</attribute>
         <attribute name="label" translatable="yes">Open File…</attribute>
-        <attribute name="action">workbench.open</attribute>
+        <attribute name="action">context.workbench.open</attribute>
         <attribute name="accel">&lt;primary&gt;o</attribute>
         <attribute name="verb-icon">document-open-symbolic</attribute>
         <attribute name="description" translatable="yes">Open a file in the workspace</attribute>
diff --git a/src/libide/editor/ide-editor-workspace.c b/src/libide/editor/ide-editor-workspace.c
index 66b05a802..bba9da5d9 100644
--- a/src/libide/editor/ide-editor-workspace.c
+++ b/src/libide/editor/ide-editor-workspace.c
@@ -276,8 +276,6 @@ ide_editor_workspace_class_init (IdeEditorWorkspaceClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeEditorWorkspace, header_bar);
   gtk_widget_class_bind_template_child (widget_class, IdeEditorWorkspace, project_title);
 
-  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, GDK_CONTROL_MASK, 
"workbench.global-search", NULL);
-
   gtk_widget_class_install_action (widget_class, "panel.toggle-start", NULL, toggle_panel_action);
   gtk_widget_class_install_action (widget_class, "panel.toggle-end", NULL, toggle_panel_action);
   gtk_widget_class_install_action (widget_class, "panel.toggle-bottom", NULL, toggle_panel_action);
diff --git a/src/libide/gui/gtk/keybindings.json b/src/libide/gui/gtk/keybindings.json
index 8231dbc4e..c8be77539 100644
--- a/src/libide/gui/gtk/keybindings.json
+++ b/src/libide/gui/gtk/keybindings.json
@@ -1,5 +1,5 @@
 /* Global Search */
-{ "trigger" : "<Control>Return", "action" : "workbench.global-search", "when" : "canSearch()", "phase" : 
"capture" },
+{ "trigger" : "<Control>Return", "action" : "context.workbench.global-search", "when" : "canSearch()", 
"phase" : "capture" },
 { "trigger" : "Escape", "action" : "search.hide", "when" : "inPopoverSearch() || inPageSearch()", "phase" : 
"capture" },
 { "trigger" : "Down", "action" : "search.move", "args" : "1", "when" : "inPopoverSearch()", "phase" : 
"capture" },
 { "trigger" : "Up", "action" : "search.move", "args" : "-1", "when" : "inPopoverSearch()", "phase" : 
"capture" },
@@ -11,7 +11,7 @@
 { "trigger" : "<Control>n", "action" : "editorui.new-file", "when" : "canEdit()", "phase" : "bubble" },
 
 /* Open Files */
-{ "trigger" : "<Control>o", "action" : "workbench.open", "when" : "canEdit()", "phase" : "bubble" },
+{ "trigger" : "<Control>o", "action" : "context.workbench.open", "when" : "canEdit()", "phase" : "bubble" },
 
 /* Switching pages in grid */
 { "trigger" : "<Alt>1", "action" : "frame.page", "args" : "1", "when" : "inGrid()", "phase" : "capture" },
@@ -26,7 +26,7 @@
 
 /* Workspace Actions */
 { "trigger" : "<Control>comma", "action" : "app.preferences", "phase" : "capture" },
-{ "trigger" : "<Alt>comma", "action" : "workbench.configure", "phase" : "capture" },
+{ "trigger" : "<Alt>comma", "action" : "context.workbench.configure", "phase" : "capture" },
 { "trigger" : "<Control>w", "action" : "frame.close-page-or-frame", "when" : "inPage()", "phase" : "bubble" 
},
 
 /* Toggle Panels */
diff --git a/src/libide/gui/gtk/menus.ui b/src/libide/gui/gtk/menus.ui
index b71764224..f82f415de 100644
--- a/src/libide/gui/gtk/menus.ui
+++ b/src/libide/gui/gtk/menus.ui
@@ -12,7 +12,7 @@
       <item>
         <attribute name="id">ide-primary-workspace-menu-close-project</attribute>
         <attribute name="label" translatable="yes">Close Project</attribute>
-        <attribute name="action">workbench.close</attribute>
+        <attribute name="action">context.workbench.close</attribute>
         <attribute name="verb-icon">window-close-symbolic</attribute>
       </item>
     </section>
diff --git a/src/libide/gui/ide-frame.ui b/src/libide/gui/ide-frame.ui
index 8c9e363e2..4fb9fbdce 100644
--- a/src/libide/gui/ide-frame.ui
+++ b/src/libide/gui/ide-frame.ui
@@ -102,7 +102,7 @@
                 <child>
                   <object class="GtkButton">
                     <property name="label" translatable="yes">Open File…</property>
-                    <property name="action-name">workbench.open</property>
+                    <property name="action-name">context.workbench.open</property>
                   </object>
                 </child>
                 <child>
diff --git a/src/libide/gui/ide-primary-workspace.c b/src/libide/gui/ide-primary-workspace.c
index 1dceceb91..0c804b819 100644
--- a/src/libide/gui/ide-primary-workspace.c
+++ b/src/libide/gui/ide-primary-workspace.c
@@ -296,8 +296,6 @@ ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, project_title);
   gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, run_button);
 
-  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, GDK_CONTROL_MASK, 
"workbench.global-search", NULL);
-
   gtk_widget_class_install_action (widget_class, "panel.toggle-start", NULL, toggle_panel_action);
   gtk_widget_class_install_action (widget_class, "panel.toggle-end", NULL, toggle_panel_action);
   gtk_widget_class_install_action (widget_class, "panel.toggle-bottom", NULL, toggle_panel_action);
diff --git a/src/libide/gui/ide-primary-workspace.ui b/src/libide/gui/ide-primary-workspace.ui
index 05a67a942..7b4fc8678 100644
--- a/src/libide/gui/ide-primary-workspace.ui
+++ b/src/libide/gui/ide-primary-workspace.ui
@@ -51,7 +51,7 @@
         </child>
         <child type="right">
           <object class="GtkButton" id="search_button">
-            <property name="action-name">workbench.global-search</property>
+            <property name="action-name">context.workbench.global-search</property>
             <property name="icon-name">edit-find-symbolic</property>
             <property name="margin-start">6</property>
             <property name="tooltip-text" translatable="yes">Search (Ctrl+Enter)</property>
diff --git a/src/libide/gui/ide-shortcut-bundle.c b/src/libide/gui/ide-shortcut-bundle.c
index 88c4b8b97..df23db0e1 100644
--- a/src/libide/gui/ide-shortcut-bundle.c
+++ b/src/libide/gui/ide-shortcut-bundle.c
@@ -377,7 +377,7 @@ populate_from_object (IdeShortcutBundle  *self,
 
       g_clear_pointer (&args, g_variant_unref);
       args = g_variant_builder_end (&builder);
-      action = "workbench.command";
+      action = "context.workbench.command";
     }
 
   if (!ide_str_empty0 (when_str))
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 5afb8ab5a..c85039080 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -113,42 +113,38 @@ enum {
   N_PROPS
 };
 
-static void ide_workbench_action_close         (IdeWorkbench *self,
+static void ide_workbench_action_close         (gpointer      instance,
+                                                const char   *action_name,
                                                 GVariant     *param);
-static void ide_workbench_action_open          (IdeWorkbench *self,
+static void ide_workbench_action_open          (gpointer      instance,
+                                                const char   *action_name,
                                                 GVariant     *param);
-static void ide_workbench_action_open_uri      (IdeWorkbench *self,
+static void ide_workbench_action_open_uri      (gpointer      instance,
+                                                const char   *action_name,
                                                 GVariant     *param);
-static void ide_workbench_action_dump_tasks    (IdeWorkbench *self,
+static void ide_workbench_action_dump_tasks    (gpointer      instance,
+                                                const char   *action_name,
                                                 GVariant     *param);
-static void ide_workbench_action_object_tree   (IdeWorkbench *self,
+static void ide_workbench_action_object_tree   (gpointer      instance,
+                                                const char   *action_name,
                                                 GVariant     *param);
-static void ide_workbench_action_inspector     (IdeWorkbench *self,
+static void ide_workbench_action_inspector     (gpointer      instance,
+                                                const char   *action_name,
                                                 GVariant     *param);
-static void ide_workbench_action_reload_all    (IdeWorkbench *self,
+static void ide_workbench_action_reload_all    (gpointer      instance,
+                                                const char   *action_name,
                                                 GVariant     *param);
-static void ide_workbench_action_global_search (IdeWorkbench *self,
+static void ide_workbench_action_global_search (gpointer      instance,
+                                                const char   *action_name,
                                                 GVariant     *param);
-static void ide_workbench_action_configure     (IdeWorkbench *self,
+static void ide_workbench_action_configure     (gpointer      instance,
+                                                const char   *action_name,
                                                 GVariant     *param);
 
-IDE_DEFINE_ACTION_GROUP (IdeWorkbench, ide_workbench, {
-  { "close", ide_workbench_action_close },
-  { "open", ide_workbench_action_open },
-  { "open-uri", ide_workbench_action_open_uri, "s" },
-  { "reload-files", ide_workbench_action_reload_all },
-  { "global-search", ide_workbench_action_global_search },
-  { "configure", ide_workbench_action_configure },
-  { "configure-page", ide_workbench_action_configure, "s" },
-  { "-inspector", ide_workbench_action_inspector },
-  { "-object-tree", ide_workbench_action_object_tree },
-  { "-dump-tasks", ide_workbench_action_dump_tasks },
-})
-
-G_DEFINE_FINAL_TYPE_WITH_CODE (IdeWorkbench, ide_workbench, GTK_TYPE_WINDOW_GROUP,
-                               G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, ide_workbench_init_action_group))
+G_DEFINE_FINAL_TYPE (IdeWorkbench, ide_workbench, GTK_TYPE_WINDOW_GROUP)
 
 static GParamSpec *properties [N_PROPS];
+static IdeActionMixin action_mixin;
 
 static void
 load_project_free (LoadProject *lp)
@@ -344,6 +340,8 @@ static void
 ide_workbench_constructed (GObject *object)
 {
   IdeWorkbench *self = (IdeWorkbench *)object;
+  g_autoptr(IdeActionMuxer) muxer = NULL;
+  IdeActionMuxer *our_muxer;
 
   g_assert (IDE_IS_WORKBENCH (self));
 
@@ -364,6 +362,14 @@ ide_workbench_constructed (GObject *object)
 
   G_OBJECT_CLASS (ide_workbench_parent_class)->constructed (object);
 
+  ide_action_mixin_constructed (&action_mixin, object);
+  ide_action_mixin_set_enabled (self, "configure", FALSE);
+
+  /* Add workbench actions to the muxer */
+  muxer = ide_context_ref_action_muxer (self->context);
+  our_muxer = ide_action_mixin_get_action_muxer (self);
+  ide_action_muxer_insert_action_group (muxer, "workbench", G_ACTION_GROUP (our_muxer));
+
   self->vcs_monitor = g_object_new (IDE_TYPE_VCS_MONITOR,
                                     "parent", self->context,
                                     NULL);
@@ -371,20 +377,18 @@ ide_workbench_constructed (GObject *object)
   self->addins = peas_extension_set_new (peas_engine_get_default (),
                                          IDE_TYPE_WORKBENCH_ADDIN,
                                          NULL);
-
   g_signal_connect (self->addins,
                     "extension-added",
                     G_CALLBACK (ide_workbench_addin_added_cb),
                     self);
-
   g_signal_connect (self->addins,
                     "extension-removed",
                     G_CALLBACK (ide_workbench_addin_removed_cb),
                     self);
-
   peas_extension_set_foreach (self->addins,
                               ide_workbench_addin_added_cb,
                               self);
+
 }
 
 static void
@@ -494,12 +498,24 @@ ide_workbench_class_init (IdeWorkbenchClass *klass)
                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  ide_action_mixin_init (&action_mixin, object_class);
+
+  ide_action_mixin_install_action (&action_mixin, "close", NULL, ide_workbench_action_close);
+  ide_action_mixin_install_action (&action_mixin, "open", NULL, ide_workbench_action_open);
+  ide_action_mixin_install_action (&action_mixin, "open-uri", "s", ide_workbench_action_open_uri);
+  ide_action_mixin_install_action (&action_mixin, "reload-files", NULL, ide_workbench_action_reload_all);
+  ide_action_mixin_install_action (&action_mixin, "global-search", NULL, ide_workbench_action_global_search);
+  ide_action_mixin_install_action (&action_mixin, "configure", NULL, ide_workbench_action_configure);
+  ide_action_mixin_install_action (&action_mixin, "configure-page", "s", ide_workbench_action_configure);
+  ide_action_mixin_install_action (&action_mixin, "-inspector", NULL, ide_workbench_action_inspector);
+  ide_action_mixin_install_action (&action_mixin, "-object-tree", NULL, ide_workbench_action_object_tree);
+  ide_action_mixin_install_action (&action_mixin, "-dump-tasks", NULL, ide_workbench_action_dump_tasks);
 }
 
 static void
 ide_workbench_init (IdeWorkbench *self)
 {
-  ide_workbench_set_action_enabled (self, "configure", FALSE);
 }
 
 static void
@@ -840,14 +856,6 @@ ide_workbench_add_workspace (IdeWorkbench *self,
                                   "context",
                                   G_ACTION_GROUP (muxer));
 
-  /* This causes the workspace to get an additional reference to the group
-   * (which already happens from GtkWindow:group), but IdeWorkspace will
-   * remove itself in IdeWorkspace.destroy.
-   */
-  gtk_widget_insert_action_group (GTK_WIDGET (workspace),
-                                  "workbench",
-                                  G_ACTION_GROUP (self));
-
   /* Give the workspace access to all the action groups of the context that
    * might be useful for them to access (debug-manager, run-manager, etc).
    */
@@ -1057,7 +1065,7 @@ ide_workbench_load_project_completed (IdeWorkbench *self,
   _ide_build_manager_start (build_manager);
 
   /* Enable actions that are available to projects */
-  ide_workbench_set_action_enabled (self, "configure", TRUE);
+  ide_action_mixin_set_enabled (self, "configure", FALSE);
 
   ide_task_return_boolean (task, TRUE);
 }
@@ -1350,26 +1358,33 @@ print_object_tree (IdeObject *object,
 }
 
 static void
-ide_workbench_action_object_tree (IdeWorkbench *self,
-                                  GVariant     *param)
+ide_workbench_action_object_tree (gpointer    instance,
+                                  const char *action_name,
+                                  GVariant   *param)
 {
+  IdeWorkbench *self = instance;
+
   g_assert (IDE_IS_WORKBENCH (self));
 
   print_object_tree (IDE_OBJECT (self->context), NULL);
 }
 
 static void
-ide_workbench_action_dump_tasks (IdeWorkbench *self,
-                                 GVariant     *param)
+ide_workbench_action_dump_tasks (gpointer    instance,
+                                 const char *action_name,
+                                 GVariant   *param)
 {
+  IdeWorkbench *self = instance;
+
   g_assert (IDE_IS_WORKBENCH (self));
 
   _ide_dump_tasks ();
 }
 
 static void
-ide_workbench_action_inspector (IdeWorkbench *self,
-                                GVariant     *param)
+ide_workbench_action_inspector (gpointer    instance,
+                                const char *action_name,
+                                GVariant   *param)
 {
   gtk_window_set_interactive_debugging (TRUE);
 }
@@ -1399,9 +1414,12 @@ ide_workbench_action_close_cb (GObject      *object,
 }
 
 static void
-ide_workbench_action_close (IdeWorkbench *self,
-                            GVariant     *param)
+ide_workbench_action_close (gpointer    instance,
+                            const char *action_name,
+                            GVariant   *param)
 {
+  IdeWorkbench *self = instance;
+
   g_assert (IDE_IS_WORKBENCH (self));
   g_assert (param == NULL);
 
@@ -1413,9 +1431,11 @@ ide_workbench_action_close (IdeWorkbench *self,
 }
 
 static void
-ide_workbench_action_reload_all (IdeWorkbench *self,
-                                 GVariant     *param)
+ide_workbench_action_reload_all (gpointer    instance,
+                                 const char *action_name,
+                                 GVariant   *param)
 {
+  IdeWorkbench *self = instance;
   IdeBufferManager *bufmgr;
   IdeContext *context;
 
@@ -1454,9 +1474,11 @@ ide_workbench_action_open_response_cb (IdeWorkbench         *self,
 }
 
 static void
-ide_workbench_action_open (IdeWorkbench *self,
-                           GVariant     *param)
+ide_workbench_action_open (gpointer    instance,
+                           const char *action_name,
+                           GVariant   *param)
 {
+  IdeWorkbench *self = instance;
   GtkFileChooserNative *chooser;
   IdeWorkspace *workspace;
 
@@ -1483,9 +1505,11 @@ ide_workbench_action_open (IdeWorkbench *self,
 }
 
 static void
-ide_workbench_action_open_uri (IdeWorkbench *self,
-                               GVariant     *param)
+ide_workbench_action_open_uri (gpointer    instance,
+                               const char *action_name,
+                               GVariant   *param)
 {
+  IdeWorkbench *self = instance;
   g_autoptr(GFile) file = NULL;
 
   IDE_ENTRY;
@@ -1500,9 +1524,12 @@ ide_workbench_action_open_uri (IdeWorkbench *self,
 }
 
 static void
-ide_workbench_action_global_search (IdeWorkbench *self,
-                                    GVariant     *param)
+ide_workbench_action_global_search (gpointer    instance,
+                                    const char *action_name,
+                                    GVariant   *param)
 {
+  IdeWorkbench *self = instance;
+
   IDE_ENTRY;
 
   g_assert (IDE_IS_WORKBENCH (self));
@@ -2704,9 +2731,11 @@ ide_workbench_resolve_file_finish (IdeWorkbench  *self,
 }
 
 static void
-ide_workbench_action_configure (IdeWorkbench *self,
-                                GVariant     *param)
+ide_workbench_action_configure (gpointer    instance,
+                                const char *action_name,
+                                GVariant   *param)
 {
+  IdeWorkbench *self = instance;
   const char *page = NULL;
   GtkWindow *window;
   GList *windows;
diff --git a/src/plugins/buildui/gtk/menus.ui b/src/plugins/buildui/gtk/menus.ui
index d5fa374e6..55e60630c 100644
--- a/src/plugins/buildui/gtk/menus.ui
+++ b/src/plugins/buildui/gtk/menus.ui
@@ -31,7 +31,7 @@
   <menu id="build-menu">
     <item>
       <attribute name="label" translatable="yes">Configure Project…</attribute>
-      <attribute name="action">workbench.configure</attribute>
+      <attribute name="action">context.workbench.configure</attribute>
       <attribute name="accel">&lt;alt&gt;comma</attribute>
       <attribute name="description" translatable="yes">Configure settings related to the project</attribute>
       <attribute name="verb-icon">preferences-system-symbolic</attribute>
@@ -124,7 +124,7 @@
     <section id="run-command-section">
       <item>
         <attribute name="label" translatable="yes">Select Run Command…</attribute>
-        <attribute name="action">workbench.configure-page</attribute>
+        <attribute name="action">context.workbench.configure-page</attribute>
         <attribute name="target" type="s">'application'</attribute>
       </item>
     </section>
diff --git a/src/plugins/editorui/gtk/menus.ui b/src/plugins/editorui/gtk/menus.ui
index 8b3d9f7f0..e5834a73e 100644
--- a/src/plugins/editorui/gtk/menus.ui
+++ b/src/plugins/editorui/gtk/menus.ui
@@ -149,7 +149,7 @@
       <item>
         <attribute name="id">open-file</attribute>
         <attribute name="label" translatable="yes">_Open File…</attribute>
-        <attribute name="action">workbench.open</attribute>
+        <attribute name="action">context.workbench.open</attribute>
         <attribute name="accel">&lt;primary&gt;o</attribute>
       </item>
     </section>


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