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