Skip to content

Commit cc2dd90

Browse files
committed
[osx] Fix Drag-n-drop
Old-style `NSFilenamesPboardType` would give an array of (string) file names. New-style `NSPasteboardTypeFileURL` gives exactly one file URL. Also, all file urls are Reference-type urls which we must massage first.
1 parent 833bc12 commit cc2dd90

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

platforms/iOS/vm/OSX/SqSqueakOSXView.m.inc

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -365,35 +365,34 @@ lastSeenKeyBoardModifierDetails,dragInProgress,dragCount,windowLogic;
365365

366366
#pragma mark Events - Dragging
367367

368+
- (NSMutableArray *) filterSqueakImageFilesFromDraggedFiles: (id<NSDraggingInfo>)info include: (BOOL)doInclude {
369+
NSPasteboard *pboard= [info draggingPasteboard];
370+
NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10];
371+
if ([[pboard types] containsObject: NSPasteboardTypeFileURL]) {
372+
NSArray *urlClasses = [NSArray arrayWithObject:[NSURL class]];
373+
NSDictionary *pbOptions = [NSDictionary dictionaryWithObject:
374+
[NSNumber numberWithBool:YES] forKey:NSPasteboardURLReadingFileURLsOnlyKey];
375+
NSArray *files = [pboard readObjectsForClasses:urlClasses options:pbOptions];
376+
for (NSURL *fileRefURL in files) {
377+
/*
378+
* Although we already have an URL, it is a file-refernce-type URL
379+
* of the form 'file:///.file/id=6571367.25595293' with numbers
380+
* apparently identifying the file. However, this does not say
381+
* anything about file names and such, which we rely on.
382+
*/
383+
NSURL* fileURL = fileRefURL.filePathURL;
384+
if ([((sqSqueakOSXApplication*) gDelegateApp.squeakApplication) isImageFile: [fileURL path]] == doInclude)
385+
[results addObject: fileURL];
386+
}
387+
}
388+
return results;
389+
}
368390
- (NSMutableArray *) filterSqueakImageFilesFromDraggedFiles: (id<NSDraggingInfo>)info {
369-
NSPasteboard *pboard= [info draggingPasteboard];
370-
NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10];
371-
if ([[pboard types] containsObject: NSPasteboardTypeFileURL]) {
372-
NSArray *files= [pboard propertyListForType: NSPasteboardTypeFileURL];
373-
NSString *fileName;
374-
for (fileName in files) {
375-
if ([((sqSqueakOSXApplication*) gDelegateApp.squeakApplication) isImageFile: fileName] == YES)
376-
[results addObject: fileName];
377-
}
378-
}
379-
return results;
391+
return [self filterSqueakImageFilesFromDraggedFiles: info include: YES];
380392
}
381393

382394
- (NSMutableArray *) filterOutSqueakImageFilesFromDraggedURIs: (id<NSDraggingInfo>)info {
383-
NSPasteboard *pboard= [info draggingPasteboard];
384-
NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10];
385-
if ([[pboard types] containsObject: NSPasteboardTypeFileURL]) {
386-
NSArray *files= [pboard propertyListForType: NSPasteboardTypeFileURL];
387-
NSString *fileName;
388-
for (fileName in files) {
389-
if ([((sqSqueakOSXApplication*) gDelegateApp.squeakApplication) isImageFile: fileName] == NO)
390-
{
391-
[results addObject: [NSURL fileURLWithPath: fileName]];
392-
}
393-
}
394-
}
395-
396-
return results;
395+
return [self filterSqueakImageFilesFromDraggedFiles: info include: NO];
397396
}
398397

399398
- (NSUInteger) countNumberOfNoneSqueakImageFilesInDraggedFiles: (id<NSDraggingInfo>)info {

0 commit comments

Comments
 (0)