[gnome-builder] libide/gui: allow workspace addin to define action groups



commit 643852f6decec140192d91ed8bfb2863c4fe5e85
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 28 16:36:39 2022 -0700

    libide/gui: allow workspace addin to define action groups
    
    This will allow them to be auto-muxed into the "workspace.module-name."
    prefix.

 src/libide/gui/ide-workspace-addin.c | 21 +++++++++++++++++++++
 src/libide/gui/ide-workspace-addin.h | 15 +++++++++------
 src/libide/gui/ide-workspace.c       | 12 +++++++++++-
 3 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/src/libide/gui/ide-workspace-addin.c b/src/libide/gui/ide-workspace-addin.c
index f6acde158..2ec3427cd 100644
--- a/src/libide/gui/ide-workspace-addin.c
+++ b/src/libide/gui/ide-workspace-addin.c
@@ -106,3 +106,24 @@ ide_workspace_addin_page_changed (IdeWorkspaceAddin *self,
   if (IDE_WORKSPACE_ADDIN_GET_IFACE (self)->page_changed)
     IDE_WORKSPACE_ADDIN_GET_IFACE (self)->page_changed (self, page);
 }
+
+/**
+ * ide_workspace_addin_ref_action_group:
+ * @self: a #IdeWorkspaceAddin
+ *
+ * Gets the action group for the workspace addin. This is automatically
+ * registered with an action prefix like "workspace.module-name" where
+ * "module-name" is the value of "Module=" in the plugin's manifest.
+ *
+ * Returns: (transfer full) (nullable): a #GActionGroup or %NULL
+ */
+GActionGroup *
+ide_workspace_addin_ref_action_group (IdeWorkspaceAddin *self)
+{
+  g_return_val_if_fail (IDE_IS_WORKSPACE_ADDIN (self), NULL);
+
+  if (IDE_WORKSPACE_ADDIN_GET_IFACE (self)->ref_action_group)
+    return IDE_WORKSPACE_ADDIN_GET_IFACE (self)->ref_action_group (self);
+
+  return NULL;
+}
diff --git a/src/libide/gui/ide-workspace-addin.h b/src/libide/gui/ide-workspace-addin.h
index 4c915a841..d34a2bbfa 100644
--- a/src/libide/gui/ide-workspace-addin.h
+++ b/src/libide/gui/ide-workspace-addin.h
@@ -40,12 +40,13 @@ struct _IdeWorkspaceAddinInterface
 {
   GTypeInterface parent_iface;
 
-  void     (*load)          (IdeWorkspaceAddin *self,
-                             IdeWorkspace      *workspace);
-  void     (*unload)        (IdeWorkspaceAddin *self,
-                             IdeWorkspace      *workspace);
-  void     (*page_changed)  (IdeWorkspaceAddin *self,
-                             IdePage           *page);
+  void          (*load)             (IdeWorkspaceAddin *self,
+                                     IdeWorkspace      *workspace);
+  void          (*unload)           (IdeWorkspaceAddin *self,
+                                     IdeWorkspace      *workspace);
+  void          (*page_changed)     (IdeWorkspaceAddin *self,
+                                     IdePage           *page);
+  GActionGroup *(*ref_action_group) (IdeWorkspaceAddin *self);
 };
 
 IDE_AVAILABLE_IN_ALL
@@ -58,6 +59,8 @@ IDE_AVAILABLE_IN_ALL
 void               ide_workspace_addin_page_changed        (IdeWorkspaceAddin *self,
                                                             IdePage           *page);
 IDE_AVAILABLE_IN_ALL
+GActionGroup      *ide_workspace_addin_ref_action_group    (IdeWorkspaceAddin *self);
+IDE_AVAILABLE_IN_ALL
 IdeWorkspaceAddin *ide_workspace_addin_find_by_module_name (IdeWorkspace      *workspace,
                                                             const gchar       *module_name);
 
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index fe25876f6..f7dc2f20f 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -37,6 +37,8 @@
 #define GET_PRIORITY(w)   GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"PRIORITY"))
 #define SET_PRIORITY(w,i) g_object_set_data(G_OBJECT(w),"PRIORITY",GINT_TO_POINTER(i))
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GActionGroup, g_object_unref)
+
 typedef struct
 {
   /* Used as a link in IdeWorkbench's GQueue to track the most-recently-used
@@ -155,6 +157,7 @@ ide_workspace_addin_added_cb (IdeExtensionSetAdapter *set,
                               gpointer                user_data)
 {
   IdeWorkspaceAddin *addin = (IdeWorkspaceAddin *)exten;
+  g_autoptr(GActionGroup) action_group = NULL;
   IdeWorkspace *self = user_data;
   IdePage *page;
 
@@ -168,6 +171,14 @@ ide_workspace_addin_added_cb (IdeExtensionSetAdapter *set,
 
   ide_workspace_addin_load (addin, self);
 
+  if ((action_group = ide_workspace_addin_ref_action_group (addin)))
+    {
+      IdeActionMuxer *muxer = ide_action_mixin_get_action_muxer (self);
+      ide_action_muxer_insert_action_group (muxer,
+                                            peas_plugin_info_get_module_name (plugin_info),
+                                            G_ACTION_GROUP (muxer));
+    }
+
   if ((page = ide_workspace_get_focus_page (self)))
     ide_workspace_addin_page_changed (addin, page);
 }
@@ -524,7 +535,6 @@ ide_workspace_constructed (GObject *object)
 
   G_OBJECT_CLASS (ide_workspace_parent_class)->constructed (object);
 
-  /* TODO: Connect addins to muxer */
   ide_action_mixin_constructed (&IDE_WORKSPACE_GET_CLASS (self)->action_mixin, object);
   muxer = ide_action_mixin_get_action_muxer (self);
   gtk_widget_insert_action_group (GTK_WIDGET (self), "workspace", G_ACTION_GROUP (muxer));


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