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.  
  25. @implementation BrowserWindowController (STBrowserWindowController)
  26.  
  27.  
  28. ////////////////////////////////////////////// *** _tc_windowShouldClose
  29.  
  30. - (BOOL)_tc_windowShouldClose:(id)sender
  31. {  
  32.     if ([self moreThanOneTabShowing]) {
  33.         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:@""];
  34.        
  35.         [alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(tabWarningDidEnd:returnCode:contextInfo:) contextInfo:(void *)sender];
  36.        
  37.         return NO;
  38.     }
  39.     else {
  40.         return YES;
  41.     }
  42. }
  43.  
  44.  
  45. ////////////////////////////////////////////// *** tabWarningDidEnd
  46.  
  47. - (void)tabWarningDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo
  48. {
  49.     if (returnCode == NSAlertDefaultReturn) {
  50.         // We don't want the window being closed before the sheet is dismissed (disappears from view), so we call a method after half
  51.         // second to close the window.
  52.         [self performSelector:@selector(_tc_closeWindow) withObject:nil afterDelay:0.5];
  53.     }
  54. }
  55.  
  56.  
  57. ////////////////////////////////////////////// *** _tc_closeWindow
  58.  
  59. - (void)_tc_closeWindow
  60. {
  61.     [self close];
  62. }
  63.  
  64. @end