[gnome-builder] plugins: allow enable/disable of plugins in preferences



commit 5043de8bc0fe3f214e29bd9ff2627cffc2cd1c3c
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 5 20:38:35 2015 -0800

    plugins: allow enable/disable of plugins in preferences

 data/gsettings/Makefile.am                         |    1 +
 .../gsettings/org.gnome.builder.plugin.gschema.xml |    9 ++++
 libide/ide-application-plugins.c                   |   46 ++++++++++++++++++++
 libide/preferences/ide-preferences-builtin.c       |    4 +-
 4 files changed, 58 insertions(+), 2 deletions(-)
---
diff --git a/data/gsettings/Makefile.am b/data/gsettings/Makefile.am
index f0801e3..d8b73b5 100644
--- a/data/gsettings/Makefile.am
+++ b/data/gsettings/Makefile.am
@@ -4,6 +4,7 @@ gsettings_SCHEMAS = \
        org.gnome.builder.editor.language.gschema.xml \
        org.gnome.builder.extension-type.gschema.xml \
        org.gnome.builder.gschema.xml \
+       org.gnome.builder.plugin.gschema.xml \
        org.gnome.builder.project-tree.gschema.xml \
        org.gnome.builder.terminal.gschema.xml \
        org.gnome.builder.workbench.gschema.xml \
diff --git a/data/gsettings/org.gnome.builder.plugin.gschema.xml 
b/data/gsettings/org.gnome.builder.plugin.gschema.xml
new file mode 100644
index 0000000..28b3df4
--- /dev/null
+++ b/data/gsettings/org.gnome.builder.plugin.gschema.xml
@@ -0,0 +1,9 @@
+<schemalist>
+  <schema id="org.gnome.builder.plugin" gettext-domain="gnome-builder">
+    <key name="enabled" type="b">
+      <default>true</default>
+      <summary>Enabled</summary>
+      <description>If the plugin should be enabled</description>
+    </key>
+  </schema>
+</schemalist>
diff --git a/libide/ide-application-plugins.c b/libide/ide-application-plugins.c
index 8633f9c..7995b13 100644
--- a/libide/ide-application-plugins.c
+++ b/libide/ide-application-plugins.c
@@ -110,6 +110,34 @@ ide_application_discover_plugins (IdeApplication *self)
     }
 }
 
+static void
+ide_application_plugins_enabled_changed (IdeApplication *self,
+                                         const gchar    *key,
+                                         GSettings      *settings)
+{
+  PeasPluginInfo *plugin_info;
+  PeasEngine *engine;
+  gboolean enabled;
+
+  g_assert (IDE_IS_APPLICATION (self));
+  g_assert (ide_str_equal0 (key, "enabled"));
+  g_assert (G_IS_SETTINGS (settings));
+
+  enabled = g_settings_get_boolean (settings, key);
+
+  engine = peas_engine_get_default ();
+
+  plugin_info = g_object_get_data (G_OBJECT (settings), "PEAS_PLUGIN_INFO");
+  g_assert (plugin_info != NULL);
+
+  if (enabled &&
+      ide_application_can_load_plugin (self, plugin_info) &&
+      !peas_plugin_info_is_loaded (plugin_info))
+    peas_engine_load_plugin (engine, plugin_info);
+  else if (!enabled && peas_plugin_info_is_loaded (plugin_info))
+    peas_engine_unload_plugin (engine, plugin_info);
+}
+
 void
 ide_application_load_plugins (IdeApplication *self)
 {
@@ -124,6 +152,24 @@ ide_application_load_plugins (IdeApplication *self)
   for (; list; list = list->next)
     {
       PeasPluginInfo *plugin_info = list->data;
+      GSettings *settings;
+      g_autofree gchar *path = NULL;
+      const gchar *module_name;
+
+      module_name = peas_plugin_info_get_module_name (plugin_info);
+      path = g_strdup_printf ("/org/gnome/builder/plugins/%s/", module_name);
+      settings = g_settings_new_with_path ("org.gnome.builder.plugin", path);
+
+      g_object_set_data (G_OBJECT (settings), "PEAS_PLUGIN_INFO", plugin_info);
+
+      g_signal_connect_object (settings,
+                               "changed::enabled",
+                               G_CALLBACK (ide_application_plugins_enabled_changed),
+                               self,
+                               G_CONNECT_SWAPPED);
+
+      if (!g_settings_get_boolean (settings, "enabled"))
+        continue;
 
       if (ide_application_can_load_plugin (self, plugin_info))
         {
diff --git a/libide/preferences/ide-preferences-builtin.c b/libide/preferences/ide-preferences-builtin.c
index 9e00396..cb998ec 100644
--- a/libide/preferences/ide-preferences-builtin.c
+++ b/libide/preferences/ide-preferences-builtin.c
@@ -53,10 +53,10 @@ ide_preferences_builtin_register_plugins (IdePreferences *preferences)
       name = peas_plugin_info_get_name (plugin_info);
       desc = peas_plugin_info_get_description (plugin_info);
 
-      path = g_strdup_printf ("/org/gnome/builder/extension-types/%s/",
+      path = g_strdup_printf ("/org/gnome/builder/plugins/%s/",
                               peas_plugin_info_get_module_name (plugin_info));
 
-      ide_preferences_add_switch (preferences, "plugins", "builtin", "org.gnome.builder.extension", 
"enabled", path, NULL, name, desc, NULL, i);
+      ide_preferences_add_switch (preferences, "plugins", "builtin", "org.gnome.builder.plugin", "enabled", 
path, NULL, name, desc, NULL, i);
     }
 }
 


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