yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
undo_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_CORE_UNDO_MANAGER_H_
2#define YAZE_APP_EDITOR_CORE_UNDO_MANAGER_H_
3
4#include <cstddef>
5#include <deque>
6#include <memory>
7#include <string>
8
9#include "absl/status/status.h"
11
12namespace yaze {
13namespace editor {
14
24 public:
25 UndoManager() = default;
26 ~UndoManager() = default;
27
28 // Non-copyable, movable
29 UndoManager(const UndoManager&) = delete;
33
36 void Push(std::unique_ptr<UndoAction> action);
37
39 absl::Status Undo();
40
42 absl::Status Redo();
43
44 bool CanUndo() const { return !undo_stack_.empty(); }
45 bool CanRedo() const { return !redo_stack_.empty(); }
46
48 std::string GetUndoDescription() const;
49
51 std::string GetRedoDescription() const;
52
53 void SetMaxStackSize(size_t max) { max_stack_size_ = max; }
54 size_t GetMaxStackSize() const { return max_stack_size_; }
55
56 size_t UndoStackSize() const { return undo_stack_.size(); }
57 size_t RedoStackSize() const { return redo_stack_.size(); }
58
59 void Clear();
60
61 private:
62 void EnforceStackLimit();
63
64 std::deque<std::unique_ptr<UndoAction>> undo_stack_;
65 std::deque<std::unique_ptr<UndoAction>> redo_stack_;
66 size_t max_stack_size_ = 50;
67};
68
69} // namespace editor
70} // namespace yaze
71
72#endif // YAZE_APP_EDITOR_CORE_UNDO_MANAGER_H_
Manages undo/redo stacks for a single editor.
void Push(std::unique_ptr< UndoAction > action)
UndoManager(UndoManager &&)=default
absl::Status Redo()
Redo the top action. Returns error if stack is empty.
void SetMaxStackSize(size_t max)
std::string GetRedoDescription() const
Description of the action that would be redone (for UI)
std::deque< std::unique_ptr< UndoAction > > redo_stack_
size_t GetMaxStackSize() const
std::string GetUndoDescription() const
Description of the action that would be undone (for UI)
UndoManager & operator=(const UndoManager &)=delete
size_t RedoStackSize() const
absl::Status Undo()
Undo the top action. Returns error if stack is empty.
size_t UndoStackSize() const
std::deque< std::unique_ptr< UndoAction > > undo_stack_
UndoManager & operator=(UndoManager &&)=default
UndoManager(const UndoManager &)=delete