From b5d3c429e83d6a16e01ab97f405db6611ebbb87a Mon Sep 17 00:00:00 2001 From: Yee Cheng Chin Date: Fri, 1 Nov 2024 04:50:20 -0400 Subject: [PATCH] Add setting for whether to show document icon at title bar Don't automatically hide the icon while in transparent title bar mode, since it's a little confusing to the user. Instead, just use an extra setting for that. Also, when hiding the icon, properly hide it now by clearing it. Previously it was just making an invisible icon which was still draggable and didn't behave properly. Make sure after we set the setting it's refreshed correctly. Fix #1503 --- src/MacVim/Base.lproj/Preferences.xib | 66 ++++++++++++++++----------- src/MacVim/MMAppController.m | 1 + src/MacVim/MMWindowController.h | 2 + src/MacVim/MMWindowController.m | 23 +++++++--- src/MacVim/Miscellaneous.h | 1 + src/MacVim/Miscellaneous.m | 1 + 6 files changed, 61 insertions(+), 33 deletions(-) diff --git a/src/MacVim/Base.lproj/Preferences.xib b/src/MacVim/Base.lproj/Preferences.xib index ba62b25118..bbb29eef8c 100644 --- a/src/MacVim/Base.lproj/Preferences.xib +++ b/src/MacVim/Base.lproj/Preferences.xib @@ -31,7 +31,7 @@ - + @@ -76,7 +76,7 @@ - + @@ -117,7 +117,7 @@ - + @@ -139,7 +139,7 @@ - + @@ -155,7 +155,7 @@ - + @@ -169,7 +169,7 @@ - + @@ -201,7 +201,7 @@ - + @@ -227,7 +227,7 @@ - + @@ -276,14 +276,14 @@ - + - + - + @@ -328,7 +328,7 @@ - + @@ -341,11 +341,11 @@ - + - - + + @@ -354,7 +354,7 @@ + - + @@ -452,7 +464,7 @@ - + @@ -480,7 +492,7 @@ - + @@ -492,7 +504,7 @@ - + @@ -502,7 +514,7 @@ - + @@ -596,7 +608,7 @@ - + @@ -618,7 +630,7 @@ - + @@ -639,7 +651,7 @@ - + @@ -660,7 +672,7 @@ - + diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index f81128e712..4ca7055b9f 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -217,6 +217,7 @@ + (void)registerDefaults [NSNumber numberWithInt:0], MMAppearanceModeSelectionKey, [NSNumber numberWithBool:NO], MMNoTitleBarWindowKey, [NSNumber numberWithBool:NO], MMTitlebarAppearsTransparentKey, + [NSNumber numberWithBool:YES], MMTitlebarShowsDocumentIconKey, [NSNumber numberWithBool:NO], MMZoomBothKey, @"", MMLoginShellCommandKey, @"", MMLoginShellArgumentKey, diff --git a/src/MacVim/MMWindowController.h b/src/MacVim/MMWindowController.h index 6bae3ff145..6aa28e2852 100644 --- a/src/MacVim/MMWindowController.h +++ b/src/MacVim/MMWindowController.h @@ -42,6 +42,7 @@ NSRect preFullScreenFrame; MMWindow *decoratedWindow; NSString *lastSetTitle; + NSString *documentFilename; ///< File name of document being edited, used for the icon at the title bar. int userRows; int userCols; NSPoint userTopLeft; @@ -72,6 +73,7 @@ - (void)zoomWithRows:(int)rows columns:(int)cols state:(int)state; - (void)setTitle:(NSString *)title; - (void)setDocumentFilename:(NSString *)filename; +- (void)updateDocumentFilename; - (void)setToolbar:(NSToolbar *)toolbar; - (void)createScrollbarWithIdentifier:(int32_t)ident type:(int)type; - (BOOL)destroyScrollbarWithIdentifier:(int32_t)ident; diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index 6da87b00cf..454532be09 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -268,6 +268,7 @@ - (void)dealloc // in case processAfterWindowPresentedQueue wasn't called [afterWindowPresentedQueue release]; afterWindowPresentedQueue = nil; [lastSetTitle release]; lastSetTitle = nil; + [documentFilename release]; documentFilename = nil; [super dealloc]; } @@ -503,6 +504,8 @@ - (void)setTitle:(NSString *)title } } +/// Set the currently edited document's file path, passed in from Vim. Buffers with +/// no file paths will be passed in as empty strings. - (void)setDocumentFilename:(NSString *)filename { if (!filename) @@ -513,15 +516,22 @@ - (void)setDocumentFilename:(NSString *)filename if (![[NSFileManager defaultManager] fileExistsAtPath:filename]) filename = @""; + [filename retain]; + [documentFilename release]; + documentFilename = filename; + + [self updateDocumentFilename]; +} + +- (void)updateDocumentFilename +{ + if (documentFilename == nil) + return; + const bool showDocumentIcon = [[NSUserDefaults standardUserDefaults] boolForKey:MMTitlebarShowsDocumentIconKey]; + NSString *filename = showDocumentIcon ? documentFilename : @""; [decoratedWindow setRepresentedFilename:filename]; [fullScreenWindow setRepresentedFilename:filename]; - if ([[NSUserDefaults standardUserDefaults] boolForKey:MMTitlebarAppearsTransparentKey]) { - // Remove the draggable file icon in the title bar for a clean look - // when we are in transparent titlebar mode. - [[decoratedWindow standardWindowButton:NSWindowDocumentIconButton] setImage: nil]; - [[fullScreenWindow standardWindowButton:NSWindowDocumentIconButton] setImage: nil]; - } } - (void)setToolbar:(NSToolbar *)theToolbar @@ -613,6 +623,7 @@ - (void)refreshApperanceMode // Title may have been lost if we hid the title-bar. Reset it. [self setTitle:lastSetTitle]; + [self updateDocumentFilename]; // Dark mode only works on 10.14+ because that's when dark mode was // introduced. diff --git a/src/MacVim/Miscellaneous.h b/src/MacVim/Miscellaneous.h index c3a9367caf..33c2be980c 100644 --- a/src/MacVim/Miscellaneous.h +++ b/src/MacVim/Miscellaneous.h @@ -37,6 +37,7 @@ extern NSString *MMFontPreserveLineSpacingKey; extern NSString *MMAppearanceModeSelectionKey; extern NSString *MMNoTitleBarWindowKey; extern NSString *MMTitlebarAppearsTransparentKey; +extern NSString *MMTitlebarShowsDocumentIconKey; extern NSString *MMNoWindowShadowKey; extern NSString *MMDisableLaunchAnimationKey; extern NSString *MMLoginShellKey; diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m index 3ac5fcd9a3..98ffcd75f7 100644 --- a/src/MacVim/Miscellaneous.m +++ b/src/MacVim/Miscellaneous.m @@ -33,6 +33,7 @@ NSString *MMAppearanceModeSelectionKey = @"MMAppearanceModeSelection"; NSString *MMNoTitleBarWindowKey = @"MMNoTitleBarWindow"; NSString *MMTitlebarAppearsTransparentKey = @"MMTitlebarAppearsTransparent"; +NSString *MMTitlebarShowsDocumentIconKey = @"MMTitlebarShowsDocumentIcon"; NSString *MMNoWindowShadowKey = @"MMNoWindowShadow"; NSString *MMDisableLaunchAnimationKey = @"MMDisableLaunchAnimation"; NSString *MMLoginShellKey = @"MMLoginShell";