dev.stuconnolly.com / svn / safaritabs

  1. /*
  2.  *  STAppController.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 "STAppController.h"
  24. #import "STSafariPlugin.h"
  25. #import "BrowserWindowController.h"
  26.  
  27. @implementation AppController (STAppController)
  28.  
  29.  
  30. ////////////////////////////////////////////// *** _tc_applicationShouldTerminate
  31.  
  32. - (NSApplicationTerminateReply)_tc_applicationShouldTerminate:(id)sender;
  33. {  
  34.     int tabCount;
  35.     NSString *message; 
  36.     NSArray *windows = [[NSDocumentController sharedDocumentController] documents];
  37.    
  38.     if ([windows count] == 0) {
  39.         return NSTerminateNow;
  40.     }
  41.     else if ([windows count] > 1) {
  42.         message = [NSString stringWithFormat:@"You currently have %d windows open. Are you sure you want quit?", [windows count]];
  43.     }
  44.     else {
  45.         NSEnumerator* e = [[[NSDocumentController sharedDocumentController] documents] objectEnumerator];
  46.         id document;
  47.        
  48.         while(document = [e nextObject]) {
  49.             BrowserWindowController *windowController = [[document windowControllers] objectAtIndex:0];
  50.            
  51.             tabCount = [[windowController orderedTabs] count];
  52.         }
  53.    
  54.         if (tabCount == 1) {
  55.             return NSTerminateNow;
  56.         }
  57.        
  58.         message = [NSString stringWithFormat:@"You currently have %d tabs open. Are you sure you want quit?", tabCount];
  59.     }
  60.    
  61.     NSAlert *alert = [NSAlert alertWithMessageText:message defaultButton:@"Quit" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@""];
  62.    
  63.     if ([alert runModal] == NSAlertAlternateReturn) {
  64.         return NSTerminateCancel;
  65.     }
  66.    
  67.     return NSTerminateNow;
  68. }
  69.  
  70. @end