mirror of https://github.com/mpv-player/mpv
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
This commit is contained in:
parent
60755108a6
commit
89a49ffd74
|
@ -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)) {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue