yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
command_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SYSTEM_COMMAND_MANAGER_H
2#define YAZE_APP_EDITOR_SYSTEM_COMMAND_MANAGER_H
3
4#include <string>
5#include <unordered_map>
6
7namespace yaze {
8namespace app {
9namespace editor {
10
11class Command {
12 public:
13 virtual ~Command() = default;
14 virtual void Execute() = 0;
15};
16
18 public:
19 void RegisterCommand(const std::string& shortcut, Command* command) {
20 commands_[shortcut] = command;
21 }
22
23 void ExecuteCommand(const std::string& shortcut) {
24 if (commands_.find(shortcut) != commands_.end()) {
25 commands_[shortcut]->Execute();
26 }
27 }
28
29 void Undo() {
30 if (!undo_stack_.empty()) {
31 undo_stack_.top()->Execute();
32 redo_stack_.push(undo_stack_.top());
33 undo_stack_.pop();
34 }
35 }
36
37 void Redo() {
38 if (!redo_stack_.empty()) {
39 redo_stack_.top()->Execute();
40 undo_stack_.push(redo_stack_.top());
41 redo_stack_.pop();
42 }
43 }
44
45 private:
46 std::stack<Command*> undo_stack_;
47 std::stack<Command*> redo_stack_;
48 std::unordered_map<std::string, Command*> commands_;
49};
50
51} // namespace editor
52} // namespace app
53} // namespace yaze
std::unordered_map< std::string, Command * > commands_
std::stack< Command * > redo_stack_
void RegisterCommand(const std::string &shortcut, Command *command)
void ExecuteCommand(const std::string &shortcut)
std::stack< Command * > undo_stack_
virtual ~Command()=default
virtual void Execute()=0
Definition common.cc:21