[gnome-builder] libide/core: auto-load settings from plugins



commit 313ecd8f3f71247318d57a5eee7439c1c9169575
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 26 23:14:05 2022 -0700

    libide/core: auto-load settings from plugins
    
    Use X-Settings-Schemas=a;b;c to auto-load app/project settings schemas
    from plugins into the IdeContext for both app and project overrides. This
    means that in a lot of cases, we won't have to "do anything" from plugin
    code other than denote that we have settings to load. Menus and preferences
    can then go aobut using the context GActionGroup to access settings in
    many cases.

 src/libide/core/ide-context.c | 72 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
---
diff --git a/src/libide/core/ide-context.c b/src/libide/core/ide-context.c
index a7c20075b..76f1c8ca6 100644
--- a/src/libide/core/ide-context.c
+++ b/src/libide/core/ide-context.c
@@ -103,10 +103,62 @@ ide_context_repr (IdeObject *object)
                           self->project_loaded);
 }
 
+static void
+ide_context_engine_load_plugin_cb (IdeContext           *self,
+                                   const PeasPluginInfo *plugin_info,
+                                   PeasEngine           *engine)
+{
+  g_autofree char *schemas = NULL;
+
+  g_assert (IDE_IS_CONTEXT (self));
+  g_assert (plugin_info != NULL);
+  g_assert (PEAS_IS_ENGINE (engine));
+
+  if ((schemas = g_strdup (peas_plugin_info_get_external_data (plugin_info, "Settings-Schemas"))))
+    {
+      g_auto(GStrv) split = g_strsplit (g_strdelimit (schemas, " ,\t:", ';'), ";", 0);
+
+      for (guint i = 0; split[i]; i++)
+        {
+          g_strstrip (split[i]);
+
+          if (!ide_str_empty0 (split[i]))
+            ide_context_register_settings (self, split[i]);
+        }
+    }
+}
+
+static void
+ide_context_engine_unload_plugin_cb (IdeContext           *self,
+                                     const PeasPluginInfo *plugin_info,
+                                     PeasEngine           *engine)
+{
+  g_autofree char *schemas = NULL;
+
+  g_assert (IDE_IS_CONTEXT (self));
+  g_assert (plugin_info != NULL);
+  g_assert (PEAS_IS_ENGINE (engine));
+
+  if ((schemas = g_strdup (peas_plugin_info_get_external_data (plugin_info, "Settings-Schemas"))))
+    {
+      g_auto(GStrv) split = g_strsplit (g_strdelimit (schemas, " ,\t:", ';'), ";", 0);
+
+      for (guint i = 0; split[i]; i++)
+        {
+          g_strstrip (split[i]);
+
+          if (!ide_str_empty0 (split[i]))
+            ide_context_unregister_settings (self, split[i]);
+        }
+    }
+}
+
 static void
 ide_context_constructed (GObject *object)
 {
   IdeContext *self = (IdeContext *)object;
+  g_auto(GStrv) loaded_plugins = NULL;
+  PeasEngine *engine;
 
   IDE_ENTRY;
 
@@ -122,6 +174,26 @@ ide_context_constructed (GObject *object)
                                             G_ACTION_GROUP (settings));
     }
 
+  engine = peas_engine_get_default ();
+  g_signal_connect_object (engine,
+                           "load-plugin",
+                           G_CALLBACK (ide_context_engine_load_plugin_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+  g_signal_connect_object (engine,
+                           "unload-plugin",
+                           G_CALLBACK (ide_context_engine_unload_plugin_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  loaded_plugins = peas_engine_get_loaded_plugins (engine);
+
+  for (guint i = 0; loaded_plugins[i]; i++)
+    {
+      const PeasPluginInfo *info = peas_engine_get_plugin_info (engine, loaded_plugins[i]);
+      ide_context_engine_load_plugin_cb (self, info, engine);
+    }
+
   IDE_EXIT;
 }
 


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