yaze 0.2.2
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 <functional>
5#include <string>
6#include <unordered_map>
7
8#include "imgui/imgui.h"
9
10namespace yaze {
11namespace editor {
12
13ImGuiKey MapKeyToImGuiKey(char key);
14
16 public:
17 CommandManager() = default;
18 ~CommandManager() = default;
19
20 using Command = std::function<void()>;
21
22 struct CommandInfo {
25 std::string name;
26 std::string desc;
27 CommandInfo(Command command, char mnemonic, const std::string &name,
28 const std::string &desc)
29 : command(std::move(command)),
31 name(name),
32 desc(desc) {}
33 CommandInfo() = default;
34 };
35
36 // New command info which supports subsections of commands
39 std::unordered_map<std::string, CommandInfoOrPrefix> subcommands;
43 };
44
45 void RegisterPrefix(const std::string &group_name, const char prefix,
46 const std::string &name, const std::string &desc) {
47 commands_[group_name].command_info = {nullptr, prefix, name, desc};
48 }
49
50 void RegisterSubcommand(const std::string &group_name,
51 const std::string &shortcut, const char mnemonic,
52 const std::string &name, const std::string &desc,
53 Command command) {
54 commands_[group_name].subcommands[shortcut].command_info = {
55 command, mnemonic, name, desc};
56 }
57
58 void RegisterCommand(const std::string &shortcut, Command command,
59 char mnemonic, const std::string &name,
60 const std::string &desc) {
61 commands_[shortcut].command_info = {std::move(command), mnemonic, name,
62 desc};
63 }
64
65 void ExecuteCommand(const std::string &shortcut) {
66 if (commands_.find(shortcut) != commands_.end()) {
67 commands_[shortcut].command_info.command();
68 }
69 }
70
71 void ShowWhichKey();
72
73 void SaveKeybindings(const std::string &filepath);
74 void LoadKeybindings(const std::string &filepath);
75
76 private:
77 std::unordered_map<std::string, CommandInfoOrPrefix> commands_;
78};
79
80} // namespace editor
81} // namespace yaze
82
83#endif // YAZE_APP_EDITOR_SYSTEM_COMMAND_MANAGER_H
void RegisterSubcommand(const std::string &group_name, const std::string &shortcut, const char mnemonic, const std::string &name, const std::string &desc, Command command)
std::unordered_map< std::string, CommandInfoOrPrefix > commands_
void LoadKeybindings(const std::string &filepath)
std::function< void()> Command
void ExecuteCommand(const std::string &shortcut)
void SaveKeybindings(const std::string &filepath)
void RegisterCommand(const std::string &shortcut, Command command, char mnemonic, const std::string &name, const std::string &desc)
void RegisterPrefix(const std::string &group_name, const char prefix, const std::string &name, const std::string &desc)
Editors are the view controllers for the application.
ImGuiKey MapKeyToImGuiKey(char key)
Main namespace for the application.
Definition controller.cc:18
std::unordered_map< std::string, CommandInfoOrPrefix > subcommands
CommandInfo(Command command, char mnemonic, const std::string &name, const std::string &desc)