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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UNDO_UNDO_MANAGER_H_
6 #define CHROME_BROWSER_UNDO_UNDO_MANAGER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/strings/string16.h"
15 // UndoGroup ------------------------------------------------------------------
17 // UndoGroup represents a user action and stores all the operations that
18 // make that action. Typically there is only one operation per UndoGroup.
24 void AddOperation(scoped_ptr
<UndoOperation
> operation
);
25 const std::vector
<UndoOperation
*>& undo_operations() {
26 return operations_
.get();
30 // The resource string id describing the undo and redo action.
31 int get_undo_label_id() const { return undo_label_id_
; }
32 void set_undo_label_id(int label_id
) { undo_label_id_
= label_id
; }
34 int get_redo_label_id() const { return redo_label_id_
; }
35 void set_redo_label_id(int label_id
) { redo_label_id_
= label_id
; }
38 ScopedVector
<UndoOperation
> operations_
;
40 // The resource string id describing the undo and redo action.
44 DISALLOW_COPY_AND_ASSIGN(UndoGroup
);
47 // UndoManager ----------------------------------------------------------------
49 // Maintains user actions as a group of operations that store enough info to
50 // undo and redo those operations.
56 // Perform an undo or redo operation.
60 size_t undo_count() const { return undo_actions_
.size(); }
61 size_t redo_count() const { return redo_actions_
.size(); }
63 base::string16
GetUndoLabel() const;
64 base::string16
GetRedoLabel() const;
66 void AddUndoOperation(scoped_ptr
<UndoOperation
> operation
);
68 // Group multiple operations into one undoable action.
69 void StartGroupingActions();
70 void EndGroupingActions();
72 // Suspend undo tracking while processing non-user initiated changes such as
73 // profile synchonization.
74 void SuspendUndoTracking();
75 void ResumeUndoTracking();
76 bool IsUndoTrakingSuspended() const;
78 // Returns all UndoOperations that are awaiting Undo or Redo. Note that
79 // ownership of the UndoOperations is retained by UndoManager.
80 std::vector
<UndoOperation
*> GetAllUndoOperations() const;
82 // Remove all undo and redo operations. Note that grouping of actions and
83 // suspension of undo tracking states are left unchanged.
84 void RemoveAllOperations();
87 void Undo(bool* performing_indicator
,
88 ScopedVector
<UndoGroup
>* active_undo_group
);
89 bool is_user_action() const { return !performing_undo_
&& !performing_redo_
; }
91 // Handle the addition of |new_undo_group| to the active undo group container.
92 void AddUndoGroup(UndoGroup
* new_undo_group
);
94 // Returns the undo or redo UndoGroup container that should store the next
95 // change taking into account if an undo or redo is being executed.
96 ScopedVector
<UndoGroup
>* GetActiveUndoGroup();
98 // Containers of user actions ready for an undo or redo treated as a stack.
99 ScopedVector
<UndoGroup
> undo_actions_
;
100 ScopedVector
<UndoGroup
> redo_actions_
;
102 // Supports grouping operations into a single undo action.
103 int group_actions_count_
;
105 // The container that is used when actions are grouped.
106 scoped_ptr
<UndoGroup
> pending_grouped_action_
;
108 // The action that is in the process of being undone.
109 UndoGroup
* undo_in_progress_action_
;
111 // Supports the suspension of undo tracking.
112 int undo_suspended_count_
;
114 // Set when executing Undo or Redo so that incoming changes are correctly
116 bool performing_undo_
;
117 bool performing_redo_
;
119 DISALLOW_COPY_AND_ASSIGN(UndoManager
);
122 #endif // CHROME_BROWSER_UNDO_UNDO_MANAGER_H_