summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Weidauer <sven.weidauer@gmail.com>2011-01-31 08:07:22 +0000
committerSven Weidauer <sven.weidauer@gmail.com>2011-01-31 08:07:22 +0000
commit899c2e3305592725d646f5acf3c21eaad13699c7 (patch)
tree740afbfd9bd744068f7c958a765359b36b70e15f
parentfd23621211e814d86da1a12bf0f5a20368d4c037 (diff)
downloadnetsurf-899c2e3305592725d646f5acf3c21eaad13699c7.tar.gz
netsurf-899c2e3305592725d646f5acf3c21eaad13699c7.tar.bz2
Asking before closing window with multiple open tabs.
svn path=/trunk/netsurf/; revision=11559
-rw-r--r--cocoa/BrowserWindowController.m32
-rw-r--r--cocoa/gui.h1
-rw-r--r--cocoa/gui.m1
3 files changed, 34 insertions, 0 deletions
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__ )