Asking before closing window with multiple open tabs.

svn path=/trunk/netsurf/; revision=11559
This commit is contained in:
Sven Weidauer 2011-01-31 08:07:22 +00:00
parent fd23621211
commit 899c2e3305
3 changed files with 34 additions and 0 deletions

View File

@ -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]) {

View File

@ -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 );

View File

@ -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__ )