[gnome-builder] libide/tweaks: load addins when setting tweaks instance



commit 06f42d1c23fefb6da96b765bbe830837d1387a5d
Author: Christian Hergert <chergert redhat com>
Date:   Wed Aug 10 17:02:18 2022 -0700

    libide/tweaks: load addins when setting tweaks instance

 src/libide/tweaks/ide-tweaks-window.c | 92 +++++++++++++++++++++++++++++------
 1 file changed, 76 insertions(+), 16 deletions(-)
---
diff --git a/src/libide/tweaks/ide-tweaks-window.c b/src/libide/tweaks/ide-tweaks-window.c
index 648843f7a..75fb1b1ae 100644
--- a/src/libide/tweaks/ide-tweaks-window.c
+++ b/src/libide/tweaks/ide-tweaks-window.c
@@ -22,6 +22,9 @@
 
 #include "config.h"
 
+#include <libpeas/peas.h>
+
+#include "ide-tweaks-addin.h"
 #include "ide-tweaks-panel-private.h"
 #include "ide-tweaks-panel-list-private.h"
 #include "ide-tweaks-window.h"
@@ -30,21 +33,22 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (GtkStackPage, g_object_unref)
 
 struct _IdeTweaksWindow
 {
-  AdwWindow       parent_instance;
-
-  IdeTweaks      *tweaks;
-
-  AdwLeaflet     *leaflet;
-  GtkBox         *panel_box;
-  GtkStack       *panel_stack;
-  GtkStack       *panel_list_stack;
-  GtkBox         *panel_list_box;
-  AdwWindowTitle *sidebar_title;
-  GtkSearchBar   *sidebar_search_bar;
-  GtkSearchEntry *sidebar_search_entry;
-
-  guint           can_navigate_back : 1;
-  guint           folded : 1;
+  AdwWindow         parent_instance;
+
+  IdeTweaks        *tweaks;
+  PeasExtensionSet *addins;
+
+  AdwLeaflet       *leaflet;
+  GtkBox           *panel_box;
+  GtkStack         *panel_stack;
+  GtkStack         *panel_list_stack;
+  GtkBox           *panel_list_box;
+  AdwWindowTitle   *sidebar_title;
+  GtkSearchBar     *sidebar_search_bar;
+  GtkSearchEntry   *sidebar_search_entry;
+
+  guint             can_navigate_back : 1;
+  guint             folded : 1;
 };
 
 enum {
@@ -196,6 +200,8 @@ ide_tweaks_window_clear (IdeTweaksWindow *self)
   g_assert (IDE_IS_TWEAKS_WINDOW (self));
   g_assert (IDE_IS_TWEAKS (self->tweaks));
 
+  g_clear_object (&self->addins);
+
   while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->panel_list_stack))))
     gtk_stack_remove (self->panel_list_stack, child);
 
@@ -205,6 +211,42 @@ ide_tweaks_window_clear (IdeTweaksWindow *self)
   ide_tweaks_window_update_actions (self);
 }
 
+static void
+ide_tweaks_window_addin_added_cb (PeasExtensionSet *set,
+                                  PeasPluginInfo   *plugin_info,
+                                  PeasExtension    *exten,
+                                  gpointer          user_data)
+{
+  IdeTweaksWindow *self = user_data;
+  IdeTweaksAddin *addin = (IdeTweaksAddin *)exten;
+
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_TWEAKS_ADDIN (addin));
+  g_assert (IDE_IS_TWEAKS_WINDOW (self));
+  g_assert (IDE_IS_TWEAKS (self->tweaks));
+
+  ide_tweaks_addin_load (addin, self->tweaks);
+}
+
+static void
+ide_tweaks_window_addin_removed_cb (PeasExtensionSet *set,
+                                    PeasPluginInfo   *plugin_info,
+                                    PeasExtension    *exten,
+                                    gpointer          user_data)
+{
+  IdeTweaksWindow *self = user_data;
+  IdeTweaksAddin *addin = (IdeTweaksAddin *)exten;
+
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_TWEAKS_ADDIN (addin));
+  g_assert (IDE_IS_TWEAKS_WINDOW (self));
+  g_assert (IDE_IS_TWEAKS (self->tweaks));
+
+  ide_tweaks_addin_unload (addin, self->tweaks);
+}
+
 static void
 ide_tweaks_window_rebuild (IdeTweaksWindow *self)
 {
@@ -212,7 +254,23 @@ ide_tweaks_window_rebuild (IdeTweaksWindow *self)
 
   g_assert (IDE_IS_TWEAKS_WINDOW (self));
   g_assert (IDE_IS_TWEAKS (self->tweaks));
-
+  g_assert (self->addins == NULL);
+
+  /* Allow addins to extend the tweaks instance */
+  self->addins = peas_extension_set_new (peas_engine_get_default (),
+                                         IDE_TYPE_TWEAKS_ADDIN,
+                                         NULL);
+  g_signal_connect (self->addins,
+                    "extension-added",
+                    G_CALLBACK (ide_tweaks_window_addin_added_cb),
+                    self);
+  g_signal_connect (self->addins,
+                    "extension-removed",
+                    G_CALLBACK (ide_tweaks_window_addin_removed_cb),
+                    self);
+  peas_extension_set_foreach (self->addins, ide_tweaks_window_addin_added_cb, self);
+
+  /* Now create our list for toplevel pages */
   list = ide_tweaks_panel_list_new (IDE_TWEAKS_ITEM (self->tweaks));
   g_signal_connect_object (list,
                            "page-activated",
@@ -223,11 +281,13 @@ ide_tweaks_window_rebuild (IdeTweaksWindow *self)
                        list,
                        ide_tweaks_item_get_id (IDE_TWEAKS_ITEM (self->tweaks)));
 
+  /* Setup initial selection state */
   if (self->folded)
     ide_tweaks_panel_list_set_selection_mode (IDE_TWEAKS_PANEL_LIST (list), GTK_SELECTION_NONE);
   else
     ide_tweaks_panel_list_select_first (IDE_TWEAKS_PANEL_LIST (list));
 
+  /* Ensure action state visibility */
   ide_tweaks_window_update_actions (self);
 }
 


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