diff --git a/src/MacVim/Base.lproj/Preferences.xib b/src/MacVim/Base.lproj/Preferences.xib
index e1c521a09a..54e83955d9 100644
--- a/src/MacVim/Base.lproj/Preferences.xib
+++ b/src/MacVim/Base.lproj/Preferences.xib
@@ -280,11 +280,11 @@
-
+
-
+
@@ -345,11 +345,11 @@
-
+
-
+
@@ -358,7 +358,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..0ea422a7a1 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;
@@ -57,6 +58,7 @@
- (id)initWithVimController:(MMVimController *)controller;
- (MMVimController *)vimController;
- (MMVimView *)vimView;
+- (NSWindow *)window;
- (NSString *)windowAutosaveKey;
- (void)setWindowAutosaveKey:(NSString *)key;
- (void)cleanup;
@@ -72,6 +74,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..3d334fcfcd 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];
}
@@ -290,6 +291,11 @@ - (MMVimView *)vimView
return vimView;
}
+- (NSWindow *)window
+{
+ return decoratedWindow;
+}
+
- (NSString *)windowAutosaveKey
{
return windowAutosaveKey;
@@ -503,6 +509,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 +521,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 +628,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/MacVimTests/MacVimTests.m b/src/MacVim/MacVimTests/MacVimTests.m
index f74f8a7356..04a29f6cd8 100644
--- a/src/MacVim/MacVimTests/MacVimTests.m
+++ b/src/MacVim/MacVimTests/MacVimTests.m
@@ -458,4 +458,52 @@ - (void) testGuifontSystemMonospace {
[self waitForVimClose];
}
+/// Test that document icon is shown in title bar when enabled.
+- (void) testTitlebarDocumentIcon {
+ MMAppController *app = MMAppController.sharedInstance;
+
+ [app openNewWindow:NewWindowClean activate:YES];
+ [self waitForVimOpenAndMessages];
+
+ NSWindow *win = [[[app keyVimController] windowController] window];
+
+ // Untitled documents have no icons
+ XCTAssertEqualObjects(@"", win.representedFilename);
+
+ // Test that the document icon is shown when a file (gui_mac.txt) is opened by querying "representedFilename"
+ [self sendStringToVim:@":help macvim\n" withMods:0];
+ [self waitForEventHandlingAndVimProcess];
+ NSString *gui_mac_path = [[NSBundle mainBundle] pathForResource:@"gui_mac.txt" ofType:nil inDirectory:@"vim/runtime/doc"];
+ XCTAssertEqualObjects(gui_mac_path, win.representedFilename);
+
+ // Change setting to hide the document icon
+ NSUserDefaults *ud = NSUserDefaults.standardUserDefaults;
+ NSDictionary *defaults = [ud volatileDomainForName:NSArgumentDomain];
+ NSMutableDictionary *newDefaults = [defaults mutableCopy];
+ newDefaults[MMTitlebarShowsDocumentIconKey] = @NO;
+ [ud setVolatileDomain:newDefaults forName:NSArgumentDomain];
+
+ // Test that there is no document icon shown
+ [app refreshAllAppearances];
+ XCTAssertEqualObjects(@"", win.representedFilename);
+
+ // Change setting back to show the document icon. Test that the path was remembered and icon is shown.
+ newDefaults[MMTitlebarShowsDocumentIconKey] = @YES;
+ [ud setVolatileDomain:newDefaults forName:NSArgumentDomain];
+ [app refreshAllAppearances];
+ XCTAssertEqualObjects(gui_mac_path, win.representedFilename);
+
+ // Close the file to go back to untitled document and make sure no icon is shown
+ [self sendStringToVim:@":q\n" withMods:0];
+ [self waitForEventHandlingAndVimProcess];
+ XCTAssertEqualObjects(@"", win.representedFilename);
+
+ // Restore settings to test defaults
+ [ud setVolatileDomain:defaults forName:NSArgumentDomain];
+
+ // Clean up
+ [[app keyVimController] sendMessage:VimShouldCloseMsgID data:nil];
+ [self waitForVimClose];
+}
+
@end
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";