/*
* $Id: STAppController.m 206 2010-01-30 22:43:48Z stuart $
*
* SafariTabs
* http://stuconnolly.com/projects/safaritabs/
*
* Copyright (c) 2010 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#import "STAppController.h"
#import "STSafariPlugin.h"
#import "STSessionHandler.h"
#import "STSafariPluginHandler.h"
#import "BrowserDocument.h"
#import "STBrowserWindowController.h"
#import "STUtilities.h"
#import "STConstants.h"
@interface STAppController (DeclaredAPI)
- (NSApplicationTerminateReply)safari_applicationShouldTerminate:(id)sender;
@end
@implementation STAppController
/*!
* This is the re-implementation of Safari's swizzled applicationShouldTerminate: method. If specified in the
* user's preferences then the currently open tabs will be saved.
*
* @param sender The object calling the method (instance of NSApplication)
*
* @return An integer (one of NSApplicationTerminateReply constants) indicating whether the application should
* terminate.
*/
- (NSApplicationTerminateReply)st_applicationShouldTerminate:(id)sender
{
NSMenuItem *privateBrowsingMenuItem
= [[[[NSApp mainMenu
] itemAtIndex
:0] submenu
] itemAtIndex
:7];
// If required save the currently open tabs
if (([[NSUserDefaults standardUserDefaults
] integerForKey
:STTabRestoreQuitAction
] == 0) && ([privateBrowsingMenuItem state
] != NSOnState
)) {
[[[STSafariPluginHandler sharedInstance] sessionHandler] saveOpenTabs];
}
return [self safari_applicationShouldTerminate:sender];
}
/*!
* This is the re-implementation of Safari's swizzled application:OpenFile: method.
*/
{
STSessionHandler *sessionHandler = [[STSafariPluginHandler sharedInstance] sessionHandler];
// Safari's attempting to open a file, so don't overwrite the first window
[sessionHandler setIsFirstWindow:NO];
[sessionHandler setLaunchedViaURLEvent:YES];
return [self safari_application:application openFile:filename];
}
/*!
* This is the re-implementation of Safari's swizzled handleURLEvent:withReplyEvent: method.
*/
{
STSessionHandler *sessionHandler = [[STSafariPluginHandler sharedInstance] sessionHandler];
// Safari's attempting to open a URL passed in from an event, so don't overwrite the first window
[sessionHandler setIsFirstWindow:NO];
[sessionHandler setLaunchedViaURLEvent:YES];
[self safari_handleURLEvent:event withReplyEvent:reply];
}
@end