[tepl/wip/file-loading: 4/4] App: add option to handle GApplication::open



commit 777e555987287e74acec753696d1d89e25771658
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Oct 10 16:05:44 2017 +0200

    App: add option to handle GApplication::open

 tepl/tepl-application.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/tepl/tepl-application.c b/tepl/tepl-application.c
index 4a9f3b2..dd02794 100644
--- a/tepl/tepl-application.c
+++ b/tepl/tepl-application.c
@@ -40,6 +40,8 @@ struct _TeplApplicationPrivate
        GtkApplication *gtk_app;
        AmtkActionInfoStore *app_action_info_store;
        AmtkActionInfoStore *tepl_action_info_store;
+
+       guint handle_open : 1;
 };
 
 enum
@@ -350,6 +352,63 @@ tepl_application_get_active_main_window (TeplApplication *tepl_app)
        return NULL;
 }
 
+static void
+open_cb (GApplication     *g_app,
+        GFile           **files,
+        gint              n_files,
+        const gchar      *hint,
+        TeplApplication  *tepl_app)
+{
+       GtkApplicationWindow *active_window;
+       GtkApplicationWindow *main_window;
+       TeplApplicationWindow *tepl_window;
+
+       if (n_files < 1)
+       {
+               return;
+       }
+
+       active_window = get_active_gcsv_window (GCSV_APPLICATION (app));
+
+       if (active_window != NULL)
+       {
+               gcsv_window = active_window;
+       }
+       else
+       {
+               gcsv_window = gcsv_window_new (GTK_APPLICATION (app));
+               gtk_widget_show (GTK_WIDGET (gcsv_window));
+       }
+
+       tepl_window = tepl_application_window_get_from_gtk_application_window (GTK_APPLICATION_WINDOW 
(gcsv_window));
+       tepl_application_window_open_file (tepl_window, files[0]);
+}
+
+/**
+ * tepl_application_handle_open:
+ * @tepl_app: a #TeplApplication.
+ *
+ * Connects a generic function handler for the GApplication::open signal.
+ *
+ * Since: 3.2
+ */
+void
+tepl_application_handle_open (TeplApplication *tepl_app)
+{
+       g_return_if_fail (TEPL_IS_APPLICATION (tepl_app));
+
+       if (!tepl_app->priv->handle_open)
+       {
+               g_signal_connect_object (tepl_app->priv->gtk_app,
+                                        "open",
+                                        G_CALLBACK (open_cb),
+                                        tepl_app,
+                                        0);
+
+               tepl_app->priv->handle_open = TRUE;
+       }
+}
+
 /**
  * tepl_application_open_simple:
  * @tepl_app: a #TeplApplication.


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