Skip to content

Commit

Permalink
Add setting for whether to show document icon at title bar
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ychin committed Nov 1, 2024
1 parent 5ca4161 commit b5d3c42
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 33 deletions.
66 changes: 39 additions & 27 deletions src/MacVim/Base.lproj/Preferences.xib

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/MacVim/MMWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 17 additions & 6 deletions src/MacVim/MMWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/Miscellaneous.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/Miscellaneous.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit b5d3c42

Please sign in to comment.