dev.stuconnolly.com / svn / safaritabs

  1. /*
  2.  *  STBrowserWindowController.m
  3.  *
  4.  *  SafariTabs
  5.  *
  6.  *  Copyright (c) 2007 Stuart Connolly. All rights reserved.
  7.  *
  8.  *  This program is free software; you can redistribute it and/or
  9.  *  modify it under the terms of the GNU General Public License
  10.  *  as published by the Free Software Foundation; either version 2
  11.  *  of the License, or (at your option) any later version.
  12.  *
  13.  *  This program is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.  *  GNU General Public License for more details.
  17.  *
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with this program; if not, write to the Free Software
  20.  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  21.  */
  22.  
  23. #import "STBrowserWindowController.h"
  24. #import "STConstants.h"
  25.  
  26. @implementation BrowserWindowController (STBrowserWindowController)
  27.  
  28.  
  29. ////////////////////////////////////////////// *** _tc_windowShouldClose
  30.  
  31. - (BOOL)_tc_windowShouldClose:(id)sender
  32. {  
  33.     if ([[NSUserDefaults standardUserDefaults] boolForKey:STEnableCloseWindowWarning] == YES) {
  34.         if ([self moreThanOneTabShowing]) {
  35.             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:@""];
  36.        
  37.             [alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(tabWarningDidEnd:returnCode:contextInfo:) contextInfo:(void *)sender];
  38.        
  39.             return NO;
  40.         }
  41.     }
  42.  
  43.     return YES;
  44. }
  45.  
  46.  
  47. ////////////////////////////////////////////// *** tabWarningDidEnd
  48.  
  49. - (void)tabWarningDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo
  50. {
  51.     if (returnCode == NSAlertDefaultReturn) {
  52.         // We don't want the window being closed before the sheet is dismissed (disappears from view), so we call a method after half
  53.         // second to close the window.
  54.         [self performSelector:@selector(_tc_closeWindow) withObject:nil afterDelay:0.5];
  55.     }
  56. }
  57.  
  58.  
  59. ////////////////////////////////////////////// *** _tc_closeWindow
  60.  
  61. - (void)_tc_closeWindow
  62. {
  63.     [self close];
  64. }
  65.  
  66. @end