[gnome-builder] layout-stack: add helper to get addin by module name



commit eeb673265c19aac3ce8a77347410d0fda69292f7
Author: Christian Hergert <chergert redhat com>
Date:   Sun Sep 3 12:24:26 2017 -0700

    layout-stack: add helper to get addin by module name
    
    We have this in various other places, and it can be convenient to allow
    editor plugins to find a coordinating addin in the header.

 libide/layout/ide-layout-stack-addin.h |   14 ++++++-----
 libide/layout/ide-layout-stack.c       |   38 ++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 6 deletions(-)
---
diff --git a/libide/layout/ide-layout-stack-addin.h b/libide/layout/ide-layout-stack-addin.h
index cee30c6..31e9a03 100644
--- a/libide/layout/ide-layout-stack-addin.h
+++ b/libide/layout/ide-layout-stack-addin.h
@@ -41,11 +41,13 @@ struct _IdeLayoutStackAddinInterface
                     IdeLayoutView       *view);
 };
 
-void ide_layout_stack_addin_load     (IdeLayoutStackAddin *self,
-                                      IdeLayoutStack      *stack);
-void ide_layout_stack_addin_unload   (IdeLayoutStackAddin *self,
-                                      IdeLayoutStack      *stack);
-void ide_layout_stack_addin_set_view (IdeLayoutStackAddin *self,
-                                      IdeLayoutView       *view);
+void                 ide_layout_stack_addin_load                (IdeLayoutStackAddin *self,
+                                                                 IdeLayoutStack      *stack);
+void                 ide_layout_stack_addin_unload              (IdeLayoutStackAddin *self,
+                                                                 IdeLayoutStack      *stack);
+void                 ide_layout_stack_addin_set_view            (IdeLayoutStackAddin *self,
+                                                                 IdeLayoutView       *view);
+IdeLayoutStackAddin *ide_layout_stack_addin_find_by_module_name (IdeLayoutStack      *stack,
+                                                                 const gchar         *module_name);
 
 G_END_DECLS
diff --git a/libide/layout/ide-layout-stack.c b/libide/layout/ide-layout-stack.c
index 031047a..67b0e00 100644
--- a/libide/layout/ide-layout-stack.c
+++ b/libide/layout/ide-layout-stack.c
@@ -1014,3 +1014,41 @@ ide_layout_stack_foreach_view (IdeLayoutStack *self,
 
   gtk_container_foreach (GTK_CONTAINER (priv->stack), callback, user_data);
 }
+
+/**
+ * ide_layout_stack_addin_find_by_module_name:
+ * @stack: An #IdeLayoutStack
+ * @module_name: the module name which provides the addin
+ *
+ * This function will locate the #IdeLayoutStackAddin that was registered by
+ * the plugin named @module_name (which should match the "Module" field
+ * provided in the .plugin file).
+ *
+ * If no module was found or that module does not implement the
+ * #IdeLayoutStackAddinInterface, then %NULL is returned.
+ *
+ * Returns: (transfer none) (nullable): An #IdeLayoutStackAddin or %NULL
+ *
+ * Since: 3.26
+ */
+IdeLayoutStackAddin *
+ide_layout_stack_addin_find_by_module_name (IdeLayoutStack *stack,
+                                            const gchar    *module_name)
+{
+  IdeLayoutStackPrivate *priv = ide_layout_stack_get_instance_private (stack);
+  PeasExtension *ret = NULL;
+  PeasPluginInfo *plugin_info;
+
+  g_return_val_if_fail (IDE_IS_LAYOUT_STACK (stack), NULL);
+  g_return_val_if_fail (priv->addins != NULL, NULL);
+  g_return_val_if_fail (module_name != NULL, NULL);
+
+  plugin_info = peas_engine_get_plugin_info (peas_engine_get_default (), module_name);
+
+  if (plugin_info != NULL)
+    ret = peas_extension_set_get_extension (priv->addins, plugin_info);
+  else
+    g_warning ("No addin could be found matching module \"%s\"", module_name);
+
+  return ret ? IDE_LAYOUT_STACK_ADDIN (ret) : NULL;
+}


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