yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
shortcut_manager.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SYSTEM_SHORTCUT_MANAGER_H
2#define YAZE_APP_EDITOR_SYSTEM_SHORTCUT_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
13struct Shortcut {
14 std::string name;
15 std::vector<ImGuiKey> keys;
16 std::function<void()> callback;
17};
18
19std::vector<ImGuiKey> ParseShortcut(const std::string &shortcut);
20
21std::string PrintShortcut(const std::vector<ImGuiKey> &keys);
22
24 public:
25 void RegisterShortcut(const std::string &name,
26 const std::vector<ImGuiKey> &keys) {
27 shortcuts_[name] = {name, keys};
28 }
29 void RegisterShortcut(const std::string &name,
30 const std::vector<ImGuiKey> &keys,
31 std::function<void()> callback) {
32 shortcuts_[name] = {name, keys, callback};
33 }
34
35 void RegisterShortcut(const std::string &name, ImGuiKey key,
36 std::function<void()> callback) {
37 shortcuts_[name] = {name, {key}, callback};
38 }
39
40 void ExecuteShortcut(const std::string &name) const {
41 shortcuts_.at(name).callback();
42 }
43
44 // Access the shortcut and print the readable name of the shortcut for menus
45 const Shortcut &GetShortcut(const std::string &name) const {
46 return shortcuts_.at(name);
47 }
48
49 // Get shortcut callback function
50 std::function<void()> GetCallback(const std::string &name) const {
51 return shortcuts_.at(name).callback;
52 }
53
54 const std::string GetKeys(const std::string &name) const {
55 return PrintShortcut(shortcuts_.at(name).keys);
56 }
57
58 auto GetShortcuts() const { return shortcuts_; }
59
60 private:
61 std::unordered_map<std::string, Shortcut> shortcuts_;
62};
63
64void ExecuteShortcuts(const ShortcutManager &shortcut_manager);
65
66} // namespace editor
67} // namespace yaze
68
69#endif // YAZE_APP_EDITOR_SYSTEM_SHORTCUT_MANAGER_H
const Shortcut & GetShortcut(const std::string &name) const
const std::string GetKeys(const std::string &name) const
void RegisterShortcut(const std::string &name, ImGuiKey key, std::function< void()> callback)
std::function< void()> GetCallback(const std::string &name) const
void RegisterShortcut(const std::string &name, const std::vector< ImGuiKey > &keys, std::function< void()> callback)
void ExecuteShortcut(const std::string &name) const
std::unordered_map< std::string, Shortcut > shortcuts_
void RegisterShortcut(const std::string &name, const std::vector< ImGuiKey > &keys)
Editors are the view controllers for the application.
std::vector< ImGuiKey > ParseShortcut(const std::string &shortcut)
std::string PrintShortcut(const std::vector< ImGuiKey > &keys)
void ExecuteShortcuts(const ShortcutManager &shortcut_manager)
Main namespace for the application.
Definition controller.cc:18
std::function< void()> callback
std::vector< ImGuiKey > keys