From: Damiano Galassi Date: Thu, 13 Dec 2018 12:23:34 +0000 (+0100) Subject: MacGui: add a touch bar button to open a new source when all the windows are closed. X-Git-Tag: 1.2.0~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4475ff63b6dcf61cc90d8667d070022b18654b6e;p=handbrake MacGui: add a touch bar button to open a new source when all the windows are closed. --- diff --git a/macosx/HBAppDelegate.m b/macosx/HBAppDelegate.m index e4d78e6fb..630fcb750 100644 --- a/macosx/HBAppDelegate.m +++ b/macosx/HBAppDelegate.m @@ -367,3 +367,39 @@ } @end + +@interface NSApplication (TouchBar) +@end + +@implementation NSApplication (TouchBar) + +static NSTouchBarItemIdentifier HBTouchBarMain = @"fr.handbrake.appDelegateTouchBar"; +static NSTouchBarItemIdentifier HBTouchBarOpen = @"fr.handbrake.openSource"; + +- (NSTouchBar *)makeTouchBar +{ + NSTouchBar *bar = [[NSTouchBar alloc] init]; + bar.delegate = self; + + bar.defaultItemIdentifiers = @[HBTouchBarOpen]; + + return bar; +} + +- (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier +{ + if ([identifier isEqualTo:HBTouchBarOpen]) + { + NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; + item.customizationLabel = NSLocalizedString(@"Open Source", @"Touch bar"); + + NSButton *button = [NSButton buttonWithTitle:NSLocalizedString(@"Open Source", @"Touch bar") target:nil action:@selector(browseSources:)]; + + item.view = button; + return item; + } + + return nil; +} + +@end