[4.0] Fix file drag-drop on M1 Macs.

This commit is contained in:
bruvzg 2020-12-23 18:00:50 +02:00
parent 8ad0ff8ae5
commit 39bcc77d6a
No known key found for this signature in database
GPG Key ID: 009E1BFE42239B95
1 changed files with 25 additions and 21 deletions

View File

@ -751,28 +751,32 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
ERR_FAIL_COND_V(!DS_OSX->windows.has(window_id), NO);
DisplayServerOSX::WindowData &wd = DS_OSX->windows[window_id];
NSPasteboard *pboard = [sender draggingPasteboard];
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
NSArray<NSURL *> *filenames = [pboard propertyListForType:NSPasteboardTypeFileURL];
#else
NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
#endif
Vector<String> files;
for (NSUInteger i = 0; i < filenames.count; i++) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
NSString *ns = [[filenames objectAtIndex:i] path];
#else
NSString *ns = [filenames objectAtIndex:i];
#endif
char *utfs = strdup([ns UTF8String]);
String ret;
ret.parse_utf8(utfs);
free(utfs);
files.push_back(ret);
}
if (!wd.drop_files_callback.is_null()) {
Vector<String> files;
NSPasteboard *pboard = [sender draggingPasteboard];
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
NSArray *items = pboard.pasteboardItems;
for (NSPasteboardItem *item in items) {
NSString *path = [item stringForType:NSPasteboardTypeFileURL];
NSString *ns = [NSURL URLWithString:path].path;
char *utfs = strdup([ns UTF8String]);
String ret;
ret.parse_utf8(utfs);
free(utfs);
files.push_back(ret);
}
#else
NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
for (NSString *ns in filenames) {
char *utfs = strdup([ns UTF8String]);
String ret;
ret.parse_utf8(utfs);
free(utfs);
files.push_back(ret);
}
#endif
Variant v = files;
Variant *vp = &v;
Variant ret;