Skip to content

Allow never opening window + terminate on last window, with guards #1339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/MacVim/Base.lproj/Preferences.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="17701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment version="1090" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -67,7 +67,6 @@
</column>
</cells>
<connections>
<action selector="openUntitledWindowChanged:" target="-2" id="S8l-uX-tEl"/>
<binding destination="58" name="selectedTag" keyPath="values.MMUntitledWindow" id="171"/>
</connections>
</matrix>
Expand Down Expand Up @@ -180,7 +179,6 @@
</menu>
</popUpButtonCell>
<connections>
<action selector="lastWindowClosedChanged:" target="-2" id="IcT-7v-gxr"/>
<binding destination="58" name="selectedIndex" keyPath="values.MMLastWindowClosedBehavior" id="968"/>
</connections>
</popUpButton>
Expand Down
2 changes: 2 additions & 0 deletions src/MacVim/MMAppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
int numChildProcesses;
NSMutableDictionary *inputQueues;
int processingFlag;

BOOL hasShownWindowBefore;

#if !DISABLE_SPARKLE
#if USE_SPARKLE_1
Expand Down
20 changes: 10 additions & 10 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -548,17 +548,15 @@ - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
if (MMUntitledWindowNever ==
[[NSUserDefaults standardUserDefaults]
integerForKey:MMUntitledWindowKey]) {
// Sanity protection: If we never open a new window on application launch, there could
// be an issue here where we immediately terminate MacVim. Because of that, we always
// return false regardless of what MMLastWindowClosedBehavior is. Note that the user
// should not be able to set these two conflicting options together in the preference pane
// but it's possible to do so in the terminal by calling "defaults" manually.
return false;
if (!hasShownWindowBefore) {
// If we have not opened a window before, never return YES. This can
// happen when MacVim is not configured to open window at launch. We
// want to give the user a chance to open a window first. Otherwise
// just opening the About MacVim or Settings windows could immediately
// terminate the app (since those are not proper app windows),
// depending if the OS feels like invoking this method.
return NO;
}

return (MMTerminateWhenLastWindowClosed ==
[[NSUserDefaults standardUserDefaults]
integerForKey:MMLastWindowClosedBehaviorKey]);
Expand Down Expand Up @@ -899,6 +897,8 @@ - (void)windowControllerWillOpen:(MMWindowController *)windowController
[NSApp activateIgnoringOtherApps:YES];
shouldActivateWhenNextWindowOpens = NO;
}

hasShownWindowBefore = YES;
}

- (void)setMainMenu:(NSMenu *)mainMenu
Expand Down
30 changes: 0 additions & 30 deletions src/MacVim/MMPreferenceController.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,36 +167,6 @@ - (IBAction)fontPropertiesChanged:(id)sender
[[MMAppController sharedInstance] refreshAllFonts];
}

-(IBAction)lastWindowClosedChanged:(id)sender
{
// Sanity checking for terminate when last window closed + not opening an untitled window.
// This results in a potentially awkward situation wehre MacVim will close itself since it
// doesn't have any window opened when launched.
// Note that the potentially bad behavior is already protected against for in applicationShouldTerminateAfterLastWindowClosed:,
// but this sanity checking is to make sure the user can see that in an explicit fashion.
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if ([defaults integerForKey:MMLastWindowClosedBehaviorKey] == MMTerminateWhenLastWindowClosed) {
if ([defaults integerForKey:MMUntitledWindowKey] == MMUntitledWindowNever) {
[defaults setInteger:MMUntitledWindowOnOpen forKey:MMUntitledWindowKey];
}
}
}

-(IBAction)openUntitledWindowChanged:(id)sender
{
// Sanity checking for terminate when last window closed + not opening an untitled window.
// This results in a potentially awkward situation wehre MacVim will close itself since it
// doesn't have any window opened when launched.
// Note that the potentially bad behavior is already protected against for in applicationShouldTerminateAfterLastWindowClosed:,
// but this sanity checking is to make sure the user can see that in an explicit fashion.
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if ([defaults integerForKey:MMLastWindowClosedBehaviorKey] == MMTerminateWhenLastWindowClosed) {
if ([defaults integerForKey:MMUntitledWindowKey] == MMUntitledWindowNever) {
[defaults setInteger:MMHideWhenLastWindowClosed forKey:MMLastWindowClosedBehaviorKey];
}
}
}

- (IBAction)smoothResizeChanged:(id)sender
{
[[MMAppController sharedInstance] refreshAllResizeConstraints];
Expand Down