From 05acbff09c6f74801997fcc3df507186d855232e Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Wed, 16 Sep 2020 11:08:01 +0300 Subject: macOS: Changing sidebar modes via touch bar --- src/macos.m | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/macos.m b/src/macos.m index 6f833e12..b000fed9 100644 --- a/src/macos.m +++ b/src/macos.m @@ -28,10 +28,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #import -static NSTouchBarItemIdentifier goBack_TouchId_ = @"fi.skyjake.Lagrange.back"; -static NSTouchBarItemIdentifier goForward_TouchId_ = @"fi.skyjake.Lagrange.forward"; -static NSTouchBarItemIdentifier find_TouchId_ = @"fi.skyjake.Lagrange.find"; -static NSTouchBarItemIdentifier newTab_TouchId_ = @"fi.skyjake.Lagrange.tabs.new"; +static NSTouchBarItemIdentifier goBack_TouchId_ = @"fi.skyjake.Lagrange.back"; +static NSTouchBarItemIdentifier goForward_TouchId_ = @"fi.skyjake.Lagrange.forward"; +static NSTouchBarItemIdentifier find_TouchId_ = @"fi.skyjake.Lagrange.find"; +static NSTouchBarItemIdentifier newTab_TouchId_ = @"fi.skyjake.Lagrange.tabs.new"; +static NSTouchBarItemIdentifier sidebarMode_TouchId_ = @"fi.skyjake.Lagrange.sidebar.mode"; enum iTouchBarVariant { default_TouchBarVariant, @@ -205,6 +206,8 @@ static void appearanceChanged_MacOS_(NSString *name) { NSTouchBarItemIdentifierFixedSpaceSmall, find_TouchId_, NSTouchBarItemIdentifierFlexibleSpace, + sidebarMode_TouchId_, + NSTouchBarItemIdentifierFlexibleSpace, newTab_TouchId_, NSTouchBarItemIdentifierOtherItemsProxy ]; break; @@ -228,6 +231,11 @@ static void appearanceChanged_MacOS_(NSString *name) { } } +- (void)sidebarModePressed:(id)sender { + NSSegmentedControl *seg = sender; + postCommandf_App("sidebar.mode arg:%d toggle:1", (int) [seg selectedSegment]); +} + - (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { iUnused(touchBar); @@ -249,6 +257,16 @@ static void appearanceChanged_MacOS_(NSString *name) { widget:nil command:@"focus.set id:find.input"]; } + else if ([identifier isEqualToString:sidebarMode_TouchId_]) { + NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:sidebarMode_TouchId_]; + NSSegmentedControl *seg = + [NSSegmentedControl segmentedControlWithLabels:@[ @"Bookmarks", @"History", @"Identities", @"Outline"] + trackingMode:NSSegmentSwitchTrackingMomentary + target:[[NSApplication sharedApplication] delegate] + action:@selector(sidebarModePressed:)]; + item.view = seg; + return item; + } else if ([identifier isEqualToString:newTab_TouchId_]) { return [[CommandButton alloc] initWithIdentifier:identifier image:[NSImage imageNamed:NSImageNameTouchBarAddTemplate] -- cgit v1.2.3