[gnome-builder/wip/plugins] app: add GbApplicationAddin



commit 3c0f066577969aae41e55226b646a83dab4d9d93
Author: Christian Hergert <christian hergert me>
Date:   Tue Jun 9 14:31:38 2015 -0700

    app: add GbApplicationAddin
    
    This addin will be activated and attached to the application. You can use
    this to do work that will be active as a singleton in the Builder process.

 src/Makefile.am                  |    2 +
 src/app/gb-application-addin.c   |   60 ++++++++++++++++++++++++++++++++++++++
 src/app/gb-application-addin.h   |   47 +++++++++++++++++++++++++++++
 src/app/gb-application-private.h |    2 +
 src/app/gb-application.c         |   56 ++++++++++++++++++++++++++++++++++-
 5 files changed, 166 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index f0e7a26..bd5e238 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,6 +11,8 @@ libgnome_builder_la_SOURCES = \
        $(gnome_builder_built_sources) \
        app/gb-application-actions.c \
        app/gb-application-actions.h \
+       app/gb-application-addin.c \
+       app/gb-application-addin.h \
        app/gb-application-credits.h \
        app/gb-application-private.h \
        app/gb-application.c \
diff --git a/src/app/gb-application-addin.c b/src/app/gb-application-addin.c
new file mode 100644
index 0000000..463e896
--- /dev/null
+++ b/src/app/gb-application-addin.c
@@ -0,0 +1,60 @@
+/* gb-application-addin.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gb-application-addin.h"
+
+G_DEFINE_INTERFACE (GbApplicationAddin, gb_application_addin, G_TYPE_OBJECT)
+
+static void
+gb_application_addin_real_load (GbApplicationAddin *self,
+                                GbApplication      *application)
+{
+}
+
+static void
+gb_application_addin_real_unload (GbApplicationAddin *self,
+                                  GbApplication      *application)
+{
+}
+
+static void
+gb_application_addin_default_init (GbApplicationAddinInterface *iface)
+{
+  iface->load = gb_application_addin_real_load;
+  iface->unload = gb_application_addin_real_unload;
+}
+
+void
+gb_application_addin_load (GbApplicationAddin *self,
+                           GbApplication      *application)
+{
+  g_return_if_fail (GB_IS_APPLICATION_ADDIN (self));
+  g_return_if_fail (GB_IS_APPLICATION (application));
+
+  GB_APPLICATION_ADDIN_GET_IFACE (self)->load (self, application);
+}
+
+void
+gb_application_addin_unload (GbApplicationAddin *self,
+                             GbApplication      *application)
+{
+  g_return_if_fail (GB_IS_APPLICATION_ADDIN (self));
+  g_return_if_fail (GB_IS_APPLICATION (application));
+
+  GB_APPLICATION_ADDIN_GET_IFACE (self)->unload (self, application);
+}
diff --git a/src/app/gb-application-addin.h b/src/app/gb-application-addin.h
new file mode 100644
index 0000000..5b723cc
--- /dev/null
+++ b/src/app/gb-application-addin.h
@@ -0,0 +1,47 @@
+/* gb-application-addin.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_APPLICATION_ADDIN_H
+#define GB_APPLICATION_ADDIN_H
+
+#include "gb-application.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_APPLICATION_ADDIN (gb_application_addin_get_type ())
+
+G_DECLARE_INTERFACE (GbApplicationAddin, gb_application_addin, GB, APPLICATION_ADDIN, GObject)
+
+struct _GbApplicationAddinInterface
+{
+  GTypeInterface parent;
+
+  void (*load)   (GbApplicationAddin *self,
+                  GbApplication      *application);
+  void (*unload) (GbApplicationAddin *self,
+                  GbApplication      *application);
+};
+
+void gb_application_addin_load   (GbApplicationAddin *self,
+                                  GbApplication      *application);
+void gb_application_addin_unload (GbApplicationAddin *self,
+                                  GbApplication      *application);
+
+G_END_DECLS
+
+#endif /* GB_APPLICATION_ADDIN_H */
diff --git a/src/app/gb-application-private.h b/src/app/gb-application-private.h
index 9ee7865..76868f6 100644
--- a/src/app/gb-application-private.h
+++ b/src/app/gb-application-private.h
@@ -22,6 +22,7 @@
 #include <gtk/gtk.h>
 #include <gio/gio.h>
 #include <ide.h>
