diff options
Diffstat (limited to 'macosx/HBController.m')
-rw-r--r-- | macosx/HBController.m | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/macosx/HBController.m b/macosx/HBController.m index df2b90863..a0a72a941 100644 --- a/macosx/HBController.m +++ b/macosx/HBController.m @@ -5,6 +5,7 @@ It may be used under the terms of the GNU General Public License. */ #import "HBController.h" +#import "HBFocusRingView.h" #import "HBQueueController.h" #import "HBTitleSelectionController.h" @@ -32,7 +33,7 @@ #import "HBJob.h" #import "HBStateFormatter.h" -@interface HBController () <HBPresetsViewControllerDelegate, HBTitleSelectionDelegate, NSDrawerDelegate> +@interface HBController () <HBPresetsViewControllerDelegate, HBTitleSelectionDelegate, NSDrawerDelegate, NSDraggingDestination> { IBOutlet NSTabView *fMainTabView; @@ -246,56 +247,54 @@ #pragma mark - #pragma mark Drag & drop handling -/** This method is used by OSX to know what kind of files can be drag & drop on the NSWindow - * We only want filenames (and so folders too) - */ -- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender +- (nullable NSArray<NSURL *> *)fileURLsFromPasteboard:(NSPasteboard *)pasteboard { - NSPasteboard *pboard = [sender draggingPasteboard]; - - if ([[pboard types] containsObject:NSFilenamesPboardType]) - { - NSArray *paths = [pboard propertyListForType:NSFilenamesPboardType]; - return paths.count == 1 ? NSDragOperationGeneric : NSDragOperationNone; - } + NSDictionary *options = @{NSPasteboardURLReadingFileURLsOnlyKey: @YES}; + return [pasteboard readObjectsForClasses:@[[NSURL class]] options:options]; +} - return NSDragOperationNone; +- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender +{ + NSArray<NSURL *> *fileURLs = [self fileURLsFromPasteboard:[sender draggingPasteboard]]; + [self.window.contentView setShowFocusRing:YES]; + return fileURLs.count ? NSDragOperationGeneric : NSDragOperationNone; } -// This method is doing the job after the drag & drop operation has been validated by [self draggingEntered] and OSX - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender { - NSPasteboard *pboard = [sender draggingPasteboard]; + NSArray<NSURL *> *fileURLs = [self fileURLsFromPasteboard:[sender draggingPasteboard]]; - if ([pboard.types containsObject:NSFilenamesPboardType]) + if (fileURLs.count) { - NSArray *paths = [pboard propertyListForType:NSFilenamesPboardType]; - [self openURL:[NSURL fileURLWithPath:paths.firstObject]]; + [self openURL:fileURLs.firstObject]; } + [self.window.contentView setShowFocusRing:NO]; return YES; } +- (void)draggingExited:(nullable id <NSDraggingInfo>)sender +{ + [self.window.contentView setShowFocusRing:NO]; +} + #pragma mark - KVO - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (context == NULL) + if ([keyPath isEqualToString:@"values.HBShowAdvancedTab"]) { - if ([keyPath isEqualToString:@"values.HBShowAdvancedTab"]) + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HBShowAdvancedTab"]) { - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HBShowAdvancedTab"]) - { - if (![[fMainTabView tabViewItems] containsObject:fAdvancedTab]) - { - [fMainTabView insertTabViewItem:fAdvancedTab atIndex:3]; - } - } - else + if (![[fMainTabView tabViewItems] containsObject:fAdvancedTab]) { - [fMainTabView removeTabViewItem:fAdvancedTab]; + [fMainTabView insertTabViewItem:fAdvancedTab atIndex:5]; } } + else + { + [fMainTabView removeTabViewItem:fAdvancedTab]; + } } else { |