yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
tree_undo_stack.cc
Go to the documentation of this file.
2
3#include <utility>
4
5namespace yaze {
6namespace editor {
7namespace layout_designer {
8
9TreeUndoStack::TreeUndoStack(std::size_t max_steps) : max_steps_(max_steps) {}
10
11void TreeUndoStack::Push(const DockTree& current) {
12 undo_.push_back(current.Clone());
13 redo_.clear();
14 if (max_steps_ > 0 && undo_.size() > max_steps_) {
15 const std::size_t excess = undo_.size() - max_steps_;
16 undo_.erase(undo_.begin(), undo_.begin() + excess);
17 }
18}
19
21 if (current == nullptr || undo_.empty())
22 return false;
23 redo_.push_back(std::move(*current));
24 *current = std::move(undo_.back());
25 undo_.pop_back();
26 return true;
27}
28
30 if (current == nullptr || redo_.empty())
31 return false;
32 undo_.push_back(std::move(*current));
33 *current = std::move(redo_.back());
34 redo_.pop_back();
35 return true;
36}
37
39 if (undo_.empty())
40 return;
41 undo_.pop_back();
42}
43
45 undo_.clear();
46 redo_.clear();
47}
48
49} // namespace layout_designer
50} // namespace editor
51} // namespace yaze
TreeUndoStack(std::size_t max_steps=kDefaultMaxSteps)