summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bookmark_all_tabs_controller.mm
diff options
context:
space:
mode:
authormrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-06 03:24:29 +0000
committermrossetti@chromium.org <mrossetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-06 03:24:29 +0000
commita5971dc68d14d4cb063c10138133483a14cd7530 (patch)
treea141b12594ce9c79a25dd586b5b754976d14ab11 /chrome/browser/cocoa/bookmark_all_tabs_controller.mm
parent85c55dcd717445cd3763b5c94f9902b4cdd194b0 (diff)
downloadchromium_src-a5971dc68d14d4cb063c10138133483a14cd7530.zip
chromium_src-a5971dc68d14d4cb063c10138133483a14cd7530.tar.gz
chromium_src-a5971dc68d14d4cb063c10138133483a14cd7530.tar.bz2
Implement Bookmark All Tabs... Added an abstraction of BookmarkEditorController called BookmarkEditorBaseController, from which BookmarkEditorController and the new BookmarkAllTabsController derive. The bookmark/folder name, URL and OK button now use bindings/KVO. Added BookmarkAllTabs.xib which is nearly identical to BookmarkEditor.xib. Changed unit test since an empty bookmark name is now acceptable. Added unit test for the Bookmark All Tabs...
BookmarkEditor.xib changes: Removed the bookmark name and url as outlets and instead bound their values to controller's displayName and displayURL respectively. Bound the OK button enabling to the controller's okEnabled. BUG=25099 TEST=Open two or more tabs. Bring up a contextual menu by control-clicking on one of the tabs. Choose the Bookmark All Tabs... menu item. A dialog will be presented in which you can type a folder name and select the parent folder in which the new folder will be placed. By default, the most recently touched folder will be selected as the parent. Click OK. Now check to parent folder to see that the newly created folder has been added and then check within that folder to see that the open tabs have been added. Perform the above operation again only this time choose the Bookmark All Tabs... menu item found in the Bookmarks menu. Review URL: http://codereview.chromium.org/357005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31200 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_all_tabs_controller.mm')
-rw-r--r--chrome/browser/cocoa/bookmark_all_tabs_controller.mm90
1 files changed, 90 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/bookmark_all_tabs_controller.mm b/chrome/browser/cocoa/bookmark_all_tabs_controller.mm
new file mode 100644
index 0000000..93b4026
--- /dev/null
+++ b/chrome/browser/cocoa/bookmark_all_tabs_controller.mm
@@ -0,0 +1,90 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/cocoa/bookmark_all_tabs_controller.h"
+#include "app/l10n_util_mac.h"
+#include "base/sys_string_conversions.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "grit/generated_resources.h"
+
+@implementation BookmarkAllTabsController
+
+- (id)initWithParentWindow:(NSWindow*)parentWindow
+ profile:(Profile*)profile
+ parent:(const BookmarkNode*)parent
+ configuration:(BookmarkEditor::Configuration)configuration
+ handler:(BookmarkEditor::Handler*)handler {
+ NSString* nibName = @"BookmarkAllTabs";
+ if ((self = [super initWithParentWindow:parentWindow
+ nibName:nibName
+ profile:profile
+ parent:parent
+ configuration:configuration
+ handler:handler])) {
+ }
+ return self;
+}
+
+- (void)awakeFromNib {
+ [self
+ setInitialName:
+ l10n_util::GetNSStringWithFixup(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME)];
+ [super awakeFromNib];
+}
+
+#pragma mark Bookmark Editing
+
+- (void)UpdateActiveTabPairs {
+ activeTabPairsVector_.clear();
+ Browser* browser = BrowserList::GetLastActive();
+ TabStripModel* tabstrip_model = browser->tabstrip_model();
+ const int tabCount = tabstrip_model->count();
+ for (int i = 0; i < tabCount; ++i) {
+ TabContents* tc = tabstrip_model->GetTabContentsAt(i);
+ const std::wstring tabTitle = UTF16ToWideHack(tc->GetTitle());
+ const GURL& tabURL(tc->GetURL());
+ ActiveTabNameURLPair tabPair(tabTitle, tabURL);
+ activeTabPairsVector_.push_back(tabPair);
+ }
+}
+
+// The the name for the folder into which the tabs will be recorded as
+// bookmarks is assumed to be non-empty. The folder is then created
+// and a bookmark for each open tab added therein.
+- (IBAction)ok:(id)sender {
+ NSString* name = [[self displayName] stringByTrimmingCharactersInSet:
+ [NSCharacterSet newlineCharacterSet]];
+ std::wstring newTitle = base::SysNSStringToWide(name);
+ const BookmarkNode* newParentNode = [self selectedNode];
+ int newIndex = newParentNode->GetChildCount();
+ // Create the new folder which will contain all of the tab URLs.
+ NSString* newFolderName = [self displayName];
+ std::wstring newFolderString = base::SysNSStringToWide(newFolderName);
+ BookmarkModel* model = [self bookmarkModel];
+ const BookmarkNode* newFolder = model->AddGroup(newParentNode, newIndex,
+ newFolderString);
+ [self NotifyHandlerCreatedNode:newFolder];
+ // Get a list of all open tabs, create nodes for them, and add
+ // to the new folder node.
+ [self UpdateActiveTabPairs];
+ int i = 0;
+ for (ActiveTabsNameURLPairVector::const_iterator it =
+ activeTabPairsVector_.begin();
+ it != activeTabPairsVector_.end(); ++it, ++i) {
+ const BookmarkNode* node = model->AddURL(newFolder, i,
+ it->first, it->second);
+ [self NotifyHandlerCreatedNode:node];
+ }
+ [super ok:sender];
+}
+
+- (ActiveTabsNameURLPairVector*)activeTabPairsVector {
+ return &activeTabPairsVector_;
+}
+
+@end // BookmarkAllTabsController
+