Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
shincurry committed Aug 11, 2020
1 parent f5797a0 commit 7c70c49
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
38 changes: 19 additions & 19 deletions DUImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ @implementation DUImageView

- (void) awakeFromNib
{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_14
[self registerForDraggedTypes: [NSArray arrayWithObjects: NSPasteboardTypeFileURL, nil]];
#else
[self registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
#endif
}

- (NSDragOperation) draggingEntered: (id < NSDraggingInfo >) sender
Expand All @@ -30,26 +34,22 @@ - (BOOL) performDragOperation: (id < NSDraggingInfo >) sender
NSPasteboard *pboard = [sender draggingPasteboard];
BOOL successful = NO;

if ([[pboard types] containsObject: NSPasteboardTypeFileURL])
{
/**
Note: tmp fix
ENV: Xcode 11.3.1 (11C504) Catalina 10.15.3 (19D76)
Don't know why [pboard propertyListForType: NSPasteboardTypeFileURL] returns a string directly instead of an array.
*/
NSObject *data = [pboard propertyListForType: NSPasteboardTypeFileURL];
if ([data isKindOfClass: [NSArray class]]) {
NSArray * files = (NSArray *)data;
[controller startConversion: [files objectAtIndex: 0]];
} else if ([data isKindOfClass: [NSString class]]) {
NSString * filePath = (NSString *)data;
NSURL * fileUrl = [NSURL URLWithString: filePath];
[controller startConversion: fileUrl.path];
}
successful = NO;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_14
if ([[pboard types] containsObject: NSPasteboardTypeFileURL]) {
NSArray<NSURL *> *filenames = [pboard propertyListForType:NSPasteboardTypeFileURL];
NSURL * filename = [filenames objectAtIndex: 0];
[controller startConversion: [filename path]];
successful = YES;
}

#else
if ([[pboard types] containsObject: NSFilenamesPboardType]) {
NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
NSString * filename = [filenames objectAtIndex: 0];
[controller startConversion: filename];
successful = YES;
}
#endif

return successful;
}

Expand Down
37 changes: 18 additions & 19 deletions DUWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ @implementation DUWindow

- (void) awakeFromNib
{
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_14
[self registerForDraggedTypes: [NSArray arrayWithObjects: NSPasteboardTypeFileURL, nil]];
#else
[self registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
#endif
}

- (NSDragOperation) draggingEntered: (id < NSDraggingInfo >) sender
Expand All @@ -30,26 +34,21 @@ - (BOOL) performDragOperation: (id < NSDraggingInfo >) sender
NSPasteboard *pboard = [sender draggingPasteboard];
BOOL successful = NO;

if ([[pboard types] containsObject: NSPasteboardTypeFileURL])
{
/**
Note: tmp fix
ENV: Xcode 11.3.1 (11C504) Catalina 10.15.3 (19D76)
Don't know why [pboard propertyListForType: NSPasteboardTypeFileURL] returns a string directly instead of an array.
*/
NSObject *data = [pboard propertyListForType: NSPasteboardTypeFileURL];
if ([data isKindOfClass: [NSArray class]]) {
NSArray * files = (NSArray *)data;
[controller startConversion: [files objectAtIndex: 0]];
} else if ([data isKindOfClass: [NSString class]]) {
NSString * filePath = (NSString *)data;
NSURL * fileUrl = [NSURL URLWithString: filePath];
[controller startConversion: fileUrl.path];
}

successful = NO;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_14
if ([[pboard types] containsObject: NSPasteboardTypeFileURL]) {
NSArray<NSURL *> *filenames = [pboard propertyListForType:NSPasteboardTypeFileURL];
NSURL * filename = [filenames objectAtIndex: 0];
[controller startConversion: [filename path]];
successful = YES;
}
#else
if ([[pboard types] containsObject: NSFilenamesPboardType]) {
NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
NSString * filename = [filenames objectAtIndex: 0];
[controller startConversion: filename];
successful = YES;
}
#endif

return successful;
}
Expand Down

0 comments on commit 7c70c49

Please sign in to comment.