mirror of
https://github.com/mpv-player/mpv
synced 2025-02-23 08:26:56 +00:00
cocoa: refactor files drag and drop on the Dock icon
Use the newly added `mp_event_drop_files` core function instead of having logic in the platform dependent code.
This commit is contained in:
parent
082c5c19a1
commit
69d44d992c
@ -22,6 +22,7 @@
|
||||
|
||||
#include "common/msg.h"
|
||||
#include "input/input.h"
|
||||
#include "input/event.h"
|
||||
#include "input/keycodes.h"
|
||||
|
||||
#include "osdep/macosx_application_objc.h"
|
||||
@ -55,21 +56,6 @@ Application *mpv_shared_app(void)
|
||||
return (Application *)[Application sharedApplication];
|
||||
}
|
||||
|
||||
static NSString *escape_loadfile_name(NSString *input)
|
||||
{
|
||||
NSArray *mappings = @[
|
||||
@{ @"in": @"\\", @"out": @"\\\\" },
|
||||
@{ @"in": @"\"", @"out": @"\\\"" },
|
||||
];
|
||||
|
||||
for (NSDictionary *mapping in mappings) {
|
||||
input = [input stringByReplacingOccurrencesOfString:mapping[@"in"]
|
||||
withString:mapping[@"out"]];
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@implementation Application
|
||||
@synthesize files = _files;
|
||||
@synthesize argumentsList = _arguments_list;
|
||||
@ -287,17 +273,23 @@ static NSString *escape_loadfile_name(NSString *input)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)handleFilesArray:(NSArray *)files
|
||||
{
|
||||
size_t num_files = [files count];
|
||||
char **files_utf8 = talloc_array(NULL, char*, num_files);
|
||||
[files enumerateObjectsUsingBlock:^(id obj, NSUInteger i, BOOL *_){
|
||||
char *filename = (char *)[obj UTF8String];
|
||||
size_t bytes = [obj lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
|
||||
files_utf8[i] = talloc_memdup(files_utf8, filename, bytes + 1);
|
||||
}];
|
||||
mp_event_drop_files(self.inputContext, num_files, files_utf8);
|
||||
talloc_free(files_utf8);
|
||||
}
|
||||
|
||||
- (void)handleFiles
|
||||
{
|
||||
void *ctx = talloc_new(NULL);
|
||||
[self.files enumerateObjectsUsingBlock:^(id obj, NSUInteger i, BOOL *_){
|
||||
const char *file = [escape_loadfile_name(obj) UTF8String];
|
||||
const char *append = (i == 0) ? "" : " append";
|
||||
char *cmd = talloc_asprintf(ctx, "raw loadfile \"%s\"%s", file, append);
|
||||
mp_cmd_t *cmdt = mp_input_parse_cmd(self.inputContext, bstr0(cmd), "");
|
||||
mp_input_queue_cmd(self.inputContext, cmdt);
|
||||
}];
|
||||
talloc_free(ctx);
|
||||
[self handleFilesArray:self.files];
|
||||
}
|
||||
@end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user