/*
* STBrowserWindowController.m
*
* SafariTabs
*
* Copyright (c) 2007 Stuart Connolly. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#import "STBrowserWindowController.h"
#import "STConstants.h"
@implementation BrowserWindowController (STBrowserWindowController)
////////////////////////////////////////////// *** _tc_windowShouldClose
- (BOOL)_tc_windowShouldClose:(id)sender
{
if ([[NSUserDefaults standardUserDefaults
] boolForKey
:STEnableCloseWindowWarning
] == YES) {
if ([self moreThanOneTabShowing]) {
NSAlert *alert
= [NSAlert alertWithMessageText
:[NSString stringWithFormat
:@"You currently have %d tabs open. Are you sure you want to close them?",
[[self orderedTabs
] count
]] defaultButton
:@"Close Tabs" alternateButton
:@"Cancel" otherButton
:nil informativeTextWithFormat
:@""];
[alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(tabWarningDidEnd:returnCode:contextInfo:) contextInfo:(void *)sender];
return NO;
}
}
return YES;
}
////////////////////////////////////////////// *** tabWarningDidEnd
- (void)tabWarningDidEnd
:(NSAlert *)alert returnCode
:(int)returnCode contextInfo
:(void *)contextInfo
{
if (returnCode == NSAlertDefaultReturn) {
// We don't want the window being closed before the sheet is dismissed (disappears from view), so we call a method after half
// second to close the window.
[self performSelector:@selector(_tc_closeWindow) withObject:nil afterDelay:0.5];
}
}
////////////////////////////////////////////// *** _tc_closeWindow
- (void)_tc_closeWindow
{
[self close];
}
@end