macOS: Fix drag and drop of files not working on mojave

Fixes #1058
This commit is contained in:
Kovid Goyal 2018-10-11 18:36:24 +05:30
parent b4afbe47b3
commit c493583f25
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 14 additions and 5 deletions

View File

@ -15,6 +15,8 @@ Changelog
- Fix incorrect key repeat rate on wayland (:pull:`1055`) - Fix incorrect key repeat rate on wayland (:pull:`1055`)
- macOS: Fix drag and drop of files not working on mojave (:iss:`1058`)
0.12.3 [2018-09-29] 0.12.3 [2018-09-29]
------------------------------ ------------------------------

View File

@ -917,17 +917,24 @@ is_ascii_control_char(char x) {
return YES; return YES;
} }
- (NSArray *)fileURLWithDraggingInfo:(id <NSDraggingInfo>)sender
{
NSPasteboard *pasteboard = [sender draggingPasteboard];
NSDictionary *options = [NSDictionary dictionaryWithObject:@YES forKey:NSPasteboardURLReadingFileURLsOnlyKey];
NSArray *results = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]] options:options];
return results;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ {
NSPasteboard* pasteboard = [sender draggingPasteboard];
NSArray* files = [pasteboard propertyListForType:NSPasteboardTypeFileURL];
const NSRect contentRect = [window->ns.view frame]; const NSRect contentRect = [window->ns.view frame];
_glfwInputCursorPos(window, _glfwInputCursorPos(window,
[sender draggingLocation].x, [sender draggingLocation].x,
contentRect.size.height - [sender draggingLocation].y); contentRect.size.height - [sender draggingLocation].y);
const NSArray* files = [self fileURLWithDraggingInfo:sender];
if (!files) return NO;
const NSUInteger count = [files count]; const NSUInteger count = [files count];
if (count) if (count)
{ {
NSEnumerator* e = [files objectEnumerator]; NSEnumerator* e = [files objectEnumerator];
@ -935,7 +942,7 @@ is_ascii_control_char(char x) {
NSUInteger i; NSUInteger i;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
paths[i] = _glfw_strdup([[e nextObject] UTF8String]); paths[i] = _glfw_strdup([[[e nextObject] path] UTF8String]);
_glfwInputDrop(window, (int) count, (const char**) paths); _glfwInputDrop(window, (int) count, (const char**) paths);