diff --git a/src/MacVim/Base.lproj/Preferences.xib b/src/MacVim/Base.lproj/Preferences.xib index 70e38fe872..84216c9283 100644 --- a/src/MacVim/Base.lproj/Preferences.xib +++ b/src/MacVim/Base.lproj/Preferences.xib @@ -1,8 +1,8 @@ - + - + @@ -63,6 +63,7 @@ + @@ -175,6 +176,7 @@ + diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 8a70dec11f..78361af670 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -529,6 +529,17 @@ - (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; + } + return (MMTerminateWhenLastWindowClosed == [[NSUserDefaults standardUserDefaults] integerForKey:MMLastWindowClosedBehaviorKey]); diff --git a/src/MacVim/MMPreferenceController.m b/src/MacVim/MMPreferenceController.m index ac63f2751b..a5078987fa 100644 --- a/src/MacVim/MMPreferenceController.m +++ b/src/MacVim/MMPreferenceController.m @@ -133,4 +133,34 @@ - (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]; + } + } +} + @end