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 393006: Change the folder presentation in the Bookmark Editor and the Bookmark All Ta... (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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/cocoa/bookmark_all_tabs_controller.h" 5 #import "chrome/browser/cocoa/bookmark_all_tabs_controller.h"
6 #include "app/l10n_util_mac.h" 6 #include "app/l10n_util_mac.h"
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
(...skipping 12 matching lines...) Expand all
23 nibName:nibName 23 nibName:nibName
24 profile:profile 24 profile:profile
25 parent:parent 25 parent:parent
26 configuration:configuration 26 configuration:configuration
27 handler:handler])) { 27 handler:handler])) {
28 } 28 }
29 return self; 29 return self;
30 } 30 }
31 31
32 - (void)awakeFromNib { 32 - (void)awakeFromNib {
33 [self 33 [self setInitialName:
34 setInitialName: 34 l10n_util::GetNSStringWithFixup(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME)];
35 l10n_util::GetNSStringWithFixup(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME)];
36 [super awakeFromNib]; 35 [super awakeFromNib];
37 } 36 }
38 37
39 #pragma mark Bookmark Editing 38 #pragma mark Bookmark Editing
40 39
41 - (void)UpdateActiveTabPairs { 40 - (void)UpdateActiveTabPairs {
42 activeTabPairsVector_.clear(); 41 activeTabPairsVector_.clear();
43 Browser* browser = BrowserList::GetLastActive(); 42 Browser* browser = BrowserList::GetLastActive();
44 TabStripModel* tabstrip_model = browser->tabstrip_model(); 43 TabStripModel* tabstrip_model = browser->tabstrip_model();
45 const int tabCount = tabstrip_model->count(); 44 const int tabCount = tabstrip_model->count();
46 for (int i = 0; i < tabCount; ++i) { 45 for (int i = 0; i < tabCount; ++i) {
47 TabContents* tc = tabstrip_model->GetTabContentsAt(i); 46 TabContents* tc = tabstrip_model->GetTabContentsAt(i);
48 const std::wstring tabTitle = UTF16ToWideHack(tc->GetTitle()); 47 const std::wstring tabTitle = UTF16ToWideHack(tc->GetTitle());
49 const GURL& tabURL(tc->GetURL()); 48 const GURL& tabURL(tc->GetURL());
50 ActiveTabNameURLPair tabPair(tabTitle, tabURL); 49 ActiveTabNameURLPair tabPair(tabTitle, tabURL);
51 activeTabPairsVector_.push_back(tabPair); 50 activeTabPairsVector_.push_back(tabPair);
52 } 51 }
53 } 52 }
54 53
55 // The the name for the folder into which the tabs will be recorded as 54 // Called by -[BookmarkEditorBaseController ok:]. Creates the container
56 // bookmarks is assumed to be non-empty. The folder is then created 55 // folder for the tabs and then the bookmarks in that new folder.
57 // and a bookmark for each open tab added therein. 56 // Returns a BOOL as an NSNumber indicating that the commit may proceed.
58 - (IBAction)ok:(id)sender { 57 - (NSNumber*)didCommit {
59 NSString* name = [[self displayName] stringByTrimmingCharactersInSet: 58 NSString* name = [[self displayName] stringByTrimmingCharactersInSet:
60 [NSCharacterSet newlineCharacterSet]]; 59 [NSCharacterSet newlineCharacterSet]];
61 std::wstring newTitle = base::SysNSStringToWide(name); 60 std::wstring newTitle = base::SysNSStringToWide(name);
62 const BookmarkNode* newParentNode = [self selectedNode]; 61 const BookmarkNode* newParentNode = [self selectedNode];
63 int newIndex = newParentNode->GetChildCount(); 62 int newIndex = newParentNode->GetChildCount();
64 // Create the new folder which will contain all of the tab URLs. 63 // Create the new folder which will contain all of the tab URLs.
65 NSString* newFolderName = [self displayName]; 64 NSString* newFolderName = [self displayName];
66 std::wstring newFolderString = base::SysNSStringToWide(newFolderName); 65 std::wstring newFolderString = base::SysNSStringToWide(newFolderName);
67 BookmarkModel* model = [self bookmarkModel]; 66 BookmarkModel* model = [self bookmarkModel];
68 const BookmarkNode* newFolder = model->AddGroup(newParentNode, newIndex, 67 const BookmarkNode* newFolder = model->AddGroup(newParentNode, newIndex,
69 newFolderString); 68 newFolderString);
70 [self NotifyHandlerCreatedNode:newFolder]; 69 [self notifyHandlerCreatedNode:newFolder];
71 // Get a list of all open tabs, create nodes for them, and add 70 // Get a list of all open tabs, create nodes for them, and add
72 // to the new folder node. 71 // to the new folder node.
73 [self UpdateActiveTabPairs]; 72 [self UpdateActiveTabPairs];
74 int i = 0; 73 int i = 0;
75 for (ActiveTabsNameURLPairVector::const_iterator it = 74 for (ActiveTabsNameURLPairVector::const_iterator it =
76 activeTabPairsVector_.begin(); 75 activeTabPairsVector_.begin();
77 it != activeTabPairsVector_.end(); ++it, ++i) { 76 it != activeTabPairsVector_.end(); ++it, ++i) {
78 const BookmarkNode* node = model->AddURL(newFolder, i, 77 const BookmarkNode* node = model->AddURL(newFolder, i,
79 it->first, it->second); 78 it->first, it->second);
80 [self NotifyHandlerCreatedNode:node]; 79 [self notifyHandlerCreatedNode:node];
81 } 80 }
82 [super ok:sender]; 81 return [NSNumber numberWithBool:YES];
83 } 82 }
84 83
85 - (ActiveTabsNameURLPairVector*)activeTabPairsVector { 84 - (ActiveTabsNameURLPairVector*)activeTabPairsVector {
86 return &activeTabPairsVector_; 85 return &activeTabPairsVector_;
87 } 86 }
88 87
89 @end // BookmarkAllTabsController 88 @end // BookmarkAllTabsController
90 89
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