From 3d29b2ce5cd5909441ec849f89a7b4a39273ef09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Dj=C3=A4rv?= Date: Sat, 11 Aug 2012 11:10:08 +0200 Subject: [PATCH] * nsterm.m (not_in_argv): New function. (application:openFile, application:openTempFile:): (application:openFileWithoutUI:, application:openFiles:): Open file if not_in_argv returns non-zero. Fixes: debbugs:12171 --- src/ChangeLog | 5 +++++ src/nsterm.m | 34 ++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b60ab6ec56f..7f89fcbe867 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2012-08-11 Jan Djärv + * nsterm.m (not_in_argv): New function. + (application:openFile, application:openTempFile:): + (application:openFileWithoutUI:, application:openFiles:): Open file + if not_in_argv returns non-zero (bug#12171). + * gtkutil.c (gtk_font_chooser_dialog_new, GTK_FONT_CHOOSER) (gtk_font_chooser_set_font, gtk_font_chooser_get_font): Define for Gtk+ versions less than 3.2. diff --git a/src/nsterm.m b/src/nsterm.m index 807ff564213..b99241f4e15 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -4448,11 +4448,20 @@ ns_term_shutdown (int sig) return NSTerminateNow; /* just in case */ } +static int +not_in_argv (NSString *arg) +{ + int k; + const char *a = [arg UTF8String]; + for (k = 1; k < initial_argc; ++k) + if (strcmp (a, initial_argv[k]) == 0) return 0; + return 1; +} /* Notification from the Workspace to open a file */ - (BOOL)application: sender openFile: (NSString *)file { - if (ns_do_open_file) + if (ns_do_open_file || not_in_argv (file)) [ns_pending_files addObject: file]; return YES; } @@ -4461,7 +4470,7 @@ ns_term_shutdown (int sig) /* Open a file as a temporary file */ - (BOOL)application: sender openTempFile: (NSString *)file { - if (ns_do_open_file) + if (ns_do_open_file || not_in_argv (file)) [ns_pending_files addObject: file]; return YES; } @@ -4470,25 +4479,22 @@ ns_term_shutdown (int sig) /* Notification from the Workspace to open a file noninteractively (?) */ - (BOOL)application: sender openFileWithoutUI: (NSString *)file { - if (ns_do_open_file) + if (ns_do_open_file || not_in_argv (file)) [ns_pending_files addObject: file]; return YES; } - /* Notification from the Workspace to open multiple files */ - (void)application: sender openFiles: (NSArray *)fileList { - /* Don't open files from the command line, Cocoa parses the command line - wrong anyway, --option value tries to open value if --option is the last - option. */ - if (ns_do_open_file) - { - NSEnumerator *files = [fileList objectEnumerator]; - NSString *file; - while ((file = [files nextObject]) != nil) - [ns_pending_files addObject: file]; - } + NSEnumerator *files = [fileList objectEnumerator]; + NSString *file; + /* Don't open files from the command line unconditionally, + Cocoa parses the command line wrong, --option value tries to open value + if --option is the last option. */ + while ((file = [files nextObject]) != nil) + if (ns_do_open_file || not_in_argv (file)) + [ns_pending_files addObject: file]; [self replyToOpenOrPrint: NSApplicationDelegateReplySuccess]; -- 2.39.2