From cc2dd909045721f6cbf16cb62f5662fe68158021 Mon Sep 17 00:00:00 2001 From: Tobias Pape Date: Mon, 18 Dec 2023 15:41:18 +0100 Subject: [PATCH] [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. --- platforms/iOS/vm/OSX/SqSqueakOSXView.m.inc | 49 +++++++++++----------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/platforms/iOS/vm/OSX/SqSqueakOSXView.m.inc b/platforms/iOS/vm/OSX/SqSqueakOSXView.m.inc index e30908cf24..ce7b834ed1 100644 --- a/platforms/iOS/vm/OSX/SqSqueakOSXView.m.inc +++ b/platforms/iOS/vm/OSX/SqSqueakOSXView.m.inc @@ -365,35 +365,34 @@ lastSeenKeyBoardModifierDetails,dragInProgress,dragCount,windowLogic; #pragma mark Events - Dragging +- (NSMutableArray *) filterSqueakImageFilesFromDraggedFiles: (id)info include: (BOOL)doInclude { + NSPasteboard *pboard= [info draggingPasteboard]; + NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10]; + if ([[pboard types] containsObject: NSPasteboardTypeFileURL]) { + NSArray *urlClasses = [NSArray arrayWithObject:[NSURL class]]; + NSDictionary *pbOptions = [NSDictionary dictionaryWithObject: + [NSNumber numberWithBool:YES] forKey:NSPasteboardURLReadingFileURLsOnlyKey]; + NSArray *files = [pboard readObjectsForClasses:urlClasses options:pbOptions]; + for (NSURL *fileRefURL in files) { + /* + * Although we already have an URL, it is a file-refernce-type URL + * of the form 'file:///.file/id=6571367.25595293' with numbers + * apparently identifying the file. However, this does not say + * anything about file names and such, which we rely on. + */ + NSURL* fileURL = fileRefURL.filePathURL; + if ([((sqSqueakOSXApplication*) gDelegateApp.squeakApplication) isImageFile: [fileURL path]] == doInclude) + [results addObject: fileURL]; + } + } + return results; +} - (NSMutableArray *) filterSqueakImageFilesFromDraggedFiles: (id)info { - NSPasteboard *pboard= [info draggingPasteboard]; - NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10]; - if ([[pboard types] containsObject: NSPasteboardTypeFileURL]) { - NSArray *files= [pboard propertyListForType: NSPasteboardTypeFileURL]; - NSString *fileName; - for (fileName in files) { - if ([((sqSqueakOSXApplication*) gDelegateApp.squeakApplication) isImageFile: fileName] == YES) - [results addObject: fileName]; - } - } - return results; + return [self filterSqueakImageFilesFromDraggedFiles: info include: YES]; } - (NSMutableArray *) filterOutSqueakImageFilesFromDraggedURIs: (id)info { - NSPasteboard *pboard= [info draggingPasteboard]; - NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10]; - if ([[pboard types] containsObject: NSPasteboardTypeFileURL]) { - NSArray *files= [pboard propertyListForType: NSPasteboardTypeFileURL]; - NSString *fileName; - for (fileName in files) { - if ([((sqSqueakOSXApplication*) gDelegateApp.squeakApplication) isImageFile: fileName] == NO) - { - [results addObject: [NSURL fileURLWithPath: fileName]]; - } - } - } - - return results; + return [self filterSqueakImageFilesFromDraggedFiles: info include: NO]; } - (NSUInteger) countNumberOfNoneSqueakImageFilesInDraggedFiles: (id)info {