diff --git a/cocoa/BrowserWindowController.m b/cocoa/BrowserWindowController.m index 4ed220015..f30607a8e 100644 --- a/cocoa/BrowserWindowController.m +++ b/cocoa/BrowserWindowController.m @@ -22,10 +22,18 @@ #import "PSMTabBarControl.h" #import "PSMRolloverButton.h" #import "URLFieldCell.h" +#import "cocoa/gui.h" #import "desktop/browser.h" #import "desktop/options.h" +@interface BrowserWindowController () + +- (void) canCloseAlertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo; + +@end + + @implementation BrowserWindowController @synthesize tabBar; @@ -99,6 +107,30 @@ } } +- (BOOL) windowShouldClose: (NSWindow *) window; +{ + if ([tabView numberOfTabViewItems] <= 1) return YES; + if ([[NSUserDefaults standardUserDefaults] boolForKey: kAlwaysCloseMultipleTabs]) return YES; + + NSAlert *ask = [NSAlert alertWithMessageText: @"Do you really want to close this window?" defaultButton:@"Yes" alternateButton:@"No" otherButton:nil + informativeTextWithFormat: @"There are %d tabs open, do you want to close them all?", [tabView numberOfTabViewItems]]; + [ask setShowsSuppressionButton:YES]; + + [ask beginSheetModalForWindow: window modalDelegate:self didEndSelector:@selector(canCloseAlertDidEnd:returnCode:contextInfo:) + contextInfo: NULL]; + + return NO; +} + +- (void) canCloseAlertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo; +{ + if (returnCode == NSOKButton) { + [[NSUserDefaults standardUserDefaults] setBool: [[alert suppressionButton] state] == NSOnState + forKey: kAlwaysCloseMultipleTabs]; + [[self window] close]; + } +} + - (void) windowWillClose: (NSNotification *)notification; { for (NSTabViewItem *tab in [tabView tabViewItems]) { diff --git a/cocoa/gui.h b/cocoa/gui.h index b4b78466e..413727fe6 100644 --- a/cocoa/gui.h +++ b/cocoa/gui.h @@ -24,5 +24,6 @@ extern NSString * const kHotlistFileOption; extern NSString * const kHomepageURLOption; extern NSString * const kOptionsFileOption; extern NSString * const kAlwaysCancelDownload; +extern NSString * const kAlwaysCloseMultipleTabs; void cocoa_autorelease( void ); diff --git a/cocoa/gui.m b/cocoa/gui.m index 9bb1bab36..d07d4f902 100644 --- a/cocoa/gui.m +++ b/cocoa/gui.m @@ -46,6 +46,7 @@ NSString * const kHotlistFileOption = @"Hotlist"; NSString * const kHomepageURLOption = @"HomepageURL"; NSString * const kOptionsFileOption = @"ClassicOptionsFile"; NSString * const kAlwaysCancelDownload = @"AlwaysCancelDownload"; +NSString * const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs"; #define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ )