From 5879138e93b840db1e29e6dd5f7adec4b8ee34fd Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 25 Aug 2024 00:12:04 -0400 Subject: [PATCH] Refactor CommandManager to support undo and redo functionality --- src/app/editor/system/command_manager.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/app/editor/system/command_manager.h b/src/app/editor/system/command_manager.h index 4a36397b..c1dcb046 100644 --- a/src/app/editor/system/command_manager.h +++ b/src/app/editor/system/command_manager.h @@ -26,7 +26,25 @@ class CommandManager { } } + void Undo() { + if (!undo_stack_.empty()) { + undo_stack_.top()->Execute(); + redo_stack_.push(undo_stack_.top()); + undo_stack_.pop(); + } + } + + void Redo() { + if (!redo_stack_.empty()) { + redo_stack_.top()->Execute(); + undo_stack_.push(redo_stack_.top()); + redo_stack_.pop(); + } + } + private: + std::stack undo_stack_; + std::stack redo_stack_; std::unordered_map commands_; };