/*
* 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"
#import "BrowserDocument.h"
#import <WebKit/WebKit.h>
@implementation BrowserWindowController (STBrowserWindowController)
////////////////////////////////////////////// *** _st_windowShouldClose
- (BOOL)_st_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;
}
////////////////////////////////////////////// *** _st_createTab
- (id)_st_createTab
{
NSURL *currentURL
= [[self browserDocument
] currentURL
];
id tab = [self _safari_createTab];
int option
= [[NSUserDefaults standardUserDefaults
] integerForKey
:STNewTabsLoadOption
];
if (option == 1) {
[self goHome:self];
}
else if (option == 2) {
[[tab mainFrame
] loadRequest
:[NSURLRequest requestWithURL
:currentURL
]];
}
return tab;
}
////////////////////////////////////////////// *** 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(_st_closeWindow) withObject:nil afterDelay:0.5];
}
}
////////////////////////////////////////////// *** _tc_closeWindow
- (void)_st_closeWindow
{
[self close];
}
@end