diff --git a/src/MacVim/Base.lproj/Preferences.xib b/src/MacVim/Base.lproj/Preferences.xib index d9e24bfcda..228c305069 100644 --- a/src/MacVim/Base.lproj/Preferences.xib +++ b/src/MacVim/Base.lproj/Preferences.xib @@ -1,8 +1,8 @@ - + - + @@ -67,7 +67,6 @@ - @@ -180,7 +179,6 @@ - diff --git a/src/MacVim/MMAppController.h b/src/MacVim/MMAppController.h index d3e2fae121..a8acd9c219 100644 --- a/src/MacVim/MMAppController.h +++ b/src/MacVim/MMAppController.h @@ -49,6 +49,8 @@ int numChildProcesses; NSMutableDictionary *inputQueues; int processingFlag; + + BOOL hasShownWindowBefore; #if !DISABLE_SPARKLE #if USE_SPARKLE_1 diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 12e743f482..8e8af1c87e 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -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]); @@ -899,6 +897,8 @@ - (void)windowControllerWillOpen:(MMWindowController *)windowController [NSApp activateIgnoringOtherApps:YES]; shouldActivateWhenNextWindowOpens = NO; } + + hasShownWindowBefore = YES; } - (void)setMainMenu:(NSMenu *)mainMenu diff --git a/src/MacVim/MMPreferenceController.m b/src/MacVim/MMPreferenceController.m index e93540df16..a556626496 100644 --- a/src/MacVim/MMPreferenceController.m +++ b/src/MacVim/MMPreferenceController.m @@ -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];