[gnome-builder] gui: bridge GApplication.open signal to IdeApplicationAddin.open



commit 9d95d65948a39e7cb207b6f17d277ba3fa8391fa
Author: Daniel Buch <boogiewasthere gmail com>
Date:   Sat Jan 12 14:56:33 2019 +0100

    gui: bridge GApplication.open signal to IdeApplicationAddin.open
    
    This adds a new vfunc for application addins to open files and wires up
    the GApplication.open callback to dispatch the signal to addins.

 src/libide/gui/ide-application-addin.c | 26 +++++++++++++++
 src/libide/gui/ide-application-addin.h | 11 +++++++
 src/libide/gui/ide-application.c       | 58 +++++++++++++++++++++++++++++++++-
 3 files changed, 94 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/gui/ide-application-addin.c b/src/libide/gui/ide-application-addin.c
index b5e5bee6d..eb84eeaca 100644
--- a/src/libide/gui/ide-application-addin.c
+++ b/src/libide/gui/ide-application-addin.c
@@ -84,6 +84,32 @@ ide_application_addin_activate (IdeApplicationAddin *self,
     IDE_APPLICATION_ADDIN_GET_IFACE (self)->activate (self, application);
 }
 
+/**
+ * ide_application_addin_open:
+ * @self: a #IdeApplicationAddin
+ * @application: an #ideApplication
+ * @files: an array of #GFile
+ * @n_files: number of #GFile elements in @files
+ * @hint: hint
+ *
+ * This function is activated when the #GApplication::open signal is emitted.
+ *
+ * Since: 3.32
+ */
+void
+ide_application_addin_open (IdeApplicationAddin  *self,
+                            IdeApplication       *application,
+                            GFile               **files,
+                            gint                  n_files,
+                            const gchar          *hint)
+{
+  g_return_if_fail (IDE_IS_APPLICATION_ADDIN (self));
+  g_return_if_fail (IDE_IS_APPLICATION (application));
+
+  if (IDE_APPLICATION_ADDIN_GET_IFACE (self)->open)
+    IDE_APPLICATION_ADDIN_GET_IFACE (self)->open (self, application, files, n_files, hint);
+}
+
 /**
  * ide_application_addin_load:
  * @self: An #IdeApplicationAddin.
diff --git a/src/libide/gui/ide-application-addin.h b/src/libide/gui/ide-application-addin.h
index 400a822b8..6969355c8 100644
--- a/src/libide/gui/ide-application-addin.h
+++ b/src/libide/gui/ide-application-addin.h
@@ -55,6 +55,11 @@ struct _IdeApplicationAddinInterface
                                IdeApplication          *application);
   void (*activate)            (IdeApplicationAddin     *self,
                                IdeApplication          *application);
+  void (*open)                (IdeApplicationAddin     *self,
+                               IdeApplication          *application,
+                               GFile                  **files,
+                               gint                     n_files,
+                               const gchar             *hint);
   void (*add_option_entries)  (IdeApplicationAddin     *self,
                                IdeApplication          *application);
   void (*handle_command_line) (IdeApplicationAddin     *self,
@@ -66,6 +71,12 @@ struct _IdeApplicationAddinInterface
                                IdeWorkbench            *workbench);
 };
 
+IDE_AVAILABLE_IN_3_32
+void ide_application_addin_open                (IdeApplicationAddin    *self,
+                                                IdeApplication         *application,
+                                                GFile                 **files,
+                                                gint                    n_files,
+                                                const gchar             *hint);
 IDE_AVAILABLE_IN_3_32
 void ide_application_addin_activate            (IdeApplicationAddin     *self,
                                                 IdeApplication          *application);
diff --git a/src/libide/gui/ide-application.c b/src/libide/gui/ide-application.c
index e81a70b9b..782518fdd 100644
--- a/src/libide/gui/ide-application.c
+++ b/src/libide/gui/ide-application.c
@@ -43,6 +43,14 @@ G_DEFINE_TYPE (IdeApplication, ide_application, DZL_TYPE_APPLICATION)
 
 #define IS_UI_PROCESS(app) ((app)->type == NULL)
 
+typedef struct
+{
+  IdeApplication  *self;
+  GFile          **files;
+  gint             n_files;
+  const gchar     *hint;
+} OpenData;
+
 static void
 ide_application_add_platform_data (GApplication    *app,
                                    GVariantBuilder *builder)
@@ -270,6 +278,53 @@ ide_application_activate (GApplication *app)
   IDE_EXIT;
 }
 
+static void
+ide_application_open_cb (PeasExtensionSet *set,
+                         PeasPluginInfo   *plugin_info,
+                         PeasExtension    *exten,
+                         gpointer          user_data)
+{
+  IdeApplicationAddin *app_addin = (IdeApplicationAddin*) exten;
+  OpenData *data = user_data;
+
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_APPLICATION_ADDIN (app_addin));
+  g_assert (data != NULL);
+  g_assert (IDE_IS_APPLICATION (data->self));
+  g_assert (data->files != NULL);
+
+  ide_application_addin_open (app_addin, data->self, data->files, data->n_files, data->hint);
+}
+
+static void
+ide_application_open (GApplication  *app,
+                      GFile        **files,
+                      gint           n_files,
+                      const gchar   *hint)
+{
+  IdeApplication *self = (IdeApplication*)app;
+  OpenData data;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_APPLICATION (self));
+  g_assert (files);
+  g_assert (n_files > 0);
+  g_assert (hint);
+
+  data.self = self;
+  data.files = files;
+  data.n_files = n_files;
+  data.hint = hint;
+
+  if (self->addins != NULL)
+    peas_extension_set_foreach (self->addins, ide_application_open_cb, &data);
+
+  IDE_EXIT;
+}
+
 static void
 ide_application_dispose (GObject *object)
 {
@@ -305,6 +360,7 @@ ide_application_class_init (IdeApplicationClass *klass)
   object_class->dispose = ide_application_dispose;
 
   app_class->activate = ide_application_activate;
+  app_class->open = ide_application_open;
   app_class->add_platform_data = ide_application_add_platform_data;
   app_class->command_line = ide_application_command_line;
   app_class->local_command_line = ide_application_local_command_line;
@@ -340,7 +396,7 @@ _ide_application_new (gboolean     standalone,
                       const gchar *plugin,
                       const gchar *dbus_address)
 {
-  GApplicationFlags flags = G_APPLICATION_HANDLES_COMMAND_LINE;
+  GApplicationFlags flags = G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN;
   IdeApplication *self;
 
   if (standalone || ide_str_equal0 (type, "worker"))


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