src/video/cocoa/SDL_cocoawindow.m
changeset 9795 63c4d6f1f85f
parent 9790 d968c87f2a5d
child 9796 e0db4fedf80c
equal deleted inserted replaced
9794:5aa6018e18ed 9795:63c4d6f1f85f
   104     /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
   104     /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
   105 }
   105 }
   106 
   106 
   107 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
   107 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
   108 {
   108 {
   109     return NSDragOperationGeneric;
   109     if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
       
   110         return NSDragOperationGeneric;
       
   111     }
       
   112 
       
   113     return NSDragOperationNone; /* no idea what to do with this, reject it. */
   110 }
   114 }
   111 
   115 
   112 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
   116 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
   113 {
   117 { @autoreleasepool
   114     NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
   118 {
   115     NSNumber *isAlias = nil;
   119     NSPasteboard *pasteboard = [sender draggingPasteboard];
   116 
   120     NSArray *types = [NSArray arrayWithObject:NSFilenamesPboardType];
   117     if (fileURL == nil) {
   121     NSString *desiredType = [pasteboard availableTypeFromArray:types];
       
   122     if (desiredType == nil) {
       
   123         return NO;  /* can't accept anything that's being dropped here. */
       
   124     }
       
   125 
       
   126     NSData *data = [pasteboard dataForType:desiredType];
       
   127     if (data == nil) {
   118         return NO;
   128         return NO;
   119     }
   129     }
   120 
   130 
   121     /* Functionality for resolving URL aliases was added with OS X 10.6. */
   131     SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
   122     if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
   132     NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
   123         [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
   133 
   124     }
   134     for (NSString *path in array) {
   125 
   135         NSURL *fileURL = [[NSURL fileURLWithPath:path] autorelease];
   126     /* If the URL is an alias, resolve it. */
   136         NSNumber *isAlias = nil;
   127     if ([isAlias boolValue]) {
   137 
   128         NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
   138         /* Functionality for resolving URL aliases was added with OS X 10.6. */
   129         NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
   139         if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
   130         if (bookmark != nil) {
   140             [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
   131             NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
   141         }
   132                                                            options:opts
   142 
   133                                                      relativeToURL:nil
   143         /* If the URL is an alias, resolve it. */
   134                                                bookmarkDataIsStale:nil
   144         if ([isAlias boolValue]) {
   135                                                              error:nil];
   145             NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
   136 
   146             NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
   137             if (resolvedURL != nil) {
   147             if (bookmark != nil) {
   138                 fileURL = resolvedURL;
   148                 NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
       
   149                                                                options:opts
       
   150                                                          relativeToURL:nil
       
   151                                                    bookmarkDataIsStale:nil
       
   152                                                                  error:nil];
       
   153 
       
   154                 if (resolvedURL != nil) {
       
   155                     fileURL = resolvedURL;
       
   156                 }
   139             }
   157             }
   140         }
   158         }
   141     }
   159 
   142 
   160         if (!SDL_SendDropFile([[fileURL path] UTF8String])) {
   143     return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
   161             return NO;
   144 }
   162         }
       
   163     }
       
   164 
       
   165     return YES;
       
   166 }}
   145 
   167 
   146 - (BOOL)wantsPeriodicDraggingUpdates
   168 - (BOOL)wantsPeriodicDraggingUpdates
   147 {
   169 {
   148     return NO;
   170     return NO;
   149 }
   171 }