| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/undo/bookmark_undo_service.h" | 5 #include "chrome/browser/undo/bookmark_undo_service.h" |
| 6 | 6 |
| 7 #include "chrome/browser/bookmarks/bookmark_model.h" | 7 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 9 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_utils.h" | 10 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 BookmarkAddOperation::BookmarkAddOperation(Profile* profile, | 74 BookmarkAddOperation::BookmarkAddOperation(Profile* profile, |
| 75 const BookmarkNode* parent, | 75 const BookmarkNode* parent, |
| 76 int index) | 76 int index) |
| 77 : BookmarkUndoOperation(profile), | 77 : BookmarkUndoOperation(profile), |
| 78 parent_id_(parent->id()), | 78 parent_id_(parent->id()), |
| 79 index_(index) { | 79 index_(index) { |
| 80 } | 80 } |
| 81 | 81 |
| 82 void BookmarkAddOperation::Undo() { | 82 void BookmarkAddOperation::Undo() { |
| 83 BookmarkModel* model = GetBookmarkModel(); | 83 BookmarkModel* model = GetBookmarkModel(); |
| 84 const BookmarkNode* parent = model->GetNodeByID(parent_id_); | 84 const BookmarkNode* parent = GetBookmarkNodeByID(model, parent_id_); |
| 85 DCHECK(parent); | 85 DCHECK(parent); |
| 86 | 86 |
| 87 model->Remove(parent, index_); | 87 model->Remove(parent, index_); |
| 88 } | 88 } |
| 89 | 89 |
| 90 int BookmarkAddOperation::GetUndoLabelId() const { | 90 int BookmarkAddOperation::GetUndoLabelId() const { |
| 91 return IDS_BOOKMARK_BAR_UNDO_ADD; | 91 return IDS_BOOKMARK_BAR_UNDO_ADD; |
| 92 } | 92 } |
| 93 | 93 |
| 94 int BookmarkAddOperation::GetRedoLabelId() const { | 94 int BookmarkAddOperation::GetRedoLabelId() const { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 const BookmarkNode* node) | 140 const BookmarkNode* node) |
| 141 : BookmarkUndoOperation(profile), | 141 : BookmarkUndoOperation(profile), |
| 142 parent_id_(parent->id()), | 142 parent_id_(parent->id()), |
| 143 old_index_(old_index), | 143 old_index_(old_index), |
| 144 removed_node_(node) { | 144 removed_node_(node) { |
| 145 } | 145 } |
| 146 | 146 |
| 147 void BookmarkRemoveOperation::Undo() { | 147 void BookmarkRemoveOperation::Undo() { |
| 148 DCHECK(removed_node_.is_valid()); | 148 DCHECK(removed_node_.is_valid()); |
| 149 BookmarkModel* model = GetBookmarkModel(); | 149 BookmarkModel* model = GetBookmarkModel(); |
| 150 const BookmarkNode* parent = model->GetNodeByID(parent_id_); | 150 const BookmarkNode* parent = GetBookmarkNodeByID(model, parent_id_); |
| 151 DCHECK(parent); | 151 DCHECK(parent); |
| 152 | 152 |
| 153 bookmark_utils::CloneBookmarkNode(model, removed_node_.elements, parent, | 153 bookmark_utils::CloneBookmarkNode(model, removed_node_.elements, parent, |
| 154 old_index_, false); | 154 old_index_, false); |
| 155 UpdateBookmarkIds(removed_node_.elements[0], parent, old_index_); | 155 UpdateBookmarkIds(removed_node_.elements[0], parent, old_index_); |
| 156 } | 156 } |
| 157 | 157 |
| 158 int BookmarkRemoveOperation::GetUndoLabelId() const { | 158 int BookmarkRemoveOperation::GetUndoLabelId() const { |
| 159 return IDS_BOOKMARK_BAR_UNDO_DELETE; | 159 return IDS_BOOKMARK_BAR_UNDO_DELETE; |
| 160 } | 160 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 BookmarkEditOperation::BookmarkEditOperation(Profile* profile, | 208 BookmarkEditOperation::BookmarkEditOperation(Profile* profile, |
| 209 const BookmarkNode* node) | 209 const BookmarkNode* node) |
| 210 : BookmarkUndoOperation(profile), | 210 : BookmarkUndoOperation(profile), |
| 211 node_id_(node->id()), | 211 node_id_(node->id()), |
| 212 original_bookmark_(node) { | 212 original_bookmark_(node) { |
| 213 } | 213 } |
| 214 | 214 |
| 215 void BookmarkEditOperation::Undo() { | 215 void BookmarkEditOperation::Undo() { |
| 216 DCHECK(original_bookmark_.is_valid()); | 216 DCHECK(original_bookmark_.is_valid()); |
| 217 BookmarkModel* model = GetBookmarkModel(); | 217 BookmarkModel* model = GetBookmarkModel(); |
| 218 const BookmarkNode* node = model->GetNodeByID(node_id_); | 218 const BookmarkNode* node = GetBookmarkNodeByID(model, node_id_); |
| 219 DCHECK(node); | 219 DCHECK(node); |
| 220 | 220 |
| 221 model->SetTitle(node, original_bookmark_.elements[0].title); | 221 model->SetTitle(node, original_bookmark_.elements[0].title); |
| 222 if (original_bookmark_.elements[0].is_url) | 222 if (original_bookmark_.elements[0].is_url) |
| 223 model->SetURL(node, original_bookmark_.elements[0].url); | 223 model->SetURL(node, original_bookmark_.elements[0].url); |
| 224 } | 224 } |
| 225 | 225 |
| 226 int BookmarkEditOperation::GetUndoLabelId() const { | 226 int BookmarkEditOperation::GetUndoLabelId() const { |
| 227 return IDS_BOOKMARK_BAR_UNDO_EDIT; | 227 return IDS_BOOKMARK_BAR_UNDO_EDIT; |
| 228 } | 228 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 int new_index) | 272 int new_index) |
| 273 : BookmarkUndoOperation(profile), | 273 : BookmarkUndoOperation(profile), |
| 274 old_parent_id_(old_parent->id()), | 274 old_parent_id_(old_parent->id()), |
| 275 new_parent_id_(new_parent->id()), | 275 new_parent_id_(new_parent->id()), |
| 276 old_index_(old_index), | 276 old_index_(old_index), |
| 277 new_index_(new_index) { | 277 new_index_(new_index) { |
| 278 } | 278 } |
| 279 | 279 |
| 280 void BookmarkMoveOperation::Undo() { | 280 void BookmarkMoveOperation::Undo() { |
| 281 BookmarkModel* model = GetBookmarkModel(); | 281 BookmarkModel* model = GetBookmarkModel(); |
| 282 const BookmarkNode* old_parent = model->GetNodeByID(old_parent_id_); | 282 const BookmarkNode* old_parent = GetBookmarkNodeByID(model, old_parent_id_); |
| 283 const BookmarkNode* new_parent = model->GetNodeByID(new_parent_id_); | 283 const BookmarkNode* new_parent = GetBookmarkNodeByID(model, new_parent_id_); |
| 284 DCHECK(old_parent); | 284 DCHECK(old_parent); |
| 285 DCHECK(new_parent); | 285 DCHECK(new_parent); |
| 286 | 286 |
| 287 const BookmarkNode* node = new_parent->GetChild(new_index_); | 287 const BookmarkNode* node = new_parent->GetChild(new_index_); |
| 288 int destination_index = old_index_; | 288 int destination_index = old_index_; |
| 289 | 289 |
| 290 // If the bookmark was moved up within the same parent then the destination | 290 // If the bookmark was moved up within the same parent then the destination |
| 291 // index needs to be incremented since the old index did not account for the | 291 // index needs to be incremented since the old index did not account for the |
| 292 // moved bookmark. | 292 // moved bookmark. |
| 293 if (old_parent == new_parent && new_index_ < old_index_) | 293 if (old_parent == new_parent && new_index_ < old_index_) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 ordered_bookmarks_.resize(parent->child_count()); | 345 ordered_bookmarks_.resize(parent->child_count()); |
| 346 for (int i = 0; i < parent->child_count(); ++i) | 346 for (int i = 0; i < parent->child_count(); ++i) |
| 347 ordered_bookmarks_[i] = parent->GetChild(i)->id(); | 347 ordered_bookmarks_[i] = parent->GetChild(i)->id(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 BookmarkReorderOperation::~BookmarkReorderOperation() { | 350 BookmarkReorderOperation::~BookmarkReorderOperation() { |
| 351 } | 351 } |
| 352 | 352 |
| 353 void BookmarkReorderOperation::Undo() { | 353 void BookmarkReorderOperation::Undo() { |
| 354 BookmarkModel* model = GetBookmarkModel(); | 354 BookmarkModel* model = GetBookmarkModel(); |
| 355 const BookmarkNode* parent = model->GetNodeByID(parent_id_); | 355 const BookmarkNode* parent = GetBookmarkNodeByID(model, parent_id_); |
| 356 DCHECK(parent); | 356 DCHECK(parent); |
| 357 | 357 |
| 358 std::vector<const BookmarkNode*> ordered_nodes; | 358 std::vector<const BookmarkNode*> ordered_nodes; |
| 359 for (size_t i = 0; i < ordered_bookmarks_.size(); ++i) | 359 for (size_t i = 0; i < ordered_bookmarks_.size(); ++i) |
| 360 ordered_nodes.push_back(model->GetNodeByID(ordered_bookmarks_[i])); | 360 ordered_nodes.push_back(GetBookmarkNodeByID(model, ordered_bookmarks_[i])); |
| 361 | 361 |
| 362 model->ReorderChildren(parent, ordered_nodes); | 362 model->ReorderChildren(parent, ordered_nodes); |
| 363 } | 363 } |
| 364 | 364 |
| 365 int BookmarkReorderOperation::GetUndoLabelId() const { | 365 int BookmarkReorderOperation::GetUndoLabelId() const { |
| 366 return IDS_BOOKMARK_BAR_UNDO_REORDER; | 366 return IDS_BOOKMARK_BAR_UNDO_REORDER; |
| 367 } | 367 } |
| 368 | 368 |
| 369 int BookmarkReorderOperation::GetRedoLabelId() const { | 369 int BookmarkReorderOperation::GetRedoLabelId() const { |
| 370 return IDS_BOOKMARK_BAR_REDO_REORDER; | 370 return IDS_BOOKMARK_BAR_REDO_REORDER; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 | 468 |
| 469 void BookmarkUndoService::OnBookmarkRenumbered(int64 old_id, int64 new_id) { | 469 void BookmarkUndoService::OnBookmarkRenumbered(int64 old_id, int64 new_id) { |
| 470 std::vector<UndoOperation*> all_operations = | 470 std::vector<UndoOperation*> all_operations = |
| 471 undo_manager()->GetAllUndoOperations(); | 471 undo_manager()->GetAllUndoOperations(); |
| 472 for (std::vector<UndoOperation*>::iterator it = all_operations.begin(); | 472 for (std::vector<UndoOperation*>::iterator it = all_operations.begin(); |
| 473 it != all_operations.end(); ++it) { | 473 it != all_operations.end(); ++it) { |
| 474 static_cast<BookmarkUndoOperation*>(*it)->OnBookmarkRenumbered(old_id, | 474 static_cast<BookmarkUndoOperation*>(*it)->OnBookmarkRenumbered(old_id, |
| 475 new_id); | 475 new_id); |
| 476 } | 476 } |
| 477 } | 477 } |
| OLD | NEW |