[gnome-builder] plugins: auto register css overrides for plugins



commit e2ddf7fe8907fca9abd709e816bbf5dc551dead1
Author: Christian Hergert <christian hergert me>
Date:   Fri Jan 15 11:58:23 2016 -0800

    plugins: auto register css overrides for plugins
    
    Place CSS overrides in your plugin resources such as:
    
      /org/gnome/builder/plugins/<plugin-name>/theme/Adwaita.css
    
    For non-theme-specific, use shared.css
    
    For dark modes, use Adwaita-dark.css, where Adwaita is your theme name.

 libide/ide-application-plugins.c |   62 ++++++++++++++++++++++++++++++++++++++
 libide/ide-application-private.h |    2 +
 libide/ide-application.c         |    1 +
 3 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-application-plugins.c b/libide/ide-application-plugins.c
index 4d3c79d..192be81 100644
--- a/libide/ide-application-plugins.c
+++ b/libide/ide-application-plugins.c
@@ -24,6 +24,7 @@
 #include "ide-application.h"
 #include "ide-application-addin.h"
 #include "ide-application-private.h"
+#include "ide-css-provider.h"
 #include "ide-macros.h"
 
 static gboolean
@@ -300,6 +301,57 @@ ide_application_unload_plugin_menus (IdeApplication *self,
   g_hash_table_remove (self->merge_ids, module_name);
 }
 
+static void
+ide_application_load_plugin_css (IdeApplication *self,
+                                 PeasPluginInfo *plugin_info,
+                                 PeasEngine     *engine)
+{
+  g_autofree gchar *base_path = NULL;
+  GtkCssProvider *provider;
+  const gchar *module_name;
+  GdkScreen *screen;
+
+  g_assert (IDE_IS_APPLICATION (self));
+  g_assert (plugin_info != NULL);
+  g_assert (PEAS_IS_ENGINE (engine));
+
+  if (self->plugin_css == NULL)
+    self->plugin_css = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref);
+
+  module_name = peas_plugin_info_get_module_name (plugin_info);
+  base_path = g_strdup_printf ("/org/gnome/builder/plugins/%s", module_name);
+  provider = ide_css_provider_new (base_path);
+
+  screen = gdk_screen_get_default ();
+  gtk_style_context_add_provider_for_screen (screen,
+                                             GTK_STYLE_PROVIDER (provider),
+                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
+
+  g_hash_table_insert (self->plugin_css, plugin_info, provider);
+}
+
+static void
+ide_application_unload_plugin_css (IdeApplication *self,
+                                   PeasPluginInfo *plugin_info,
+                                   PeasEngine     *engine)
+{
+  GtkStyleProvider *provider;
+
+  g_assert (IDE_IS_APPLICATION (self));
+  g_assert (plugin_info != NULL);
+  g_assert (PEAS_IS_ENGINE (engine));
+
+  provider = g_hash_table_lookup (self->plugin_css, plugin_info);
+
+  if (provider != NULL)
+    {
+      GdkScreen *screen = gdk_screen_get_default ();
+
+      gtk_style_context_remove_provider_for_screen (screen, provider);
+      g_hash_table_remove (self->plugin_css, plugin_info);
+    }
+}
+
 void
 ide_application_init_plugin_menus (IdeApplication *self)
 {
@@ -317,12 +369,22 @@ ide_application_init_plugin_menus (IdeApplication *self)
                            G_CALLBACK (ide_application_load_plugin_menus),
                            self,
                            G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+  g_signal_connect_object (engine,
+                           "load-plugin",
+                           G_CALLBACK (ide_application_load_plugin_css),
+                           self,
+                           G_CONNECT_AFTER | G_CONNECT_SWAPPED);
 
   g_signal_connect_object (engine,
                            "unload-plugin",
                            G_CALLBACK (ide_application_unload_plugin_menus),
                            self,
                            G_CONNECT_SWAPPED);
+  g_signal_connect_object (engine,
+                           "unload-plugin",
+                           G_CALLBACK (ide_application_unload_plugin_css),
+                           self,
+                           G_CONNECT_SWAPPED);
 
   list = peas_engine_get_plugin_list (engine);
 
diff --git a/libide/ide-application-private.h b/libide/ide-application-private.h
index 0d6003a..3a78064 100644
--- a/libide/ide-application-private.h
+++ b/libide/ide-application-private.h
@@ -58,6 +58,8 @@ struct _IdeApplication
   EggMenuManager      *menu_manager;
   GHashTable          *merge_ids;
 
+  GHashTable          *plugin_css;
+
   GList               *test_funcs;
 };
 
diff --git a/libide/ide-application.c b/libide/ide-application.c
index 3cd2f84..9b1c596 100644
--- a/libide/ide-application.c
+++ b/libide/ide-application.c
@@ -360,6 +360,7 @@ ide_application_finalize (GObject *object)
   g_clear_pointer (&self->tool_arguments, g_strfreev);
   g_clear_pointer (&self->started_at, g_date_time_unref);
   g_clear_pointer (&self->merge_ids, g_hash_table_unref);
+  g_clear_pointer (&self->plugin_css, g_hash_table_unref);
   g_clear_object (&self->worker_manager);
   g_clear_object (&self->keybindings);
   g_clear_object (&self->recent_projects);


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