/*
* STAppController.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 "STAppController.h"
#import "STSafariPlugin.h"
#import "BrowserWindowController.h"
#import "STConstants.h"
@implementation AppController (STAppController)
////////////////////////////////////////////// *** _tc_applicationShouldTerminate
- (NSApplicationTerminateReply)_st_applicationShouldTerminate:(id)sender;
{
if ([[NSUserDefaults standardUserDefaults
] boolForKey
:STEnableQuitSafariWarning
] == YES) {
// If terminateWithoutWarning is YES then there is no need to continue, just terminate Safari without a warning regardless.
if ([[STSafariPlugin sharedInstance] terminateWithoutWarning]) {
return NSTerminateNow;
}
int tabCount;
id document;
while(document = [e nextObject]) {
BrowserWindowController *windowController = [[document windowControllers] objectAtIndex:0];
tabCount = [[windowController orderedTabs] count];
}
if (([windows count] == 0) || ([windows count] == 1) && (tabCount == 1)) {
return NSTerminateNow;
}
else if ([windows count] > 1) {
message
= [NSString stringWithFormat
:@"You currently have %d windows open. Are you sure you want quit?",
[windows count
]];
}
else if (([windows count] == 1) && (tabCount > 1)) {
message
= [NSString stringWithFormat
:@"You currently have %d tabs open. Are you sure you want quit?", tabCount
];
}
NSAlert *alert
= [NSAlert alertWithMessageText
:message defaultButton
:@"Quit" alternateButton
:@"Cancel" otherButton
:nil informativeTextWithFormat
:@""];
if ([alert runModal] == NSAlertAlternateReturn) {
return NSTerminateCancel;
}
}
return NSTerminateNow;
}
@end