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 7722623 commit 2e87898
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
28 changes: 20 additions & 8 deletions src/MacVim/Base.lproj/Preferences.xib
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@
<point key="canvasLocation" x="137.5" y="-17"/>
</customView>
<customView id="hr4-G4-3ZG" userLabel="Appearance">
<rect key="frame" x="0.0" y="0.0" width="483" height="360"/>
<rect key="frame" x="0.0" y="0.0" width="483" height="379"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<customView id="fw0-VK-Nbz" userLabel="Dark mode selection">
<rect key="frame" x="19" y="182" width="433" height="156"/>
<rect key="frame" x="19" y="201" width="433" height="156"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="T40-Os-PUf" userLabel="Dark mode selection">
Expand Down Expand Up @@ -345,11 +345,11 @@
</subviews>
</customView>
<customView id="7af-iK-4r7" userLabel="Titlebar appearance">
<rect key="frame" x="19" y="118" width="433" height="56"/>
<rect key="frame" x="19" y="118" width="433" height="75"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="9Rk-gT-kVC" userLabel="Titlebar appearance">
<rect key="frame" x="-2" y="38" width="187" height="17"/>
<rect key="frame" x="-2" y="57" width="187" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="right" title="Window appearance:" id="HEH-Lo-v4I" userLabel="Titlebar appearance:">
<font key="font" metaFont="system"/>
Expand All @@ -358,7 +358,7 @@
</textFieldCell>
</textField>
<button id="7ie-0J-0Zr">
<rect key="frame" x="189" y="37" width="244" height="18"/>
<rect key="frame" x="189" y="56" width="244" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Transparent title bar" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="hzd-hj-Pth">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -370,7 +370,7 @@
</connections>
</button>
<button id="Hqh-Ql-2od">
<rect key="frame" x="189" y="19" width="244" height="18"/>
<rect key="frame" x="189" y="38" width="244" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Hidden title bar" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="W40-cB-m1U">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -381,8 +381,20 @@
<binding destination="58" name="value" keyPath="values.MMNoTitleBarWindow" id="CKL-mo-ZhZ"/>
</connections>
</button>
<button id="PoE-cf-3kL" userLabel="Show document icon at title bar">
<rect key="frame" x="189" y="19" width="244" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Show document icon at title bar" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="AvU-Lc-YNn" userLabel="Show document icon at title bar">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="appearanceChanged:" target="-2" id="e2x-W8-tpy"/>
<binding destination="58" name="value" keyPath="values.MMTitlebarShowsDocumentIcon" id="svp-gP-mdE"/>
</connections>
</button>
<button id="s2M-pj-U8e">
<rect key="frame" x="189" y="1" width="244" height="18"/>
<rect key="frame" x="189" y="-1" width="244" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="No drop shadows" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="VM8-tg-mVV">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand Down Expand Up @@ -496,7 +508,7 @@
</subviews>
</customView>
</subviews>
<point key="canvasLocation" x="137.5" y="435"/>
<point key="canvasLocation" x="137.5" y="444.5"/>
</customView>
<customView id="Bnq-Nx-GJH" userLabel="Input">
<rect key="frame" x="0.0" y="0.0" width="483" height="110"/>
Expand Down
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 2e87898

Please sign in to comment.