/*
* $Id: STBrowserWindowController.m 224 2011-08-13 20:39:45Z stuart $
*
* SafariTabs
* http://stuconnolly.com/projects/safaritabs/
*
* Copyright (c) 2010 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#import <WebKit/WebKit.h>
#import "STSafariPlugin.h"
#import "STBrowserWindowController.h"
#import "STConstants.h"
#import "BrowserDocument.h"
#import "BrowserWebView.h"
#import "BrowserTabViewItem.h"
@interface STBrowserWindowController (DeclaredAPI)
- (id)createTab;
- (id)orderedTabs;
- (id)orderedTabViewItems;
- (void)closeCurrentTab:(id)arg;
@end
@implementation STBrowserWindowController
/*!
* Returns an array of dictionaries, each representing a tab of the window associated with this controller. Each
* dictionary contains the tab's title and URL.
*
* @return An array of dictionaries representing the currently open tabs
*/
{
for (id tab in [self orderedTabs])
{
if (tab) {
NSURL *tabURL
= [tab currentURL
];
NSString *tabTile
= [tab titleForLocationFieldURL
];
NSImage *tabIcon
= [tab mainFrameIcon
];
if ((tabTile) && (tabURL) && (tabIcon)) {
[tabs addObject
:[NSDictionary dictionaryWithObjectsAndKeys
:tabTile, STTabTitleKey, tabURL, STTabURLKey, tabIcon, STTabIconKey,
nil]];
}
}
}
return tabs;
}
/*!
* Returns an array of strings representing the URLs of the currently open tabs on the window associated with
* this controller.
*
* @return An array of strings containing the tabs URL's
*/
{
for (id tab in [self orderedTabs])
{
if ([tab currentURL] != nil) {
[tabs addObject:[tab currentURL]];
}
}
return tabs;
}
/*!
* Gets the localized version of the string 'Close Tab' by extracting it from the menu item 'Close Tab'. This
* is used for setting the undo menu item when tab undo support is on.
*
* @return The localized 'Close Tab' string
*/
- (NSString *)getLocalizedCloseTabString
{
{
if ([item action] == @selector(closeCurrentTab:)) {
closeTabString = [item title];
break;
}
}
return closeTabString;
}
/*!
* This is the re-implementation of Safari's swizzled newTabWithURL: method. Depending on the user's preferences
* the closed tab will be registered with the application's undo manager.
*
* @param url The object calling the method
*/
{
NSUInteger i;
BrowserTabViewItem *newTabViewItem = nil;
id tab = [self createTab];
[[tab mainFrame
] loadRequest
:[NSURLRequest requestWithURL
:[NSURL URLWithString
:url
]]];
NSArray *tabViews
= [self orderedTabs
];
NSArray *tabs
= [self orderedTabViewItems
];
for (i = 0; i < [tabViews count]; i++)
{
if ([[tabViews objectAtIndex:i] isEqualTo:tab]) {
newTabViewItem = [tabs objectAtIndex:i];
break;
}
}
}
@end