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. #import "BrowserDocument.h"
  26. #import <WebKit/WebKit.h>
  27.  
  28. @implementation BrowserWindowController (STBrowserWindowController)
  29.  
  30.  
  31. ////////////////////////////////////////////// *** _st_windowShouldClose
  32.  
  33. - (BOOL)_st_windowShouldClose:(id)sender
  34. {  
  35.     if ([[NSUserDefaults standardUserDefaults] boolForKey:STEnableCloseWindowWarning] == YES) {
  36.         if ([self moreThanOneTabShowing]) {
  37.             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:@""];
  38.        
  39.             [alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(tabWarningDidEnd:returnCode:contextInfo:) contextInfo:(void *)sender];
  40.        
  41.             return NO;
  42.         }
  43.     }
  44.  
  45.     return YES;
  46. }
  47.  
  48.  
  49. ////////////////////////////////////////////// *** _st_createTab
  50.  
  51. - (id)_st_createTab
  52. {  
  53.     NSURL *currentURL = [[self browserDocument] currentURL];
  54.    
  55.     id tab = [self _safari_createTab];
  56.    
  57.     int option = [[NSUserDefaults standardUserDefaults] integerForKey:STNewTabsLoadOption];
  58.    
  59.     if (option == 1) {
  60.         [self goHome:self];
  61.     }
  62.     else if (option == 2) {
  63.         [[tab mainFrame] loadRequest:[NSURLRequest requestWithURL:currentURL]];
  64.     }
  65.     else if (option == 4) {
  66.         [[tab mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSUserDefaults standardUserDefaults] stringForKey:STCustomLoadURL]]]];
  67.     }
  68.    
  69.     return tab;
  70. }
  71.  
  72.  
  73. ////////////////////////////////////////////// *** _st_performQuickSearch
  74.  
  75. - (void)_st_performQuickSearch:(id)sender
  76. {  
  77.     if (![[sender stringValue] isEqualToString:@""]) {
  78.         //id tab = [self _safari_createTab];
  79.    
  80.         [self _safari_performQuickSearch:sender];
  81.     }
  82. }
  83.  
  84.  
  85. ////////////////////////////////////////////// *** tabWarningDidEnd
  86.  
  87. - (void)tabWarningDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo
  88. {
  89.     if (returnCode == NSAlertDefaultReturn) {
  90.         // We don't want the window being closed before the sheet is dismissed (disappears from view), so we call a method after half
  91.         // second to close the window.
  92.         [self performSelector:@selector(_st_closeWindow) withObject:nil afterDelay:0.5];
  93.     }
  94. }
  95.  
  96.  
  97. ////////////////////////////////////////////// *** _tc_closeWindow
  98.  
  99. - (void)_st_closeWindow
  100. {
  101.     [self close];
  102. }
  103.  
  104. @end