From 2d8ce84ddb1d1b700e595e0539591dc9467c6ebb Mon Sep 17 00:00:00 2001 From: "pinkerton%aol.net" Date: Sat, 20 May 2006 18:27:46 +0000 Subject: [PATCH] hook up cmd-1..9 to load the Nth bookmark from the bookmark bar (bug 317186) --- camino/src/application/MainController.h | 4 ++-- camino/src/application/MainController.mm | 6 ++++++ camino/src/browser/BrowserWindow.mm | 6 ++++++ camino/src/browser/BrowserWindowController.h | 4 ++++ camino/src/browser/BrowserWindowController.mm | 17 ++++++++++++++++- 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/camino/src/application/MainController.h b/camino/src/application/MainController.h index 59d4bd7fdaff..958a03191cf9 100644 --- a/camino/src/application/MainController.h +++ b/camino/src/application/MainController.h @@ -52,8 +52,8 @@ typedef enum EBookmarkOpenBehavior { - eBookmarkOpenBehavior_Preferred, // simply opens the bookmark - eBookmarkOpenBehavior_NewWindowOrTab, // opens the bookmark in a new tab/window, depending on the pref + eBookmarkOpenBehavior_Preferred, // opens the bookmark based on key combo and prefs + eBookmarkOpenBehavior_ForceReuse, // ignore prefs and key combo, reuse the current browser eBookmarkOpenBehavior_NewWindow, eBookmarkOpenBehavior_NewTab }; diff --git a/camino/src/application/MainController.mm b/camino/src/application/MainController.mm index 5dca60a3f8dd..3a57f7702b01 100644 --- a/camino/src/application/MainController.mm +++ b/camino/src/application/MainController.mm @@ -524,6 +524,12 @@ const int kReuseWindowOnAE = 2; } break; + case eBookmarkOpenBehavior_ForceReuse: + openInNewTab = NO; + openInNewWindow = NO; + newTabInBackground = NO; + break; + case eBookmarkOpenBehavior_NewTab: openInNewTab = YES; newTabInBackground = browserWindowController && loadNewTabsInBackgroundPref; diff --git a/camino/src/browser/BrowserWindow.mm b/camino/src/browser/BrowserWindow.mm index 001f827d1355..558645dd231f 100644 --- a/camino/src/browser/BrowserWindow.mm +++ b/camino/src/browser/BrowserWindow.mm @@ -105,6 +105,7 @@ static const int kEscapeKeyCode = 53; // Pass command-return off to the controller so that locations/searches may be opened in a new tab. // Pass command-plus off to the controller to enlarge the text size. // Pass command-shift-r off to the controller for force-reload. +// Pass command-1..9 to the controller to load that bookmark bar item - (BOOL)performKeyEquivalent:(NSEvent *)theEvent { BrowserWindowController* windowController = (BrowserWindowController*)[self delegate]; @@ -121,6 +122,11 @@ static const int kEscapeKeyCode = 53; } else if (keyChar == 'R') { // Capital letter implies shift key. [windowController reload:nil]; // The window controller does the check for the shift key. handled = YES; + } else if (keyChar >= '1' && keyChar <= '9') { + // use |forceReuse| to disable looking at the modifier keys since we know the command + // key is down right now. + [windowController loadBookmarkBarIndex:(keyChar - '1') openBehavior:eBookmarkOpenBehavior_ForceReuse]; + handled = YES; } if (handled) diff --git a/camino/src/browser/BrowserWindowController.h b/camino/src/browser/BrowserWindowController.h index c68fc36fa12f..79750636385e 100644 --- a/camino/src/browser/BrowserWindowController.h +++ b/camino/src/browser/BrowserWindowController.h @@ -38,6 +38,7 @@ #import #import "BrowserWrapper.h" #import "Find.h" +#import "MainController.h" class nsIURIFixup; class nsIBrowserHistory; @@ -356,4 +357,7 @@ typedef enum // handle command-return in location or search field - (BOOL)handleCommandReturn:(BOOL)aShiftIsDown; +// Load the item in the bookmark bar given by |inIndex| using the given behavior. +- (BOOL)loadBookmarkBarIndex:(unsigned short)inIndex openBehavior:(EBookmarkOpenBehavior)inBehavior; + @end diff --git a/camino/src/browser/BrowserWindowController.mm b/camino/src/browser/BrowserWindowController.mm index 3b471cd642ae..c3b9aedf926b 100644 --- a/camino/src/browser/BrowserWindowController.mm +++ b/camino/src/browser/BrowserWindowController.mm @@ -62,7 +62,6 @@ #import "SearchTextField.h" #import "SearchTextFieldCell.h" #import "STFPopUpButtonCell.h" -#import "MainController.h" #import "DraggableImageAndTextCell.h" #import "MVPreferencesController.h" #import "ViewCertificateDialogController.h" @@ -3760,6 +3759,21 @@ enum BWCOpenDest { return [mBrowserView currentCharset]; } +// +// -loadBookmarkBarIndex: +// +// Load the item in the bookmark bar given by |inIndex| using the given behavior. +// Uses the top-level |-loadBookmark:...| in order to get the right behavior with folders and +// tab groups. +// +- (BOOL)loadBookmarkBarIndex:(unsigned short)inIndex openBehavior:(EBookmarkOpenBehavior)inBehavior +{ + BookmarkItem* item = [[[BookmarkManager sharedBookmarkManager] toolbarFolder] objectAtIndex:inIndex]; + if (item) + [[NSApp delegate] loadBookmark:item withWindowController:self openBehavior:inBehavior]; + return YES; +} + // // - handleCommandReturn: // @@ -3947,3 +3961,4 @@ int TabBarVisiblePrefChangedCallback(const char* inPref, void* inBWC) return NS_OK; } +