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

Side by Side Diff: chrome/browser/bookmarks/bookmark_table_model.cc

Issue 27262: Wires up sorting of bookmarks to the 'organize menu' in the bookmark... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 9 months 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/bookmarks/bookmark_table_model.h" 5 #include "chrome/browser/bookmarks/bookmark_table_model.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 // FolderBookmarkTableModel is a TableModel implementation backed by the 79 // FolderBookmarkTableModel is a TableModel implementation backed by the
80 // contents of a bookmark folder. FolderBookmarkTableModel caches the contents 80 // contents of a bookmark folder. FolderBookmarkTableModel caches the contents
81 // of the folder so that it can send out the correct events when a bookmark 81 // of the folder so that it can send out the correct events when a bookmark
82 // node is moved. 82 // node is moved.
83 class FolderBookmarkTableModel : public VectorBackedBookmarkTableModel { 83 class FolderBookmarkTableModel : public VectorBackedBookmarkTableModel {
84 public: 84 public:
85 FolderBookmarkTableModel(BookmarkModel* model, BookmarkNode* root_node) 85 FolderBookmarkTableModel(BookmarkModel* model, BookmarkNode* root_node)
86 : VectorBackedBookmarkTableModel(model), 86 : VectorBackedBookmarkTableModel(model),
87 root_node_(root_node) { 87 root_node_(root_node) {
88 for (int i = 0; i < root_node->GetChildCount(); ++i) 88 PopulateNodesFromRoot();
89 nodes().push_back(root_node->GetChild(i));
90 } 89 }
91 90
92 virtual void BookmarkNodeMoved(BookmarkModel* model, 91 virtual void BookmarkNodeMoved(BookmarkModel* model,
93 BookmarkNode* old_parent, 92 BookmarkNode* old_parent,
94 int old_index, 93 int old_index,
95 BookmarkNode* new_parent, 94 BookmarkNode* new_parent,
96 int new_index) { 95 int new_index) {
97 if (old_parent == root_node_) { 96 if (old_parent == root_node_) {
98 nodes().erase(nodes().begin() + old_index); 97 nodes().erase(nodes().begin() + old_index);
99 if (observer()) 98 if (observer())
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 virtual void BookmarkNodeChanged(BookmarkModel* model, 138 virtual void BookmarkNodeChanged(BookmarkModel* model,
140 BookmarkNode* node) { 139 BookmarkNode* node) {
141 NotifyChanged(node); 140 NotifyChanged(node);
142 } 141 }
143 142
144 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, 143 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
145 BookmarkNode* node) { 144 BookmarkNode* node) {
146 NotifyChanged(node); 145 NotifyChanged(node);
147 } 146 }
148 147
148 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
149 BookmarkNode* node) {
150 if (node != root_node_)
151 return;
152
153 nodes().clear();
154 PopulateNodesFromRoot();
155
156 if (observer())
157 observer()->OnModelChanged();
158 }
159
149 private: 160 private:
150 void NotifyChanged(BookmarkNode* node) { 161 void NotifyChanged(BookmarkNode* node) {
151 if (node->GetParent() == root_node_ && observer()) 162 if (node->GetParent() == root_node_ && observer())
152 observer()->OnItemsChanged(node->GetParent()->IndexOfChild(node), 1); 163 observer()->OnItemsChanged(node->GetParent()->IndexOfChild(node), 1);
153 } 164 }
154 165
166 void PopulateNodesFromRoot() {
167 for (int i = 0; i < root_node_->GetChildCount(); ++i)
168 nodes().push_back(root_node_->GetChild(i));
169 }
170
155 // The node we're showing the children of. This is set to NULL if the node 171 // The node we're showing the children of. This is set to NULL if the node
156 // (or one of its ancestors) is removed from the model. 172 // (or one of its ancestors) is removed from the model.
157 BookmarkNode* root_node_; 173 BookmarkNode* root_node_;
158 174
159 DISALLOW_COPY_AND_ASSIGN(FolderBookmarkTableModel); 175 DISALLOW_COPY_AND_ASSIGN(FolderBookmarkTableModel);
160 }; 176 };
161 177
162 // RecentlyBookmarkedTableModel ------------------------------------------------ 178 // RecentlyBookmarkedTableModel ------------------------------------------------
163 179
164 class RecentlyBookmarkedTableModel : public VectorBackedBookmarkTableModel { 180 class RecentlyBookmarkedTableModel : public VectorBackedBookmarkTableModel {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 BuildPath(node->GetParent(), path); 375 BuildPath(node->GetParent(), path);
360 path->append(l10n_util::GetString(IDS_BOOKMARK_TABLE_PATH_SEPARATOR)); 376 path->append(l10n_util::GetString(IDS_BOOKMARK_TABLE_PATH_SEPARATOR));
361 // Force path to have LTR directionality. Otherwise, folder path "CBA/FED" 377 // Force path to have LTR directionality. Otherwise, folder path "CBA/FED"
362 // (in which, "CBA" and "FED" stand for folder names in Hebrew, and "FED" is 378 // (in which, "CBA" and "FED" stand for folder names in Hebrew, and "FED" is
363 // a subfolder of "CBA") will be displayed as "FED/CBA". 379 // a subfolder of "CBA") will be displayed as "FED/CBA".
364 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { 380 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
365 path->push_back(static_cast<wchar_t>(l10n_util::kLeftToRightMark)); 381 path->push_back(static_cast<wchar_t>(l10n_util::kLeftToRightMark));
366 } 382 }
367 path->append(node->GetTitle()); 383 path->append(node->GetTitle());
368 } 384 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698