Skip to content

Commit

Permalink
osxbundle: cocoa_common: change playlist on fileopen events
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pigoz committed Jan 16, 2013
1 parent 6075510 commit 89a49ff
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions video/out/cocoa_common.m
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,26 @@ - (void)mouseEvent:(NSEvent *)theEvent
}
}

- (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)) {
Expand Down
1 change: 1 addition & 0 deletions video/out/osx_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
21 changes: 21 additions & 0 deletions video/out/osx_common.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,24 @@ int is_osx_version_at_least(int majorv, int minorv, int bugfixv)
[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;
}

0 comments on commit 89a49ff

Please sign in to comment.