From 4475ff63b6dcf61cc90d8667d070022b18654b6e Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Thu, 13 Dec 2018 13:23:34 +0100 Subject: [PATCH] MacGui: add a touch bar button to open a new source when all the windows are closed. --- macosx/HBAppDelegate.m | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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 -- 2.40.0