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" |
11 #include "base/i18n/case_conversion.h" | 11 #include "base/i18n/case_conversion.h" |
12 #include "base/i18n/string_search.h" | 12 #include "base/i18n/string_search.h" |
13 #include "base/metrics/user_metrics_action.h" | 13 #include "base/metrics/user_metrics_action.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "components/bookmarks/browser/bookmark_client.h" | 18 #include "components/bookmarks/browser/bookmark_client.h" |
18 #include "components/bookmarks/browser/bookmark_model.h" | 19 #include "components/bookmarks/browser/bookmark_model.h" |
19 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" | 20 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" |
20 #include "components/bookmarks/common/bookmark_pref_names.h" | 21 #include "components/bookmarks/common/bookmark_pref_names.h" |
21 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
22 #include "components/query_parser/query_parser.h" | 23 #include "components/query_parser/query_parser.h" |
23 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
24 #include "ui/base/models/tree_node_iterator.h" | 25 #include "ui/base/models/tree_node_iterator.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 if (!parent) | 195 if (!parent) |
195 return; | 196 return; |
196 | 197 |
197 BookmarkNodeData bookmark_data; | 198 BookmarkNodeData bookmark_data; |
198 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) | 199 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) |
199 return; | 200 return; |
200 | 201 |
201 if (index == -1) | 202 if (index == -1) |
202 index = parent->child_count(); | 203 index = parent->child_count(); |
203 ScopedGroupBookmarkActions group_paste(model); | 204 ScopedGroupBookmarkActions group_paste(model); |
| 205 |
| 206 if (bookmark_data.elements.size() == 1 && |
| 207 model->IsBookmarked(bookmark_data.elements[0].url)) { |
| 208 std::vector<const BookmarkNode*> nodes; |
| 209 std::vector<base::string16> titles; |
| 210 std::vector<base::string16>::iterator it; |
| 211 base::string16 new_title = bookmark_data.elements[0].title; |
| 212 model->GetNodesByURLAndTitle(bookmark_data.elements[0].url, |
| 213 bookmark_data.elements[0].title, |
| 214 parent, |
| 215 &nodes, |
| 216 &titles); |
| 217 size_t i = 0; |
| 218 it = std::find(titles.begin(), titles.end(), new_title); |
| 219 if (it == titles.end()) { |
| 220 new_title = bookmark_data.elements[0].title; |
| 221 } else { |
| 222 for (i = 0; i < nodes.size(); i++) { |
| 223 new_title = bookmark_data.elements[0].title + base::UTF8ToUTF16("(") + |
| 224 base::IntToString16(i + 1) + base::UTF8ToUTF16(")"); |
| 225 it = std::find(titles.begin(), titles.end(), new_title); |
| 226 if (it == titles.end()) |
| 227 break; |
| 228 } |
| 229 } |
| 230 bookmark_data.elements[0].title = new_title; |
| 231 } |
204 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); | 232 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); |
205 } | 233 } |
206 | 234 |
207 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { | 235 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { |
208 if (!node || !model->client()->CanBeEditedByUser(node)) | 236 if (!node || !model->client()->CanBeEditedByUser(node)) |
209 return false; | 237 return false; |
210 return BookmarkNodeData::ClipboardContainsBookmarks(); | 238 return BookmarkNodeData::ClipboardContainsBookmarks(); |
211 } | 239 } |
212 | 240 |
213 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( | 241 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 465 } |
438 return false; | 466 return false; |
439 } | 467 } |
440 | 468 |
441 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 469 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
442 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 470 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
443 return GetNodeByID(model->root_node(), id); | 471 return GetNodeByID(model->root_node(), id); |
444 } | 472 } |
445 | 473 |
446 } // namespace bookmarks | 474 } // namespace bookmarks |
OLD | NEW |