Enzo
Loading...
Searching...
No Matches
UndoStack.h
1#pragma once
2
3#include "Engine/UndoRedo/UndoCommand.h"
4#include "Engine/UndoRedo/UndoGroup.h"
5#include <memory>
6#include <vector>
7
8namespace enzo::nt {
9
11{
12 public:
14 void push(std::unique_ptr<UndoCommand> command);
15 void undo();
16 void redo();
17 bool canUndo() const;
18 bool canRedo() const;
19 void clear();
20
22 void beginGroup();
23
25 void endGroup();
26
27 private:
28 std::vector<std::unique_ptr<UndoCommand>> commands_;
29 std::vector<std::unique_ptr<UndoGroup>> openGroups_;
30 int currentIndex_ = 0;
31};
32
35{
36 public:
37 explicit UndoTransaction(UndoStack& stack) : stack_(stack) { stack_.beginGroup(); }
38 ~UndoTransaction() { stack_.endGroup(); }
39
40 UndoTransaction(const UndoTransaction&) = delete;
41 UndoTransaction& operator=(const UndoTransaction&) = delete;
42
43 private:
44 UndoStack& stack_;
45};
46
47} // namespace enzo::nt
Definition UndoStack.h:11
void endGroup()
Closes the innermost transaction, recording its commands as a single group.
Definition UndoStack.cpp:25
void push(std::unique_ptr< UndoCommand > command)
Records a command, or folds it into the open group during a transaction.
Definition UndoStack.cpp:6
void beginGroup()
Opens a transaction so subsequent pushes collect into one atomic group.
Definition UndoStack.cpp:23
RAII helper that opens an undo group for the duration of its scope.
Definition UndoStack.h:35