From 899c2e3305592725d646f5acf3c21eaad13699c7 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Mon, 31 Jan 2011 08:07:22 +0000 Subject: Asking before closing window with multiple open tabs. svn path=/trunk/netsurf/; revision=11559 --- cocoa/BrowserWindowController.m | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'cocoa/BrowserWindowController.m') 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]) { -- cgit v1.2.3