Cocoa: support drag-and-drop of multiple objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index dc9cefd..8914fe8 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -106,42 +106,64 @@
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
- return NSDragOperationGeneric;
+ if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
+ return NSDragOperationGeneric;
+ }
+
+ return NSDragOperationNone; /* no idea what to do with this, reject it. */
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
+{ @autoreleasepool
{
- NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
- NSNumber *isAlias = nil;
+ NSPasteboard *pasteboard = [sender draggingPasteboard];
+ NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
+ NSString *desiredType = [pasteboard availableTypeFromArray:types];
+ if (desiredType == nil) {
+ return NO; /* can't accept anything that's being dropped here. */
+ }
- if (fileURL == nil) {
+ NSData *data = [pasteboard dataForType:desiredType];
+ if (data == nil) {
return NO;
}
- /* Functionality for resolving URL aliases was added with OS X 10.6. */
- if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
- [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
- }
+ SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
+ NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
+
+ for (NSString *path in array) {
+ NSURL *fileURL = [[NSURL fileURLWithPath:path] autorelease];
+ NSNumber *isAlias = nil;
- /* If the URL is an alias, resolve it. */
- if ([isAlias boolValue]) {
- NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
- NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
- if (bookmark != nil) {
- NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
- options:opts
- relativeToURL:nil
- bookmarkDataIsStale:nil
- error:nil];
+ /* Functionality for resolving URL aliases was added with OS X 10.6. */
+ if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
+ [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
+ }
- if (resolvedURL != nil) {
- fileURL = resolvedURL;
+ /* If the URL is an alias, resolve it. */
+ if ([isAlias boolValue]) {
+ NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
+ NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
+ if (bookmark != nil) {
+ NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
+ options:opts
+ relativeToURL:nil
+ bookmarkDataIsStale:nil
+ error:nil];
+
+ if (resolvedURL != nil) {
+ fileURL = resolvedURL;
+ }
}
}
+
+ if (!SDL_SendDropFile([[fileURL path] UTF8String])) {
+ return NO;
+ }
}
- return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
-}
+ return YES;
+}}
- (BOOL)wantsPeriodicDraggingUpdates
{