Add the ability to open multiple bookmarks or history items in new tabs/windows from the context menu, and with command-double-click (bug 285182).

This commit is contained in:
smfr%smfr.org 2005-06-23 18:10:56 +00:00
Родитель 511a6bddbf
Коммит 7c1e2f8626
9 изменённых файлов: 313 добавлений и 183 удалений

Просмотреть файл

@ -204,7 +204,8 @@
-(NSMenu*)menuForEvent:(NSEvent*)aEvent
{
lastEventWasMenu = YES;
return [[BookmarkManager sharedBookmarkManager] contextMenuForItem:[self bookmarkItem] fromView:nil target:self];
NSArray* theItemArray = [NSArray arrayWithObject:[self bookmarkItem]];
return [[BookmarkManager sharedBookmarkManager] contextMenuForItems:theItemArray fromView:nil target:self];
}
//

Просмотреть файл

@ -102,7 +102,7 @@ enum {
-(NSArray *)searchBookmarksContainer:(BookmarkFolder*)container forString:(NSString *)searchString inFieldWithTag:(int)tag;
-(unsigned) firstUserCollection;
-(BOOL) isDropValid:(NSArray *)items toFolder:(BookmarkFolder *)parent;
-(NSMenu *)contextMenuForItem:(id)item fromView:(BookmarkOutlineView *)outlineView target:(id)target;
-(NSMenu *)contextMenuForItems:(NSArray*)items fromView:(BookmarkOutlineView *)outlineView target:(id)target;
// Reading bookmark files
-(BOOL) readBookmarks;

Просмотреть файл

@ -484,27 +484,51 @@ static unsigned gFirstUserCollection = 0;
// unified context menu generator for all kinds of bookmarks
// this can be called from a bookmark outline view
// or from a bookmark button, which should pass a nil outlineView
- (NSMenu *)contextMenuForItem:(id)item fromView:(BookmarkOutlineView *)outlineView target:(id)target
- (NSMenu *)contextMenuForItems:(NSArray*)items fromView:(BookmarkOutlineView *)outlineView target:(id)target
{
// don't do anything if item == nil
if (!item)
return nil;
if ([items count] == 0) return nil;
BOOL itemsContainsFolder = NO;
BOOL itemsContainsBookmark = NO;
BOOL multipleItems = ([items count] > 1);
NSEnumerator* itemsEnum = [items objectEnumerator];
id curItem;
while ((curItem = [itemsEnum nextObject]))
{
itemsContainsFolder |= [curItem isKindOfClass:[BookmarkFolder class]];
itemsContainsBookmark |= [curItem isKindOfClass:[Bookmark class]];
}
// All the methods in this context menu need to be able to handle > 1 item
// being selected, and the selected items containing a mixture of folders
// and bookmarks.
NSMenu * contextMenu = [[[NSMenu alloc] initWithTitle:@"notitle"] autorelease];
BOOL isFolder = [item isKindOfClass:[BookmarkFolder class]];
NSString * menuTitle;
NSString * menuTitle = nil;
// open in new window
if (isFolder)
// open in new window(s)
if (itemsContainsFolder && [items count] == 1)
menuTitle = NSLocalizedString(@"Open Tabs in New Window", @"");
else if (multipleItems)
menuTitle = NSLocalizedString(@"Open in New Windows", @"");
else
menuTitle = NSLocalizedString(@"Open in New Window", @"");
NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(openBookmarkInNewWindow:) keyEquivalent:@""] autorelease];
[menuItem setTarget:target];
[contextMenu addItem:menuItem];
// open in new tab
if (isFolder)
// open in new tabs in new window
if (multipleItems)
{
menuTitle = NSLocalizedString(@"Open in Tabs in New Window", @"");
menuItem = [[[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(openBookmarksInTabsInNewWindow:) keyEquivalent:@""] autorelease];
[menuItem setTarget:target];
[contextMenu addItem:menuItem];
}
// open in new tab in current window
if (itemsContainsFolder || multipleItems)
menuTitle = NSLocalizedString(@"Open in New Tabs", @"");
else
menuTitle = NSLocalizedString(@"Open in New Tab", @"");
@ -512,7 +536,7 @@ static unsigned gFirstUserCollection = 0;
[menuItem setTarget:target];
[contextMenu addItem:menuItem];
if (!outlineView || ([outlineView numberOfSelectedRows] == 1)) {
if (!outlineView || ([items count] == 1)) {
[contextMenu addItem:[NSMenuItem separatorItem]];
menuTitle = NSLocalizedString(@"Get Info", @"");
menuItem = [[[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(showBookmarkInfo:) keyEquivalent:@""] autorelease];
@ -520,10 +544,10 @@ static unsigned gFirstUserCollection = 0;
[contextMenu addItem:menuItem];
}
if ([item isKindOfClass:[BookmarkFolder class]]) {
if (([items count] == 1) && itemsContainsFolder) {
menuTitle = NSLocalizedString(@"Use as Dock Menu", @"");
menuItem = [[[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(makeDockMenu:) keyEquivalent:@""] autorelease];
[menuItem setTarget:item];
[menuItem setTarget:[items objectAtIndex:0]];
[contextMenu addItem:menuItem];
}

Просмотреть файл

@ -130,6 +130,7 @@
-(IBAction) openBookmark: (id)aSender;
-(IBAction) openBookmarkInNewTab:(id)aSender;
-(IBAction) openBookmarkInNewWindow:(id)aSender;
-(IBAction) openBookmarksInTabsInNewWindow:(id)aSender;
-(IBAction) deleteBookmarks:(id)aSender;
-(IBAction) showBookmarkInfo:(id)aSender;
-(IBAction) locateBookmark:(id)aSender;

Просмотреть файл

@ -446,17 +446,8 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
}
}
// create array of items we need to delete. Deleting items out of of the
// selection array is problematic for some reason.
NSMutableArray *itemsToDelete = [[NSMutableArray alloc] init];
selRows = [mBookmarksOutlineView selectedRowEnumerator];
for (NSNumber* currIndex = [selRows nextObject];
currIndex != nil;
currIndex = [selRows nextObject]) {
index = [currIndex intValue];
BookmarkItem* item = [mBookmarksOutlineView itemAtRow: index];
[itemsToDelete addObject: item];
}
// create array of items we need to delete.
NSArray* itemsToDelete = [mBookmarksOutlineView selectedItems];
// delete all bookmarks that are in our array
int count = [itemsToDelete count];
@ -464,7 +455,6 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
doomedItem = [itemsToDelete objectAtIndex:i];
[[doomedItem parent] deleteChild:doomedItem];
}
[itemsToDelete release];
// restore selection to location near last item deleted or last item
int total = [mBookmarksOutlineView numberOfRows];
@ -475,93 +465,134 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
-(IBAction)openBookmark: (id)aSender
{
id item = nil;
if (aSender == mBookmarksOutlineView) {
int index = [mBookmarksOutlineView selectedRow];
if (index == -1)
return;
item = [mBookmarksOutlineView itemAtRow: index];
} else if ([aSender isKindOfClass:[BookmarkItem class]])
item = aSender;
if (!item)
return;
// see if it's a rendezvous item
id parent = [item parent];
if (![parent isKindOfClass:[BookmarkItem class]]) {
[[NetworkServices sharedNetworkServices] attemptResolveService:[parent intValue] forSender:item];
mOpenActionFlag = kOpenBookmarkAction;
return;
}
// handling toggling of folders
if ([item isKindOfClass:[BookmarkFolder class]])
{
if (![item isGroup])
{
if ([mBookmarksOutlineView isItemExpanded:item])
[mBookmarksOutlineView collapseItem: item];
NSArray* items = nil;
if ([aSender isKindOfClass:[BookmarkItem class]])
items = [NSArray arrayWithObject:aSender];
else
[mBookmarksOutlineView expandItem: item];
return;
}
}
items = [mBookmarksOutlineView selectedItems];
NSEnumerator* itemsEnum = [items objectEnumerator];
id curItem;
while ((curItem = [itemsEnum nextObject]))
{
// see if it's a rendezvous item
id parent = [curItem parent];
if (![parent isKindOfClass:[BookmarkItem class]])
{
[[NetworkServices sharedNetworkServices] attemptResolveService:[parent intValue] forSender:curItem];
mOpenActionFlag = kOpenBookmarkAction;
}
else if ([curItem isKindOfClass:[BookmarkFolder class]])
{
if (![curItem isGroup])
{
if ([mBookmarksOutlineView isItemExpanded:curItem])
[mBookmarksOutlineView collapseItem: curItem];
else
[mBookmarksOutlineView expandItem: curItem];
}
}
else
{
// otherwise follow the standard bookmark opening behavior
[[NSApp delegate] loadBookmark:item withWindowController:mBrowserWindowController openBehavior:eBookmarkOpenBehaviorDefault];
[[NSApp delegate] loadBookmark:curItem withWindowController:mBrowserWindowController openBehavior:eBookmarkOpenBehaviorDefault];
}
}
}
-(IBAction)openBookmarkInNewTab:(id)aSender
{
id item = nil;
NSArray* items = nil;
if ([aSender isKindOfClass:[BookmarkItem class]])
items = [NSArray arrayWithObject:aSender];
else
items = [mBookmarksOutlineView selectedItems];
if (![aSender isKindOfClass:[BookmarkItem class]]) {
int index = [mBookmarksOutlineView selectedRow];
if (index == -1)
return;
if ([mBookmarksOutlineView numberOfSelectedRows] == 1)
item = [mBookmarksOutlineView itemAtRow:index];
} else
item = aSender;
if (!item)
return;
NSEnumerator* itemsEnum = [items objectEnumerator];
id curItem;
while ((curItem = [itemsEnum nextObject]))
{
// see if it's a rendezvous item
id parent = [item parent];
if (![parent isKindOfClass:[BookmarkItem class]]) {
[[NetworkServices sharedNetworkServices] attemptResolveService:[parent intValue] forSender:item];
id parent = [curItem parent];
if (![parent isKindOfClass:[BookmarkItem class]])
{
[[NetworkServices sharedNetworkServices] attemptResolveService:[parent intValue] forSender:curItem];
mOpenActionFlag = kOpenInNewTabAction;
return;
}
else
{
// otherwise follow the standard bookmark opening behavior
[[NSApp delegate] loadBookmark:curItem withWindowController:mBrowserWindowController openBehavior:eBookmarkOpenBehaviorNewTabDefault];
}
}
}
// otherwise follow the standard bookmark opening behavior
[[NSApp delegate] loadBookmark:item withWindowController:mBrowserWindowController openBehavior:eBookmarkOpenBehaviorNewTabDefault];
-(IBAction)openBookmarksInTabsInNewWindow:(id)aSender
{
NSArray* items = nil;
if ([aSender isKindOfClass:[BookmarkItem class]])
items = [NSArray arrayWithObject:aSender];
else
items = [mBookmarksOutlineView selectedItems];
// make url array
NSMutableArray* urlArray = [NSMutableArray arrayWithCapacity:[items count]];
NSEnumerator* itemsEnum = [items objectEnumerator];
id curItem;
while ((curItem = [itemsEnum nextObject]))
{
// see if it's a rendezvous item (this won't open in the new window, because we suck)
id parent = [curItem parent];
if (![parent isKindOfClass:[BookmarkItem class]])
{
[[NetworkServices sharedNetworkServices] attemptResolveService:[parent intValue] forSender:curItem];
mOpenActionFlag = kOpenInNewTabAction;
}
else
{
if ([curItem isKindOfClass:[Bookmark class]])
[urlArray addObject:[curItem url]];
else if ([curItem isKindOfClass:[BookmarkFolder class]])
[urlArray addObjectsFromArray:[curItem childURLs]];
}
}
// make new window
BOOL loadNewTabsInBackgroundPref = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
NSWindow* behindWindow = nil;
if (loadNewTabsInBackgroundPref)
behindWindow = [mBrowserWindowController window];
[[NSApp delegate] openBrowserWindowWithURLs:urlArray behind:behindWindow allowPopups:NO];
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
{
id item = nil;
if (![aSender isKindOfClass:[BookmarkItem class]]) {
int index = [mBookmarksOutlineView selectedRow];
if (index == -1)
return;
if ([mBookmarksOutlineView numberOfSelectedRows] == 1)
item = [mBookmarksOutlineView itemAtRow:index];
} else
item = aSender;
if (!item)
return;
NSArray* items = nil;
if ([aSender isKindOfClass:[BookmarkItem class]])
items = [NSArray arrayWithObject:aSender];
else
items = [mBookmarksOutlineView selectedItems];
NSEnumerator* itemsEnum = [items objectEnumerator];
id curItem;
while ((curItem = [itemsEnum nextObject]))
{
// see if it's a rendezvous item
id parent = [item parent];
if (![parent isKindOfClass:[BookmarkItem class]]) {
[[NetworkServices sharedNetworkServices] attemptResolveService:[parent intValue] forSender:item];
id parent = [curItem parent];
if (![parent isKindOfClass:[BookmarkItem class]])
{
[[NetworkServices sharedNetworkServices] attemptResolveService:[parent intValue] forSender:curItem];
mOpenActionFlag = kOpenInNewWindowAction;
return;
}
else
{
// otherwise follow the standard bookmark opening behavior
[[NSApp delegate] loadBookmark:item withWindowController:mBrowserWindowController openBehavior:eBookmarkOpenBehaviorNewWindowDefault];
[[NSApp delegate] loadBookmark:curItem withWindowController:mBrowserWindowController openBehavior:eBookmarkOpenBehaviorNewWindowDefault];
}
}
}
-(IBAction)showBookmarkInfo:(id)aSender
@ -598,15 +629,7 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
- (IBAction)copy:(id)aSender
{
// Get the list of bookmark items that are selected
NSMutableArray *bookmarkItemsToCopy = [NSMutableArray array];
NSEnumerator* selRows = [mBookmarksOutlineView selectedRowEnumerator];
id curSelectedRow;
while ((curSelectedRow = [selRows nextObject])) {
[bookmarkItemsToCopy addObject: [mBookmarksOutlineView itemAtRow:[curSelectedRow intValue]]];
}
[self copyBookmarks:bookmarkItemsToCopy toPasteboard:[NSPasteboard generalPasteboard]];
[self copyBookmarks:[mBookmarksOutlineView selectedItems] toPasteboard:[NSPasteboard generalPasteboard]];
}
@ -1386,9 +1409,9 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
return nil;
}
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItems:(NSArray*)items
{
return [[BookmarkManager sharedBookmarkManager] contextMenuForItem:item fromView:outlineView target:self];
return [[BookmarkManager sharedBookmarkManager] contextMenuForItems:items fromView:outlineView target:self];
}
- (BOOL)outlineView:(NSOutlineView*)inOutlineView columnHasIcon:(NSTableColumn*)inColumn
@ -1661,10 +1684,9 @@ static const int kDisabledQuicksearchPopupItemTag = 9999;
}
else
{
int index = [mBookmarksOutlineView selectedRow];
BookmarkItem* item = [mBookmarksOutlineView itemAtRow:index];
if (item)
actionMenu = [[BookmarkManager sharedBookmarkManager] contextMenuForItem:item fromView:mBookmarksOutlineView target:self];
NSArray* selectedBMs = [mBookmarksOutlineView selectedItems];
if ([selectedBMs count] > 0)
actionMenu = [[BookmarkManager sharedBookmarkManager] contextMenuForItems:selectedBMs fromView:mBookmarksOutlineView target:self];
else
actionMenu = mActionMenuBookmarks;
}

Просмотреть файл

@ -68,6 +68,8 @@
-(void)setDeleteAction: (SEL)deleteAction;
-(SEL)deleteAction;
- (NSArray*)selectedItems;
-(void)_editItem:(id)item;
-(void)_cancelEditItem;
@ -99,6 +101,6 @@
@end
@interface NSObject (CHOutlineViewContextMenus)
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item;
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItems:(NSArray*)items;
@end

Просмотреть файл

@ -106,6 +106,21 @@ static NSString* const kAutosaveSortDirectionKey = @"sort_descending";
mDelegateTooltipStringForItem = [anObject respondsToSelector:@selector(outlineView:tooltipStringForItem:)];
}
- (NSArray*)selectedItems
{
NSMutableArray* itemsArray = [NSMutableArray arrayWithCapacity:[self numberOfSelectedRows]];
NSEnumerator* rowEnum = [self selectedRowEnumerator];
NSNumber* currentRow = nil;
while ((currentRow = [rowEnum nextObject]))
{
id item = [self itemAtRow:[currentRow intValue]];
[itemsArray addObject:item];
}
return itemsArray;
}
-(void)keyDown:(NSEvent*)aEvent
{
const unichar kForwardDeleteChar = 0xf728; // couldn't find this in any cocoa header
@ -206,40 +221,39 @@ static NSString* const kAutosaveSortDirectionKey = @"sort_descending";
*/
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
id item;
int rowIndex;
NSPoint point;
point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
rowIndex = [self rowAtPoint:point];
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
int rowIndex = [self rowAtPoint:point];
if (rowIndex >= 0) {
if (rowIndex >= 0)
{
// There seems to be a bug in AppKit; selectRow is supposed to
// abort editing, but it doesn't, thus we do it manually.
[self abortEditing];
item = [self itemAtRow:rowIndex];
if (item) {
id item = [self itemAtRow:rowIndex];
if (!item) return nil; // someone might want a menu on the blank area
id delegate = [self delegate];
// if we click on a selected item, don't deselect other stuff.
// otherwise, select just the current item.
// Make sure the item is the only selected one
if (![delegate respondsToSelector:@selector(outlineView:shouldSelectItem:)] ||
[delegate outlineView:self shouldSelectItem:item])
if (![self isRowSelected:rowIndex])
{
// we don't want anything but what was right-clicked selected
// XXX sure we do. I should be able to context-click on a bunch of selected bookmarks
// and say 'open in tabs'. However, the current delegate method prevents this, because
// it only allows you to pass a single item. This needs fixing.
[self deselectAll:nil];
BOOL shouldSelect = ![delegate respondsToSelector:@selector(outlineView:shouldSelectItem:)] ||
[delegate outlineView:self shouldSelectItem:item];
if (!shouldSelect)
return nil; // can't select it, so bail
[self selectRow:rowIndex byExtendingSelection:NO];
}
if ([delegate respondsToSelector:@selector(outlineView:contextMenuForItem:)])
return [delegate outlineView:self contextMenuForItem:item];
} else {
// no item, no context menu
return nil;
if ([delegate respondsToSelector:@selector(outlineView:contextMenuForItems:)])
return [delegate outlineView:self contextMenuForItems:[self selectedItems]];
}
}
else {
else
{
[self deselectAll:self];
}

Просмотреть файл

@ -71,6 +71,7 @@
- (IBAction)openHistoryItem:(id)sender;
- (IBAction)openHistoryItemInNewWindow:(id)aSender;
- (IBAction)openHistoryItemInNewTab:(id)aSender;
- (IBAction)openHistoryItemsInTabsInNewWindow:(id)aSender;
- (IBAction)deleteHistoryItems:(id)sender;

Просмотреть файл

@ -45,6 +45,7 @@
#import "PreferenceManager.h"
#import "BrowserWindowController.h"
#import "BookmarkViewController.h"
#import "MainController.h"
#import "HistoryOutlineViewDelegate.h"
@ -73,7 +74,6 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
- (void)historyChanged:(NSNotification *)notification;
- (HistoryDataSource*)historyDataSource;
- (NSArray*)selectedItems;
- (void)recursiveDeleteItem:(HistoryItem*)item;
- (void)saveViewToPrefs;
- (void)updateSortMenuState;
@ -171,29 +171,38 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
- (IBAction)openHistoryItem:(id)sender
{
int index = [mHistoryOutlineView selectedRow];
if (index == -1) return;
NSArray* selectedHistoryItems = [mHistoryOutlineView selectedItems];
if ([selectedHistoryItems count] == 0) return;
id item = [mHistoryOutlineView itemAtRow:index];
if (!item) return;
if ([mHistoryOutlineView isExpandable:item])
// only do expand/collapse if just one item is selected
id firstItem;
if (([selectedHistoryItems count] == 1) &&
(firstItem = [selectedHistoryItems objectAtIndex:0]) &&
[mHistoryOutlineView isExpandable:firstItem])
{
if ([mHistoryOutlineView isItemExpanded: item])
[mHistoryOutlineView collapseItem:item];
if ([mHistoryOutlineView isItemExpanded: firstItem])
[mHistoryOutlineView collapseItem:firstItem];
else
[mHistoryOutlineView expandItem:item];
[mHistoryOutlineView expandItem:firstItem];
return;
}
else
BOOL loadInBackground = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
BOOL openInTabs = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.opentabfor.middleclick" withSuccess:NULL];
BOOL cmdKeyDown = (GetCurrentKeyModifiers() & cmdKey) != 0;
NSEnumerator* itemEnum = [selectedHistoryItems objectEnumerator];
id curItem;
while ((curItem = [itemEnum nextObject]))
{
// The history view obeys the app preference for cmd-click -> open in new window or tab
if (![item isSiteItem]) return;
if (![curItem isSiteItem]) continue;
NSString* url = [item url];
BOOL loadInBackground = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
if (GetCurrentKeyModifiers() & cmdKey)
NSString* url = [curItem url];
if (cmdKeyDown)
{
if ([[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.opentabfor.middleclick" withSuccess:NULL])
if (openInTabs)
[mBrowserWindowController openNewTabWithURL:url referrer:nil loadInBackground:loadInBackground allowPopups:NO];
else
[mBrowserWindowController openNewWindowWithURL:url referrer: nil loadInBackground:loadInBackground allowPopups:NO];
@ -205,15 +214,12 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
- (IBAction)deleteHistoryItems:(id)sender
{
int index = [mHistoryOutlineView selectedRow];
if (index == -1)
return;
// If just 1 row was selected, keep it so the user can delete again immediately
BOOL clearSelectionWhenDone = ([mHistoryOutlineView numberOfSelectedRows] > 1);
// make a list of doomed items first so the rows don't change under us
NSArray* doomedItems = [self selectedItems];
NSArray* doomedItems = [mHistoryOutlineView selectedItems];
if ([doomedItems count] == 0) return;
// to avoid potentially many updates, disabled auto updating
mUpdatesDisabled = YES;
@ -241,7 +247,7 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
// called from context menu, assumes represented object has been set
- (IBAction)openHistoryItemInNewWindow:(id)aSender
{
NSArray* itemsArray = [self selectedItems];
NSArray* itemsArray = [mHistoryOutlineView selectedItems];
BOOL backgroundLoad = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
@ -257,7 +263,7 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
// called from context menu, assumes represented object has been set
- (IBAction)openHistoryItemInNewTab:(id)aSender
{
NSArray* itemsArray = [self selectedItems];
NSArray* itemsArray = [mHistoryOutlineView selectedItems];
BOOL backgroundLoad = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
@ -270,6 +276,31 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
}
}
- (IBAction)openHistoryItemsInTabsInNewWindow:(id)aSender
{
NSArray* itemsArray = [mHistoryOutlineView selectedItems];
// make url array
NSMutableArray* urlArray = [NSMutableArray arrayWithCapacity:[itemsArray count]];
NSEnumerator* itemsEnum = [itemsArray objectEnumerator];
id curItem;
while ((curItem = [itemsEnum nextObject]))
{
if ([curItem isKindOfClass:[HistorySiteItem class]])
[urlArray addObject:[curItem url]];
}
// make new window
BOOL loadNewTabsInBackgroundPref = [[PreferenceManager sharedInstance] getBooleanPref:"browser.tabs.loadInBackground" withSuccess:NULL];
NSWindow* behindWindow = nil;
if (loadNewTabsInBackgroundPref)
behindWindow = [mBrowserWindowController window];
[[NSApp delegate] openBrowserWindowWithURLs:urlArray behind:behindWindow allowPopups:NO];
}
#pragma mark -
- (IBAction)groupByDate:(id)sender
@ -345,13 +376,59 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
}
#endif
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItems:(NSArray*)items
{
HistoryItem* historyItem = (HistoryItem*)item;
if (![historyItem isKindOfClass:[HistorySiteItem class]])
return nil;
unsigned int numSiteItems = 0;
return mOutlinerContextMenu;
NSEnumerator* itemsEnum = [items objectEnumerator];
id curItem;
while ((curItem = [itemsEnum nextObject]))
{
if ([curItem isKindOfClass:[HistorySiteItem class]])
++numSiteItems;
}
if (numSiteItems == 0)
return [outlineView menu];
NSMenu* contextMenu = [[[NSMenu alloc] initWithTitle:@"notitle"] autorelease];
NSMenuItem* menuItem = nil;
NSString* menuTitle = nil;
if (numSiteItems > 1)
menuTitle = NSLocalizedString(@"Open in New Windows", @"");
else
menuTitle = NSLocalizedString(@"Open in New Window", @"");
menuItem = [[[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(openHistoryItemInNewWindow:) keyEquivalent:@""] autorelease];
[menuItem setTarget:self];
[contextMenu addItem:menuItem];
if (numSiteItems > 1)
menuTitle = NSLocalizedString(@"Open in New Tabs", @"");
else
menuTitle = NSLocalizedString(@"Open in New Tab", @"");
menuItem = [[[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(openHistoryItemInNewTab:) keyEquivalent:@""] autorelease];
[menuItem setTarget:self];
[contextMenu addItem:menuItem];
if (numSiteItems > 1)
{
menuTitle = NSLocalizedString(@"Open in Tabs in New Window", @"");
menuItem = [[[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(openHistoryItemsInTabsInNewWindow:) keyEquivalent:@""] autorelease];
[menuItem setTarget:self];
[contextMenu addItem:menuItem];
}
// space
[contextMenu addItem:[NSMenuItem separatorItem]];
// delete
menuTitle = NSLocalizedString(@"Delete", @"");
menuItem = [[[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(deleteHistoryItems:) keyEquivalent:@""] autorelease];
[menuItem setTarget:self];
[contextMenu addItem:menuItem];
return contextMenu;
}
- (void)outlineViewItemDidExpand:(NSNotification *)notification
@ -381,6 +458,9 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
if (action == @selector(openHistoryItemInNewTab:))
return [self anyHistorySiteItemsSelected];
if (action == @selector(openHistoryItemsInTabsInNewWindow:))
return [self anyHistorySiteItemsSelected];
if (action == @selector(deleteHistoryItems:))
return [self anyHistorySiteItemsSelected];
@ -403,21 +483,6 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat
}
}
- (NSArray*)selectedItems
{
NSMutableArray* itemsArray = [NSMutableArray arrayWithCapacity:[mHistoryOutlineView numberOfSelectedRows]];
NSEnumerator* rowEnum = [mHistoryOutlineView selectedRowEnumerator];
NSNumber* currentRow = nil;
while ((currentRow = [rowEnum nextObject]))
{
HistoryItem * item = [mHistoryOutlineView itemAtRow:[currentRow intValue]];
[itemsArray addObject:item];
}
return itemsArray;
}
- (void)recursiveDeleteItem:(HistoryItem*)item
{
if ([item isKindOfClass:[HistorySiteItem class]])