OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/bookmarks/browser/bookmark_utils.h" | 5 #include "components/bookmarks/browser/bookmark_utils.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 // Create array of selected nodes with descendants filtered out. | 172 // Create array of selected nodes with descendants filtered out. |
173 std::vector<const BookmarkNode*> filtered_nodes; | 173 std::vector<const BookmarkNode*> filtered_nodes; |
174 for (size_t i = 0; i < nodes.size(); ++i) | 174 for (size_t i = 0; i < nodes.size(); ++i) |
175 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) | 175 if (!HasSelectedAncestor(model, nodes, nodes[i]->parent())) |
176 filtered_nodes.push_back(nodes[i]); | 176 filtered_nodes.push_back(nodes[i]); |
177 | 177 |
178 BookmarkNodeData(filtered_nodes). | 178 BookmarkNodeData(filtered_nodes). |
179 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); | 179 WriteToClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE); |
180 | 180 |
181 if (remove_nodes) { | 181 if (remove_nodes) { |
182 bookmarks::ScopedGroupBookmarkActions group_cut(model); | 182 ScopedGroupBookmarkActions group_cut(model); |
183 for (size_t i = 0; i < filtered_nodes.size(); ++i) { | 183 for (size_t i = 0; i < filtered_nodes.size(); ++i) { |
184 int index = filtered_nodes[i]->parent()->GetIndexOf(filtered_nodes[i]); | 184 int index = filtered_nodes[i]->parent()->GetIndexOf(filtered_nodes[i]); |
185 if (index > -1) | 185 if (index > -1) |
186 model->Remove(filtered_nodes[i]->parent(), index); | 186 model->Remove(filtered_nodes[i]->parent(), index); |
187 } | 187 } |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 void PasteFromClipboard(BookmarkModel* model, | 191 void PasteFromClipboard(BookmarkModel* model, |
192 const BookmarkNode* parent, | 192 const BookmarkNode* parent, |
193 int index) { | 193 int index) { |
194 if (!parent) | 194 if (!parent) |
195 return; | 195 return; |
196 | 196 |
197 BookmarkNodeData bookmark_data; | 197 BookmarkNodeData bookmark_data; |
198 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) | 198 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) |
199 return; | 199 return; |
200 | 200 |
201 if (index == -1) | 201 if (index == -1) |
202 index = parent->child_count(); | 202 index = parent->child_count(); |
203 bookmarks::ScopedGroupBookmarkActions group_paste(model); | 203 ScopedGroupBookmarkActions group_paste(model); |
204 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); | 204 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); |
205 } | 205 } |
206 | 206 |
207 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { | 207 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { |
208 if (!node || !model->client()->CanBeEditedByUser(node)) | 208 if (!node || !model->client()->CanBeEditedByUser(node)) |
209 return false; | 209 return false; |
210 return BookmarkNodeData::ClipboardContainsBookmarks(); | 210 return BookmarkNodeData::ClipboardContainsBookmarks(); |
211 } | 211 } |
212 | 212 |
213 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( | 213 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 437 } |
438 return false; | 438 return false; |
439 } | 439 } |
440 | 440 |
441 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 441 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
442 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 442 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
443 return GetNodeByID(model->root_node(), id); | 443 return GetNodeByID(model->root_node(), id); |
444 } | 444 } |
445 | 445 |
446 } // namespace bookmarks | 446 } // namespace bookmarks |
OLD | NEW |