Revision: 14953
          http://sourceforge.net/p/skim-app/code/14953
Author:   hofman
Date:     2025-03-09 18:46:38 +0000 (Sun, 09 Mar 2025)
Log Message:
-----------
Add option for hidden pref to move either the tab bar or the toolbar in the 
title bar, hiding the title when the tab bar is visible, for a very compact 
title bar.

Modified Paths:
--------------
    trunk/SKMainWindow.m
    trunk/SKMainWindowController.m

Modified: trunk/SKMainWindow.m
===================================================================
--- trunk/SKMainWindow.m        2025-03-07 22:52:16 UTC (rev 14952)
+++ trunk/SKMainWindow.m        2025-03-09 18:46:38 UTC (rev 14953)
@@ -122,12 +122,54 @@
     [super setDelegate:newDelegate];
 }
 
+- (void)setTabBarLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
+    NSTitlebarAccessoryViewController *tabBarController = [[self 
titlebarAccessoryViewControllers] firstObject];
+    if (tabBarController && [tabBarController layoutAttribute] != 
layoutAttribute) {
+        [super removeTitlebarAccessoryViewControllerAtIndex:0];
+        [tabBarController setLayoutAttribute:layoutAttribute];
+        [super addTitlebarAccessoryViewController:tabBarController];
+    }
+}
+
 - (void)toggleToolbarShown:(id)sender {
     if (@available(macOS 11.0, *)) {
-        if ([[NSUserDefaults standardUserDefaults] 
integerForKey:SKToolbarPlacementKey] > 2)
-            [self setTitleVisibility:[[self toolbar] isVisible] ? 
NSWindowTitleVisible : NSWindowTitleHidden];
+        NSInteger placement = [[NSUserDefaults standardUserDefaults] 
integerForKey:SKToolbarPlacementKey];
+        if (placement == 1) {
+            NSLayoutAttribute layoutAttribute = [[self toolbar] isVisible] ? 
NSLayoutAttributeTop : NSLayoutAttributeBottom;
+            for (SKMainWindow *window in [self tabbedWindows] ?: @[self])
+                [window setTabBarLayoutAttribute:layoutAttribute];
+        } else if (placement > 3) {
+            NSWindowTitleVisibility visibility = [[self toolbar] isVisible] ? 
NSWindowTitleVisible : NSWindowTitleHidden;
+            for (NSWindow *window in [self tabbedWindows] ?: @[self])
+                [window setTitleVisibility:visibility];
+        }
     }
     [super toggleToolbarShown:sender];
 }
 
+- (void)addTitlebarAccessoryViewController:(NSTitlebarAccessoryViewController 
*)childViewController {
+    if (@available(macOS 11.0, *)) {
+        if ([[NSUserDefaults standardUserDefaults] 
integerForKey:SKToolbarPlacementKey] == 1 && [[self toolbar] isVisible] == NO) {
+            [childViewController setLayoutAttribute:NSLayoutAttributeTop];
+            [self setTitleVisibility:NSWindowTitleHidden];
+            NSURL *url = [self representedURL];
+            [self setRepresentedURL:nil];
+            [self setRepresentedURL:url];
+        }
+    }
+    [super addTitlebarAccessoryViewController:childViewController];
+}
+
+- (void)removeTitlebarAccessoryViewControllerAtIndex:(NSInteger)index {
+    [super removeTitlebarAccessoryViewControllerAtIndex:index];
+    if (@available(macOS 11.0, *)) {
+        if ([[NSUserDefaults standardUserDefaults] 
integerForKey:SKToolbarPlacementKey] == 1 && [[self toolbar] isVisible] == NO) {
+            [self setTitleVisibility:NSWindowTitleVisible];
+            NSURL *url = [self representedURL];
+            [self setRepresentedURL:nil];
+            [self setRepresentedURL:url];
+        }
+    }
+}
+
 @end

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2025-03-07 22:52:16 UTC (rev 14952)
+++ trunk/SKMainWindowController.m      2025-03-09 18:46:38 UTC (rev 14953)
@@ -330,10 +330,10 @@
     
     if (@available(macOS 11.0, *)) {
         // hidden pref for toolbar position relative to title:
-        // 0 = below, 1 = beside, 2 = beside compact, 3 = replacing, 4 = 
replacing compact
+        // 0 = below, 1 = compact, 2 = beside, 3 = beside compact, 4 = 
replacing, 5 = replacing compact
         NSInteger placement = [[NSUserDefaults standardUserDefaults] 
integerForKey:SKToolbarPlacementKey];
-        [window setToolbarStyle:placement == 0 ? NSWindowToolbarStyleExpanded 
: (placement % 2) ? NSWindowToolbarStyleUnified : 
NSWindowToolbarStyleUnifiedCompact];
-        if (placement > 2 && [[window toolbar] isVisible])
+        [window setToolbarStyle:placement == 0 ? NSWindowToolbarStyleExpanded 
: (placement & 1) ? NSWindowToolbarStyleUnifiedCompact : 
NSWindowToolbarStyleUnified];
+        if (placement > 3 && [[window toolbar] isVisible])
             [window setTitleVisibility:NSWindowTitleHidden];
     }
     

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to