Skip to content

Commit 89c1ea2

Browse files
authored
Merge pull request #1339 from ychin/allow-untitled-window-never-terminate-window-again
Allow never opening window + terminate on last window, with guards
2 parents b64e13c + cabb495 commit 89c1ea2

4 files changed

Lines changed: 14 additions & 44 deletions

File tree

src/MacVim/Base.lproj/Preferences.xib

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
33
<dependencies>
44
<deployment version="1090" identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
66
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
77
</dependencies>
88
<objects>
@@ -67,7 +67,6 @@
6767
</column>
6868
</cells>
6969
<connections>
70-
<action selector="openUntitledWindowChanged:" target="-2" id="S8l-uX-tEl"/>
7170
<binding destination="58" name="selectedTag" keyPath="values.MMUntitledWindow" id="171"/>
7271
</connections>
7372
</matrix>
@@ -180,7 +179,6 @@
180179
</menu>
181180
</popUpButtonCell>
182181
<connections>
183-
<action selector="lastWindowClosedChanged:" target="-2" id="IcT-7v-gxr"/>
184182
<binding destination="58" name="selectedIndex" keyPath="values.MMLastWindowClosedBehavior" id="968"/>
185183
</connections>
186184
</popUpButton>

src/MacVim/MMAppController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
int numChildProcesses;
5050
NSMutableDictionary *inputQueues;
5151
int processingFlag;
52+
53+
BOOL hasShownWindowBefore;
5254

5355
#if !DISABLE_SPARKLE
5456
#if USE_SPARKLE_1

src/MacVim/MMAppController.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -548,17 +548,15 @@ - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
548548

549549
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
550550
{
551-
if (MMUntitledWindowNever ==
552-
[[NSUserDefaults standardUserDefaults]
553-
integerForKey:MMUntitledWindowKey]) {
554-
// Sanity protection: If we never open a new window on application launch, there could
555-
// be an issue here where we immediately terminate MacVim. Because of that, we always
556-
// return false regardless of what MMLastWindowClosedBehavior is. Note that the user
557-
// should not be able to set these two conflicting options together in the preference pane
558-
// but it's possible to do so in the terminal by calling "defaults" manually.
559-
return false;
551+
if (!hasShownWindowBefore) {
552+
// If we have not opened a window before, never return YES. This can
553+
// happen when MacVim is not configured to open window at launch. We
554+
// want to give the user a chance to open a window first. Otherwise
555+
// just opening the About MacVim or Settings windows could immediately
556+
// terminate the app (since those are not proper app windows),
557+
// depending if the OS feels like invoking this method.
558+
return NO;
560559
}
561-
562560
return (MMTerminateWhenLastWindowClosed ==
563561
[[NSUserDefaults standardUserDefaults]
564562
integerForKey:MMLastWindowClosedBehaviorKey]);
@@ -899,6 +897,8 @@ - (void)windowControllerWillOpen:(MMWindowController *)windowController
899897
[NSApp activateIgnoringOtherApps:YES];
900898
shouldActivateWhenNextWindowOpens = NO;
901899
}
900+
901+
hasShownWindowBefore = YES;
902902
}
903903

904904
- (void)setMainMenu:(NSMenu *)mainMenu

src/MacVim/MMPreferenceController.m

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -167,36 +167,6 @@ - (IBAction)fontPropertiesChanged:(id)sender
167167
[[MMAppController sharedInstance] refreshAllFonts];
168168
}
169169

170-
-(IBAction)lastWindowClosedChanged:(id)sender
171-
{
172-
// Sanity checking for terminate when last window closed + not opening an untitled window.
173-
// This results in a potentially awkward situation wehre MacVim will close itself since it
174-
// doesn't have any window opened when launched.
175-
// Note that the potentially bad behavior is already protected against for in applicationShouldTerminateAfterLastWindowClosed:,
176-
// but this sanity checking is to make sure the user can see that in an explicit fashion.
177-
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
178-
if ([defaults integerForKey:MMLastWindowClosedBehaviorKey] == MMTerminateWhenLastWindowClosed) {
179-
if ([defaults integerForKey:MMUntitledWindowKey] == MMUntitledWindowNever) {
180-
[defaults setInteger:MMUntitledWindowOnOpen forKey:MMUntitledWindowKey];
181-
}
182-
}
183-
}
184-
185-
-(IBAction)openUntitledWindowChanged:(id)sender
186-
{
187-
// Sanity checking for terminate when last window closed + not opening an untitled window.
188-
// This results in a potentially awkward situation wehre MacVim will close itself since it
189-
// doesn't have any window opened when launched.
190-
// Note that the potentially bad behavior is already protected against for in applicationShouldTerminateAfterLastWindowClosed:,
191-
// but this sanity checking is to make sure the user can see that in an explicit fashion.
192-
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
193-
if ([defaults integerForKey:MMLastWindowClosedBehaviorKey] == MMTerminateWhenLastWindowClosed) {
194-
if ([defaults integerForKey:MMUntitledWindowKey] == MMUntitledWindowNever) {
195-
[defaults setInteger:MMHideWhenLastWindowClosed forKey:MMLastWindowClosedBehaviorKey];
196-
}
197-
}
198-
}
199-
200170
- (IBAction)smoothResizeChanged:(id)sender
201171
{
202172
[[MMAppController sharedInstance] refreshAllResizeConstraints];

0 commit comments

Comments
 (0)