+#include <libpeas/peas.h>
 
 #include "gb-keybindings.h"
 #include "gb-preferences-window.h"
@@ -37,6 +38,7 @@ struct _GbApplication
   GbPreferencesWindow *preferences_window;
   IdeRecentProjects   *recent_projects;
   GtkWindowGroup      *greeter_group;
+  PeasExtensionSet    *extensions;
 };
 
 
diff --git a/src/app/gb-application.c b/src/app/gb-application.c
index 651bac3..deecf73 100644
--- a/src/app/gb-application.c
+++ b/src/app/gb-application.c
@@ -24,10 +24,10 @@
 
 #include <glib/gi18n.h>
 #include <gtksourceview/gtksource.h>
-#include <ide.h>
 
 #include "gb-application.h"
 #include "gb-application-actions.h"
+#include "gb-application-addin.h"
 #include "gb-application-private.h"
 #include "gb-css-provider.h"
 #include "gb-editor-document.h"
@@ -480,6 +480,58 @@ gb_application_activate (GApplication *application)
 }
 
 static void
+gb_application__extension_added (PeasExtensionSet   *extensions,
+                                 GbApplicationAddin *addin,
+                                 GbApplication      *self)
+{
+  g_assert (GB_IS_APPLICATION (self));
+  g_assert (GB_IS_APPLICATION_ADDIN (addin));
+  g_assert (PEAS_IS_EXTENSION_SET (extensions));
+
+  gb_application_addin_load (addin, self);
+}
+
+static void
+gb_application__extension_removed (PeasExtensionSet   *extensions,
+                                   GbApplicationAddin *addin,
+                                   GbApplication      *self)
+{
+  g_assert (GB_IS_APPLICATION (self));
+  g_assert (GB_IS_APPLICATION_ADDIN (addin));
+  g_assert (PEAS_IS_EXTENSION_SET (extensions));
+
+  gb_application_addin_unload (addin, self);
+}
+
+static void
+gb_application_load_extensions (GbApplication *self)
+{
+  PeasEngine *engine;
+
+  g_assert (GB_IS_APPLICATION (self));
+
+  engine = peas_engine_get_default ();
+
+  self->extensions = peas_extension_set_new (engine, GB_TYPE_APPLICATION_ADDIN, NULL);
+
+  peas_extension_set_foreach (self->extensions,
+                              (PeasExtensionSetForeachFunc)gb_application__extension_added,
+                              self);
+
+  g_signal_connect_object (self->extensions,
+                           "extension-added",
+                           G_CALLBACK (gb_application__extension_added),
+                           self,
+                           0);
+
+  g_signal_connect_object (self->extensions,
+                           "extension-removed",
+                           G_CALLBACK (gb_application__extension_removed),
+                           self,
+                           0);
+}
+
+static void
 gb_application_startup (GApplication *app)
 {
   GbApplication *self = (GbApplication *)app;
@@ -501,6 +553,7 @@ gb_application_startup (GApplication *app)
   gb_application_register_theme_overrides (self);
   gb_application_setup_search_paths ();
   gb_application_load_keybindings (self);
+  gb_application_load_extensions (self);
 
   IDE_EXIT;
 }
@@ -540,6 +593,7 @@ gb_application_finalize (GObject *object)
 
   IDE_ENTRY;
 
+  g_clear_object (&self->extensions);
   g_clear_pointer (&self->started_at, g_date_time_unref);
   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]