Cocoa: support drag-and-drop of multiple objects.

This commit is contained in:
Ryan C. Gordon 2015-07-04 14:09:09 -04:00
parent b5c43a88b4
commit 65a1a3e7e9
1 changed files with 44 additions and 22 deletions

View File

@ -106,18 +106,35 @@
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
if (([sender draggingSourceOperationMask] & NSDragOperationGeneric) == NSDragOperationGeneric) {
return NSDragOperationGeneric;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
NSNumber *isAlias = nil;
return NSDragOperationNone; /* no idea what to do with this, reject it. */
}
if (fileURL == nil) {
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{ @autoreleasepool
{
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. */
}
NSData *data = [pasteboard dataForType:desiredType];
if (data == nil) {
return NO;
}
SDL_assert([desiredType isEqualToString:NSFilenamesPboardType]);
NSArray *array = [pasteboard propertyListForType:@"NSFilenamesPboardType"];
for (NSString *path in array) {
NSURL *fileURL = [[NSURL fileURLWithPath:path] autorelease];
NSNumber *isAlias = 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];
@ -140,8 +157,13 @@
}
}
return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
if (!SDL_SendDropFile([[fileURL path] UTF8String])) {
return NO;
}
}
return YES;
}}
- (BOOL)wantsPeriodicDraggingUpdates
{