Cocoa: support drag-and-drop of multiple objects.
This commit is contained in:
parent
b5c43a88b4
commit
65a1a3e7e9
@ -106,42 +106,64 @@
|
|||||||
|
|
||||||
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
- (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
|
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
|
||||||
|
{ @autoreleasepool
|
||||||
{
|
{
|
||||||
NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
|
NSPasteboard *pasteboard = [sender draggingPasteboard];
|
||||||
NSNumber *isAlias = nil;
|
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;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Functionality for resolving URL aliases was added with OS X 10.6. */
|
SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
|
||||||
if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
|
NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
|
||||||
[fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the URL is an alias, resolve it. */
|
for (NSString *path in array) {
|
||||||
if ([isAlias boolValue]) {
|
NSURL *fileURL = [[NSURL fileURLWithPath:path] autorelease];
|
||||||
NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
|
NSNumber *isAlias = nil;
|
||||||
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) {
|
/* Functionality for resolving URL aliases was added with OS X 10.6. */
|
||||||
fileURL = resolvedURL;
|
if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
|
||||||
|
[fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error: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];
|
||||||
|
|
||||||
|
if (resolvedURL != nil) {
|
||||||
|
fileURL = resolvedURL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!SDL_SendDropFile([[fileURL path] UTF8String])) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
|
return YES;
|
||||||
}
|
}}
|
||||||
|
|
||||||
- (BOOL)wantsPeriodicDraggingUpdates
|
- (BOOL)wantsPeriodicDraggingUpdates
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user