From f8462bd3b436028f40f4b52f55675d534a0d1d1c Mon Sep 17 00:00:00 2001 From: Yee Cheng Chin Date: Sun, 9 Oct 2022 13:20:47 -0700 Subject: [PATCH] Add File.Close support for terminal which also makes it work for Cmd-W Since Vim upstream added support for `:confirm q` for terminals, we can now get our File.Close menu to work properly for them as well. This also means Cmd-W (which is bound to that menu item) works too. Also just add validateMenuItem: for MMAppController even if we are just returning YES. This makes it semantically clearer and is easier to debug. --- runtime/menu.vim | 1 + src/MacVim/MMAppController.h | 13 ++++++++++++- src/MacVim/MMAppController.m | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/runtime/menu.vim b/runtime/menu.vim index b6a979434f..c8fd60e563 100644 --- a/runtime/menu.vim +++ b/runtime/menu.vim @@ -165,6 +165,7 @@ if has("gui_macvim") an 10.330 &File.Close\ Window:qa :conf qa tln 10.330 &File.Close\ Window:qa :conf qa an 10.332 &File.Close:q :conf q + tln 10.332 &File.Close:q :conf q an 10.341 &File.Save\ All :browse conf wa an 10.350 &File.Save\ As…:sav :browse confirm saveas else diff --git a/src/MacVim/MMAppController.h b/src/MacVim/MMAppController.h index f043fd1e4f..1e0782cbdd 100644 --- a/src/MacVim/MMAppController.h +++ b/src/MacVim/MMAppController.h @@ -20,7 +20,13 @@ #endif -@interface MMAppController : NSObject { +@interface MMAppController : NSObject < + MMAppProtocol, + NSUserInterfaceItemSearching +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 + , NSMenuItemValidation +#endif +> { NSConnection *connection; NSMutableArray *vimControllers; NSString *openSelectionString; @@ -63,6 +69,11 @@ - (void)refreshAllResizeConstraints; - (void)refreshAllTextViews; +// +// NSMenuItemValidation +// +- (BOOL)validateMenuItem:(NSMenuItem *)item; + - (IBAction)newWindow:(id)sender; - (IBAction)newWindowAndActivate:(id)sender; - (IBAction)fileOpen:(id)sender; diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 10bddcba3b..eda69bf161 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -1160,6 +1160,14 @@ fsEventCallback(ConstFSEventStreamRef streamRef, } } +- (BOOL)validateMenuItem:(NSMenuItem *)item +{ + // For the actions defined in this class we do want them to always be + // enabled since they are usually app functionality and independent of + // each Vim's state. + return YES; +} + - (IBAction)newWindow:(id)sender { ASLogDebug(@"Open new window");