check filetypes when drag-n-dropping to the recent window.

alt skips filetype check.
This commit is contained in:
Kelvin Sherlock 2020-09-15 23:11:20 -04:00
parent 59ce93bbc0
commit d5d869a407

View File

@ -19,6 +19,7 @@
@implementation DiskImagesWindowController { @implementation DiskImagesWindowController {
BOOL _dirty; BOOL _dirty;
NSSet *_extensions;
} }
@ -28,6 +29,10 @@
if ((self = [super init])) { if ((self = [super init])) {
[self loadRecentDiskImages]; [self loadRecentDiskImages];
_extensions = [NSSet setWithObjects:
@"2img", @"2mg", @"chd", @"dc", @"do", @"dsk", @"hd", @"hdv", @"image", @"nib", @"po", @"wav", @"woz", @"iso", nil
];
} }
return self; return self;
} }
@ -190,8 +195,19 @@
} }
-(NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id<NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation { -(NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id<NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation {
// option key will ignore all filetype restrictions.
if ([NSEvent modifierFlags] & NSEventModifierFlagOption) return NSDragOperationCopy;
NSPasteboard * pb = [info draggingPasteboard];
NSURL *url = [NSURL URLFromPasteboard: pb];
return NSDragOperationCopy; NSString *ext = [url pathExtension];
ext = [ext lowercaseString];
if ([_extensions containsObject: ext])
return NSDragOperationCopy;
return NSDragOperationNone;
} }
-(BOOL)tableView:(NSTableView *)tableView acceptDrop:(id<NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation { -(BOOL)tableView:(NSTableView *)tableView acceptDrop:(id<NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation {