[gnome-builder] editor: allow accessing editor-view addin by module name



commit ec049a52eec907eb4ef685d38728f9a9ccdbead3
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jul 14 15:45:19 2017 -0700

    editor: allow accessing editor-view addin by module name
    
    This makes it convenient to locate a peer addin in your plugin
    based on the module name.

 libide/editor/ide-editor-perspective.c |   13 ----------
 libide/editor/ide-editor-private.h     |   20 +++++++++++++++
 libide/editor/ide-editor-view-addin.c  |   41 +++++++++++++++++++++++++++++++-
 libide/editor/ide-editor-view-addin.h  |   14 ++++++----
 4 files changed, 68 insertions(+), 20 deletions(-)
---
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index 5f51b76..9e9bacb 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -33,19 +33,6 @@
 #include "workbench/ide-workbench.h"
 #include "util/ide-gtk.h"
 
-struct _IdeEditorPerspective
-{
-  IdeLayout            parent_instance;
-
-  /* Template widgets */
-  IdeLayoutGrid       *grid;
-  IdeEditorProperties *properties;
-
-  /* State before entering focus mode */
-  guint                prefocus_had_left : 1;
-  guint                prefocus_had_bottom : 1;
-};
-
 typedef struct
 {
   IdeEditorPerspective *self;
diff --git a/libide/editor/ide-editor-private.h b/libide/editor/ide-editor-private.h
index bb869f3..9c982d1 100644
--- a/libide/editor/ide-editor-private.h
+++ b/libide/editor/ide-editor-private.h
@@ -18,15 +18,35 @@
 
 #pragma once
 
+#include <libpeas/peas.h>
+
 #include "editor/ide-editor-perspective.h"
+#include "editor/ide-editor-properties.h"
 #include "editor/ide-editor-search-bar.h"
 #include "editor/ide-editor-sidebar.h"
 #include "editor/ide-editor-view-addin.h"
 #include "editor/ide-editor-view.h"
+#include "layout/ide-layout-grid.h"
+#include "layout/ide-layout-view.h"
 #include "plugins/ide-extension-set-adapter.h"
 
 G_BEGIN_DECLS
 
+struct _IdeEditorPerspective
+{
+  IdeLayout            parent_instance;
+
+  PeasExtensionSet    *addins;
+
+  /* Template widgets */
+  IdeLayoutGrid       *grid;
+  IdeEditorProperties *properties;
+
+  /* State before entering focus mode */
+  guint                prefocus_had_left : 1;
+  guint                prefocus_had_bottom : 1;
+};
+
 struct _IdeEditorView
 {
   IdeLayoutView            parent_instance;
diff --git a/libide/editor/ide-editor-view-addin.c b/libide/editor/ide-editor-view-addin.c
index 9ac4bae..5211fd6 100644
--- a/libide/editor/ide-editor-view-addin.c
+++ b/libide/editor/ide-editor-view-addin.c
@@ -16,7 +16,10 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "ide-editor-view-addin.h"
+#define G_LOG_DOMAIN "ide-editor-view-addin"
+
+#include "editor/ide-editor-private.h"
+#include "editor/ide-editor-view-addin.h"
 
 G_DEFINE_INTERFACE (IdeEditorViewAddin, ide_editor_view_addin, G_TYPE_OBJECT)
 
@@ -56,3 +59,39 @@ ide_editor_view_addin_language_changed (IdeEditorViewAddin *self,
   if (IDE_EDITOR_VIEW_ADDIN_GET_IFACE (self)->language_changed)
     IDE_EDITOR_VIEW_ADDIN_GET_IFACE (self)->language_changed (self, language_id);
 }
+
+/**
+ * ide_editor_view_addin_find_by_module_name:
+ * @view: an #IdeEditorView
+ * @module_name: the module name which provides the addin
+ *
+ * This function will locate the #IdeEditorViewAddin that was registered
+ * by the addin named @module_name (which should match the module_name
+ * provided in the .plugin file).
+ *
+ * If no module was found or that module does not implement the
+ * #IdeEditorViewAddinInterface, then %NULL is returned.
+ *
+ * Returns: (transfer none) (nullable): An #IdeEditorViewAddin or %NULL
+ *
+ * Since: 3.26
+ */
+IdeEditorViewAddin *
+ide_editor_view_addin_find_by_module_name (IdeEditorView *view,
+                                           const gchar   *module_name)
+{
+  PeasExtension *ret = NULL;
+  PeasPluginInfo *plugin_info;
+
+  g_return_val_if_fail (IDE_IS_EDITOR_VIEW (view), 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 = ide_extension_set_adapter_get_extension (view->addins, plugin_info);
+  else
+    g_warning ("No addin could be found matching module \"%s\"", module_name);
+
+  return ret ? IDE_EDITOR_VIEW_ADDIN (ret) : NULL;
+}
diff --git a/libide/editor/ide-editor-view-addin.h b/libide/editor/ide-editor-view-addin.h
index 0498381..0a52432 100644
--- a/libide/editor/ide-editor-view-addin.h
+++ b/libide/editor/ide-editor-view-addin.h
@@ -38,11 +38,13 @@ struct _IdeEditorViewAddinInterface
                               const gchar        *language_id);
 };
 
-void ide_editor_view_addin_load             (IdeEditorViewAddin *self,
-                                             IdeEditorView      *view);
-void ide_editor_view_addin_unload           (IdeEditorViewAddin *self,
-                                             IdeEditorView      *view);
-void ide_editor_view_addin_language_changed (IdeEditorViewAddin *self,
-                                             const gchar        *language_id);
+void                ide_editor_view_addin_load                (IdeEditorViewAddin *self,
+                                                               IdeEditorView      *view);
+void                ide_editor_view_addin_unload              (IdeEditorViewAddin *self,
+                                                               IdeEditorView      *view);
+void                ide_editor_view_addin_language_changed    (IdeEditorViewAddin *self,
+                                                               const gchar        *language_id);
+IdeEditorViewAddin *ide_editor_view_addin_find_by_module_name (IdeEditorView      *view,
+                                                               const gchar        *module_name);
 
 G_END_DECLS


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