[gtk-mac-integration] Get GtkApplicationDelegate's application:openFile: handler to work at startup.



commit 866586a77970b4cb1095dda4951313ebc6a04907
Author: John Ralls <jralls ceridwen us>
Date:   Thu Mar 26 11:38:13 2015 +0900

    Get GtkApplicationDelegate's application:openFile: handler to work at startup.
    
    It fires off the signal before the main loop has started, so stash the
    URI in a static for applicationDidFinishLaunching to fire the signal.

 src/GtkApplicationDelegate.c |   31 +++++++++++++++++++++++++++----
 src/test-integration.c       |   11 +++++++++--
 2 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/src/GtkApplicationDelegate.c b/src/GtkApplicationDelegate.c
index e7ecd2c..74f0148 100644
--- a/src/GtkApplicationDelegate.c
+++ b/src/GtkApplicationDelegate.c
@@ -24,16 +24,36 @@
 #include <gtk/gtk.h>
 #include "gtkosxapplication.h"
 
+static gchar *utf8_path = NULL;
+
 @implementation GtkApplicationDelegate
+
+-(void) applicationDidFinishLaunching: (NSNotification*)aNotification
+{
+  if (utf8_path != NULL)
+    {
+      GtkosxApplication *app = g_object_new (GTKOSX_TYPE_APPLICATION, NULL);
+      guint sig = g_signal_lookup ("NSApplicationOpenFile",
+                                  GTKOSX_TYPE_APPLICATION);
+      gboolean result = FALSE;
+      if (sig)
+       g_signal_emit (app, sig, 0, utf8_path, &result);
+      g_object_unref (app);
+    }
+}
+
 -(BOOL) application: (NSApplication*)theApplication openFile: (NSString*) file
 {
-  const gchar *utf8_path =  [file UTF8String];
+  utf8_path =  [file UTF8String];
   GtkosxApplication *app = g_object_new (GTKOSX_TYPE_APPLICATION, NULL);
   guint sig = g_signal_lookup ("NSApplicationOpenFile",
-  GTKOSX_TYPE_APPLICATION);
+                              GTKOSX_TYPE_APPLICATION);
   gboolean result = FALSE;
   if (sig)
-    g_signal_emit (app, sig, 0, utf8_path, &result);
+    {
+      g_signal_emit (app, sig, 0, utf8_path, &result);
+      utf8_path = NULL;
+    }
   g_object_unref (app);
   return result;
 }
@@ -56,7 +76,10 @@
   g_object_unref (app);
   inHandler = FALSE;
   if (!result)
-    return NSTerminateNow;
+    {
+      g_object_unref (app);
+      return NSTerminateNow;
+    }
   else
     return NSTerminateCancel;
 }
diff --git a/src/test-integration.c b/src/test-integration.c
index 7277207..839c978 100644
--- a/src/test-integration.c
+++ b/src/test-integration.c
@@ -616,7 +616,14 @@ app_will_quit_cb (GtkosxApplication *app, gpointer data)
 static gboolean
 app_open_file_cb (GtkosxApplication *app, gchar *path, gpointer user_data)
 {
-  g_print ("File open event for %s", path);
+  GtkWindow *parent = GTK_WINDOW(user_data);
+  GtkDialog *dialog = gtk_message_dialog_new (parent,
+                                             GTK_DIALOG_DESTROY_WITH_PARENT,
+                                             GTK_MESSAGE_INFO,
+                                             GTK_BUTTONS_CLOSE,
+                                             "File open event for %s", path);
+  gtk_dialog_run (dialog);
+  gtk_widget_destroy (dialog);
   return FALSE;
 }
 
@@ -850,7 +857,7 @@ main (int argc, char **argv)
     g_signal_connect (theApp, "NSApplicationWillTerminate",
                       G_CALLBACK (app_will_quit_cb), NULL);
     g_signal_connect (theApp, "NSApplicationOpenFile",
-                      G_CALLBACK (app_open_file_cb), NULL);
+                      G_CALLBACK (app_open_file_cb), (gconstpointer)window1);
   }
 # ifndef QUARTZ_HANDLERS
   gtkosx_application_set_use_quartz_accelerators (theApp, FALSE);


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