Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: chrome/browser/cocoa/bookmark_all_tabs_controller.mm

Issue 357005: Implement Bookmark All Tabs... using the BookmarkEditorController and determi... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Name: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/cocoa/bookmark_all_tabs_controller.h"
6 #include "app/l10n_util_mac.h"
7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h"
11 #include "chrome/browser/tab_contents/tab_contents.h"
12 #include "grit/generated_resources.h"
13
14 @implementation BookmarkAllTabsController
15
16 - (id)initWithParentWindow:(NSWindow*)parentWindow
17 profile:(Profile*)profile
18 parent:(const BookmarkNode*)parent
19 configuration:(BookmarkEditor::Configuration)configuration
20 handler:(BookmarkEditor::Handler*)handler {
21 NSString* nibName = @"BookmarkAllTabs";
22 if ((self = [super initWithParentWindow:parentWindow
23 nibName:nibName
24 profile:profile
25 parent:parent
26 configuration:configuration
27 handler:handler])) {
28 }
29 return self;
30 }
31
32 - (void)awakeFromNib {
33 [self
34 setInitialName:
35 l10n_util::GetNSStringWithFixup(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME)];
36 [super awakeFromNib];
37 }
38
39 #pragma mark Bookmark Editing
40
41 - (void)UpdateActiveTabPairs {
42 activeTabPairsVector_.clear();
43 Browser* browser = BrowserList::GetLastActive();
44 TabStripModel* tabstrip_model = browser->tabstrip_model();
45 const int tabCount = tabstrip_model->count();
46 for (int i = 0; i < tabCount; ++i) {
47 TabContents* tc = tabstrip_model->GetTabContentsAt(i);
48 const std::wstring tabTitle = UTF16ToWideHack(tc->GetTitle());
49 const GURL& tabURL(tc->GetURL());
50 ActiveTabNameURLPair tabPair(tabTitle, tabURL);
51 activeTabPairsVector_.push_back(tabPair);
52 }
53 }
54
55 // The the name for the folder into which the tabs will be recorded as
56 // bookmarks is assumed to be non-empty. The folder is then created
57 // and a bookmark for each open tab added therein.
58 - (IBAction)ok:(id)sender {
59 NSString* name = [[self displayName] stringByTrimmingCharactersInSet:
60 [NSCharacterSet newlineCharacterSet]];
61 std::wstring newTitle = base::SysNSStringToWide(name);
62 const BookmarkNode* newParentNode = [self selectedNode];
63 int newIndex = newParentNode->GetChildCount();
64 // Create the new folder which will contain all of the tab URLs.
65 NSString* newFolderName = [self displayName];
66 std::wstring newFolderString = base::SysNSStringToWide(newFolderName);
67 BookmarkModel* model = [self bookmarkModel];
68 const BookmarkNode* newFolder = model->AddGroup(newParentNode, newIndex,
69 newFolderString);
70 [self NotifyHandlerCreatedNode:newFolder];
71 // Get a list of all open tabs, create nodes for them, and add
72 // to the new folder node.
73 [self UpdateActiveTabPairs];
74 int i = 0;
75 for (ActiveTabsNameURLPairVector::const_iterator it =
76 activeTabPairsVector_.begin();
77 it != activeTabPairsVector_.end(); ++it, ++i) {
78 const BookmarkNode* node = model->AddURL(newFolder, i,
79 it->first, it->second);
80 [self NotifyHandlerCreatedNode:node];
81 }
82 [super ok:sender];
83 }
84
85 - (ActiveTabsNameURLPairVector*)activeTabPairsVector {
86 return &activeTabPairsVector_;
87 }
88
89 @end // BookmarkAllTabsController
90
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_all_tabs_controller.h ('k') | chrome/browser/cocoa/bookmark_all_tabs_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698