src/video/cocoa/SDL_cocoawindow.m
changeset 9795 63c4d6f1f85f
parent 9790 d968c87f2a5d
child 9796 e0db4fedf80c
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Fri Jul 03 09:18:14 2015 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Jul 04 14:09:09 2015 -0400
     1.3 @@ -106,42 +106,64 @@
     1.4  
     1.5  - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
     1.6  {
     1.7 -    return NSDragOperationGeneric;
     1.8 +    if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
     1.9 +        return NSDragOperationGeneric;
    1.10 +    }
    1.11 +
    1.12 +    return NSDragOperationNone; /* no idea what to do with this, reject it. */
    1.13  }
    1.14  
    1.15  - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
    1.16 +{ @autoreleasepool
    1.17  {
    1.18 -    NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
    1.19 -    NSNumber *isAlias = nil;
    1.20 +    NSPasteboard *pasteboard = [sender draggingPasteboard];
    1.21 +    NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
    1.22 +    NSString *desiredType = [pasteboard availableTypeFromArray:types];
    1.23 +    if (desiredType == nil) {
    1.24 +        return NO;  /* can't accept anything that's being dropped here. */
    1.25 +    }
    1.26  
    1.27 -    if (fileURL == nil) {
    1.28 +    NSData *data = [pasteboard dataForType:desiredType];
    1.29 +    if (data == nil) {
    1.30          return NO;
    1.31      }
    1.32  
    1.33 -    /* Functionality for resolving URL aliases was added with OS X 10.6. */
    1.34 -    if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
    1.35 -        [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
    1.36 -    }
    1.37 +    SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
    1.38 +    NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
    1.39  
    1.40 -    /* If the URL is an alias, resolve it. */
    1.41 -    if ([isAlias boolValue]) {
    1.42 -        NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
    1.43 -        NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
    1.44 -        if (bookmark != nil) {
    1.45 -            NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
    1.46 -                                                           options:opts
    1.47 -                                                     relativeToURL:nil
    1.48 -                                               bookmarkDataIsStale:nil
    1.49 -                                                             error:nil];
    1.50 +    for (NSString *path in array) {
    1.51 +        NSURL *fileURL = [[NSURL fileURLWithPath:path] autorelease];
    1.52 +        NSNumber *isAlias = nil;
    1.53  
    1.54 -            if (resolvedURL != nil) {
    1.55 -                fileURL = resolvedURL;
    1.56 +        /* Functionality for resolving URL aliases was added with OS X 10.6. */
    1.57 +        if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
    1.58 +            [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
    1.59 +        }
    1.60 +
    1.61 +        /* If the URL is an alias, resolve it. */
    1.62 +        if ([isAlias boolValue]) {
    1.63 +            NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
    1.64 +            NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
    1.65 +            if (bookmark != nil) {
    1.66 +                NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
    1.67 +                                                               options:opts
    1.68 +                                                         relativeToURL:nil
    1.69 +                                                   bookmarkDataIsStale:nil
    1.70 +                                                                 error:nil];
    1.71 +
    1.72 +                if (resolvedURL != nil) {
    1.73 +                    fileURL = resolvedURL;
    1.74 +                }
    1.75              }
    1.76          }
    1.77 +
    1.78 +        if (!SDL_SendDropFile([[fileURL path] UTF8String])) {
    1.79 +            return NO;
    1.80 +        }
    1.81      }
    1.82  
    1.83 -    return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
    1.84 -}
    1.85 +    return YES;
    1.86 +}}
    1.87  
    1.88  - (BOOL)wantsPeriodicDraggingUpdates
    1.89  {