summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich Beckmann <friedrich.beckmann@gmx.de>2020-06-16 16:59:06 +0200
committerFriedrich Beckmann <friedrich.beckmann@gmx.de>2020-06-16 16:59:06 +0200
commit665f8b6b8787534c2477ff6a076c4563b32f01df (patch)
treef8c838d5220d0e870fe0c1dcccf85f751bd1679f
parent3065f47ab55e2d87d51d672950f01d6a431e6070 (diff)
downloadgtk+-665f8b6b8787534c2477ff6a076c4563b32f01df.tar.gz
quartz: added open capability to gtk_application
This patch implements the openFiles delegate which is required to open files which are associated with an application via the Finder or via open on the command line. The patch has been proposed by jessevdk@gmail.com. See: https://gitlab.gnome.org/GNOME/gtk/-/issues/463 I tested the patch with the GNU pspp application on MacOS with the quartz backend.
-rw-r--r--gtk/gtkapplication-quartz.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/gtk/gtkapplication-quartz.c b/gtk/gtkapplication-quartz.c
index 9794d7b862..7abea53a5d 100644
--- a/gtk/gtkapplication-quartz.c
+++ b/gtk/gtkapplication-quartz.c
@@ -64,6 +64,7 @@ G_DEFINE_TYPE (GtkApplicationImplQuartz, gtk_application_impl_quartz, GTK_TYPE_A
- (id)initWithImpl:(GtkApplicationImplQuartz*)impl;
- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender;
+- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames;
@end
@implementation GtkApplicationQuartzDelegate
@@ -84,6 +85,35 @@ G_DEFINE_TYPE (GtkApplicationImplQuartz, gtk_application_impl_quartz, GTK_TYPE_A
*/
return quartz->quit_inhibit == 0 ? NSTerminateNow : NSTerminateCancel;
}
+
+-(void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames
+{
+ GFile **files;
+ gint i;
+ GApplicationFlags flags;
+
+ flags = g_application_get_flags (G_APPLICATION (quartz->impl.application));
+
+ if (~flags & G_APPLICATION_HANDLES_OPEN)
+ {
+ [theApplication replyToOpenOrPrint:NSApplicationDelegateReplyFailure];
+ return;
+ }
+
+ files = g_new (GFile *, [filenames count]);
+
+ for (i = 0; i < [filenames count]; i++)
+ files[i] = g_file_new_for_path ([(NSString *)[filenames objectAtIndex:i] UTF8String]);
+
+ g_application_open (G_APPLICATION (quartz->impl.application), files, [filenames count], "");
+
+ for (i = 0; i < [filenames count]; i++)
+ g_object_unref (files[i]);
+
+ g_free (files);
+
+ [theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
+}
@end
/* these exist only for accel handling */