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
14 public:
15 CommandManager() = default;
16 ~CommandManager() = default;
17
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)),
29 name(name),
30 desc(desc) {}
31 CommandInfo() = default;
32 };
33
34 // New command info which supports subsections of commands
37 std::unordered_map<std::string, CommandInfoOrPrefix> subcommands;
41 };
42
43 void RegisterPrefix(const std::string &group_name, const char prefix,
44 const std::string &name, const std::string &desc) {
45 commands_[group_name].command_info = {nullptr, prefix, name, desc};
46 }
47
48 void RegisterSubcommand(const std::string &group_name,
49 const std::string &shortcut, const char mnemonic,
50 const std::string &name, const std::string &desc,
51 Command command) {
52 commands_[group_name].subcommands[shortcut].command_info = {
53 command, mnemonic, name, desc};
54 }
55
56 void RegisterCommand(const std::string &shortcut, Command command,
57 char mnemonic, const std::string &name,
58 const std::string &desc) {
59 commands_[shortcut].command_info = {std::move(command), mnemonic, name,
60 desc};
61 }
62
63 void ExecuteCommand(const std::string &shortcut) {
64 if (commands_.find(shortcut) != commands_.end()) {
65 commands_[shortcut].command_info.command();
66 }
67 }
68
69 void ShowWhichKey();
70
71 void SaveKeybindings(const std::string &filepath);
72 void LoadKeybindings(const std::string &filepath);
73
74 private:
75 std::unordered_map<std::string, CommandInfoOrPrefix> commands_;
76};
77
78} // namespace editor
79} // namespace yaze
80
81#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.
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)