From 899152db491c640c5f3839bec1cdd73c9b03551c Mon Sep 17 00:00:00 2001 From: Dzmitry Neviadomski Date: Sun, 7 Feb 2021 01:12:19 +0300 Subject: [PATCH] Add ability to change toolbar style. Fixes #86 --- Application/AppController.h | 1 + Application/AppController.m | 30 +++++++++++++++++++++++++++++- Base.lproj/MainMenu.xib | 6 ++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Application/AppController.h b/Application/AppController.h index 822ba071b..275b7295e 100644 --- a/Application/AppController.h +++ b/Application/AppController.h @@ -102,6 +102,7 @@ - (void)windowDidExitFullScreen:(NSNotification *)notification; - (IBAction)toggleMiniMode:(id)sender; +- (IBAction)toggleToolbarStyle:(id)sender; @property BOOL miniMode; diff --git a/Application/AppController.m b/Application/AppController.m index 31e6f00f8..9c21ef211 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -22,7 +22,9 @@ #import #import "Shortcuts.h" -@implementation AppController +@implementation AppController { + BOOL _isFullToolbarStyle; +} + (void)initialize { @@ -175,6 +177,8 @@ // Restore mini mode [self setMiniMode:[[NSUserDefaults standardUserDefaults] boolForKey:@"miniMode"]]; + [self setToolbarStyle:[[NSUserDefaults standardUserDefaults] boolForKey:@"toolbarStyleFull"]]; + // We need file tree view to restore its state here // so attempt to access file tree view controller's root view // to force it to read nib and create file tree view for us @@ -549,4 +553,28 @@ [windowToShow makeKeyAndOrderFront:self]; } +- (IBAction)toggleToolbarStyle:(id)sender { + [self setToolbarStyle:!_isFullToolbarStyle]; +} + +- (void)setToolbarStyle:(BOOL)full { + _isFullToolbarStyle = full; + [[NSUserDefaults standardUserDefaults] setBool:full forKey:@"toolbarStyleFull"]; + DLog("Changed toolbar style: %@", (full ? @"full" : @"compact")); + + if (@available(macOS 11.0, *)) { + NSWindowToolbarStyle style = + full ? NSWindowToolbarStyleExpanded : NSWindowToolbarStyleUnifiedCompact; + mainWindow.toolbarStyle = style; + miniWindow.toolbarStyle = style; + } + + NSWindowTitleVisibility visibility = full ? NSWindowTitleVisible : NSWindowTitleHidden; + mainWindow.titleVisibility = visibility; + miniWindow.titleVisibility = visibility; + + // Fix empty area after changing toolbar style in mini window as it has no content view + [miniWindow setContentSize:NSMakeSize(miniWindow.frame.size.width, 0)]; +} + @end diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index 26ddc4cf5..641682298 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -978,6 +978,12 @@ + + + + + +