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

Side by Side Diff: chrome/browser/undo/undo_manager.cc

Issue 19287013: Bookmark Undo service for multiple level undo/redo of bookmarks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
OLDNEW
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/undo_manager.h" 5 #include "chrome/browser/undo/undo_manager.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/browser/undo/undo_operation.h" 9 #include "chrome/browser/undo/undo_operation.h"
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 void UndoManager::Undo() { 46 void UndoManager::Undo() {
47 Undo(&performing_undo_, &undo_actions_); 47 Undo(&performing_undo_, &undo_actions_);
48 } 48 }
49 49
50 void UndoManager::Redo() { 50 void UndoManager::Redo() {
51 Undo(&performing_redo_, &redo_actions_); 51 Undo(&performing_redo_, &redo_actions_);
52 } 52 }
53 53
54 void UndoManager::AddUndoOperation(scoped_ptr<UndoOperation> operation) { 54 void UndoManager::AddUndoOperation(scoped_ptr<UndoOperation> operation) {
sky 2013/07/18 14:35:41 Can you add a max count to this class (you can cre
Tom Cassiotis 2013/07/24 15:37:56 Good idea! I'll get a quick patch for this change
55 if (IsUndoTrakingSuspended()) { 55 if (IsUndoTrakingSuspended()) {
56 RemoveAllActions(); 56 Reset();
57 operation.reset(); 57 operation.reset();
58 return; 58 return;
59 } 59 }
60 60
61 if (group_actions_count_) { 61 if (group_actions_count_) {
62 pending_grouped_action_->AddOperation(operation.Pass()); 62 pending_grouped_action_->AddOperation(operation.Pass());
63 } else { 63 } else {
64 UndoGroup* new_action = new UndoGroup(); 64 UndoGroup* new_action = new UndoGroup();
65 new_action->AddOperation(operation.Pass()); 65 new_action->AddOperation(operation.Pass());
66 GetActiveUndoGroup()->insert(GetActiveUndoGroup()->end(), new_action); 66 GetActiveUndoGroup()->insert(GetActiveUndoGroup()->end(), new_action);
67 67
68 // A new user action invalidates any available redo actions. 68 if (is_user_action())
69 RemoveAllRedoActions(); 69 RemoveAllRedoActions();
70 } 70 }
71 } 71 }
72 72
73 void UndoManager::StartGroupingActions() { 73 void UndoManager::StartGroupingActions() {
74 if (!group_actions_count_) 74 if (!group_actions_count_)
75 pending_grouped_action_.reset(new UndoGroup()); 75 pending_grouped_action_.reset(new UndoGroup());
76 ++group_actions_count_; 76 ++group_actions_count_;
77 } 77 }
78 78
79 void UndoManager::EndGroupingActions() { 79 void UndoManager::EndGroupingActions() {
80 --group_actions_count_; 80 --group_actions_count_;
81 if (group_actions_count_ > 0) 81 if (group_actions_count_ > 0)
82 return; 82 return;
83 83
84 // Check that StartGroupingActions and EndGroupingActions are paired. 84 // Check that StartGroupingActions and EndGroupingActions are paired.
85 DCHECK_GE(group_actions_count_, 0); 85 DCHECK_GE(group_actions_count_, 0);
86 86
87 bool is_user_action = !performing_undo_ && !performing_redo_;
88 if (pending_grouped_action_->has_operations()) { 87 if (pending_grouped_action_->has_operations()) {
89 GetActiveUndoGroup()->push_back(pending_grouped_action_.release()); 88 GetActiveUndoGroup()->push_back(pending_grouped_action_.release());
90 // User actions invalidate any available redo actions. 89 // User actions invalidate any available redo actions.
91 if (is_user_action) 90 if (is_user_action())
92 RemoveAllRedoActions(); 91 RemoveAllRedoActions();
93 } else { 92 } else {
94 // No changes were executed since we started grouping actions, so the 93 // No changes were executed since we started grouping actions, so the
95 // pending UndoGroup should be discarded. 94 // pending UndoGroup should be discarded.
96 pending_grouped_action_.reset(); 95 pending_grouped_action_.reset();
97 96
98 // This situation is only expected when it is a user initiated action. 97 // This situation is only expected when it is a user initiated action.
99 // Undo/Redo should have at least one operation performed. 98 // Undo/Redo should have at least one operation performed.
100 DCHECK(is_user_action); 99 DCHECK(is_user_action());
101 } 100 }
102 } 101 }
103 102
104 void UndoManager::SuspendUndoTracking() { 103 void UndoManager::SuspendUndoTracking() {
105 ++undo_suspended_count_; 104 ++undo_suspended_count_;
106 } 105 }
107 106
108 void UndoManager::ResumeUndoTracking() { 107 void UndoManager::ResumeUndoTracking() {
109 DCHECK_GT(undo_suspended_count_, 0); 108 DCHECK_GT(undo_suspended_count_, 0);
110 --undo_suspended_count_; 109 --undo_suspended_count_;
(...skipping 14 matching lines...) Expand all
125 base::AutoReset<bool> incoming_changes(performing_indicator, true); 124 base::AutoReset<bool> incoming_changes(performing_indicator, true);
126 scoped_ptr<UndoGroup> action(active_undo_group->back()); 125 scoped_ptr<UndoGroup> action(active_undo_group->back());
127 active_undo_group->weak_erase( 126 active_undo_group->weak_erase(
128 active_undo_group->begin() + active_undo_group->size() - 1); 127 active_undo_group->begin() + active_undo_group->size() - 1);
129 128
130 StartGroupingActions(); 129 StartGroupingActions();
131 action->Undo(); 130 action->Undo();
132 EndGroupingActions(); 131 EndGroupingActions();
133 } 132 }
134 133
135 void UndoManager::RemoveAllActions() { 134 void UndoManager::Reset() {
136 undo_actions_.clear(); 135 undo_actions_.clear();
137 RemoveAllRedoActions(); 136 RemoveAllRedoActions();
138 } 137 }
139 138
140 void UndoManager::RemoveAllRedoActions() { 139 void UndoManager::RemoveAllRedoActions() {
141 redo_actions_.clear(); 140 redo_actions_.clear();
142 } 141 }
143 142
144 ScopedVector<UndoGroup>* UndoManager::GetActiveUndoGroup() { 143 ScopedVector<UndoGroup>* UndoManager::GetActiveUndoGroup() {
145 return performing_undo_ ? &redo_actions_ : &undo_actions_; 144 return performing_undo_ ? &redo_actions_ : &undo_actions_;
146 } 145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698