From 89a49ffd74f8be4ff36b0e6500e7b4434944c7fa Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 16 Jan 2013 00:42:07 +0100 Subject: osxbundle: cocoa_common: change playlist on fileopen events When opening new files in Finder when `mpv` is running from an application bundle, the new files will now replace the current playlist. Fixes #14 --- video/out/cocoa_common.m | 20 ++++++++++++++++++++ video/out/osx_common.h | 1 + video/out/osx_common.m | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+) (limited to 'video') diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index 071366c378..c713398863 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -767,6 +767,26 @@ void create_menu() } } +- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSArray *sorted_filenames = [filenames + sortedArrayUsingSelector:@selector(compare:)]; + + for (int i = 0; i < [sorted_filenames count]; i++) { + NSString *filename = [sorted_filenames objectAtIndex:i]; + NSString *escaped_filename = escape_loadfile_name(filename); + + char *cmd = talloc_asprintf(NULL, "loadfile \"%s\"%s", + [escaped_filename UTF8String], + (i == 0) ? "" : " append"); + mp_input_queue_cmd(_vo->input_ctx, mp_input_parse_cmd(bstr0(cmd), "")); + talloc_free(cmd); + } + + [pool release]; +} + - (void)applicationWillBecomeActive:(NSNotification *)aNotification { if (vo_fs && current_screen_has_dock_or_menubar(_vo)) { diff --git a/video/out/osx_common.h b/video/out/osx_common.h index ae31a6353d..8d2d70edc4 100644 --- a/video/out/osx_common.h +++ b/video/out/osx_common.h @@ -23,5 +23,6 @@ struct vo; int convert_key(unsigned key, unsigned charcode); int is_osx_version_at_least(int majorv, int minorv, int bugfixv); +NSString *escape_loadfile_name(NSString *input); #endif /* MPLAYER_OSX_COMMON_H */ diff --git a/video/out/osx_common.m b/video/out/osx_common.m index 58198c11e2..2d22fc52dc 100644 --- a/video/out/osx_common.m +++ b/video/out/osx_common.m @@ -152,3 +152,24 @@ cleanup_and_return: [pool release]; return rv; } + +struct escape_couple { + NSString *in; + NSString *out; +}; + +static struct escape_couple escapes[] = { + { @"\\", @"\\\\" }, + { @"\"", @"\\\"" }, + { NULL, NULL } +}; + +NSString *escape_loadfile_name(NSString *input) +{ + for (int i = 0; escapes[i].out; i++) { + input = [input stringByReplacingOccurrencesOfString:escapes[i].in + withString:escapes[i].out]; + } + + return input; +} -- cgit v1.2.3