1#ifndef YAZE_APP_EDITOR_SYSTEM_SHORTCUT_MANAGER_H
2#define YAZE_APP_EDITOR_SYSTEM_SHORTCUT_MANAGER_H
6#include <unordered_map>
10#ifndef IMGUI_DEFINE_MATH_OPERATORS
11#define IMGUI_DEFINE_MATH_OPERATORS
14#include "imgui/imgui.h"
27 std::vector<ImGuiKey>
keys;
31std::vector<ImGuiKey>
ParseShortcut(
const std::string& shortcut);
38 const std::vector<ImGuiKey>& keys,
43 const std::vector<ImGuiKey>& keys,
44 std::function<
void()> callback,
46 shortcuts_[name] = {name, scope, keys, callback};
50 std::function<
void()> callback,
52 shortcuts_[name] = {name, scope, {key}, callback};
62 std::function<
void()> callback,
64 shortcuts_[name] = {name, scope, {}, callback};
77 std::function<void()>
GetCallback(
const std::string& name)
const {
81 const std::string
GetKeys(
const std::string& name)
const {
87 const std::vector<ImGuiKey>& keys);
89 std::vector<Shortcut> result;
92 if (sc.scope == scope) result.push_back(sc);
99 std::function<
void()> open_callback,
100 std::function<
void()> close_callback,
101 std::function<
void()> find_callback,
102 std::function<
void()> settings_callback);
105 std::function<
void()> focus_right,
106 std::function<
void()> focus_up,
107 std::function<
void()> focus_down,
108 std::function<
void()> close_window,
109 std::function<
void()> split_horizontal,
110 std::function<
void()> split_vertical);
const Shortcut & GetShortcut(const std::string &name) const
const std::string GetKeys(const std::string &name) const
void RegisterCommand(const std::string &name, std::function< void()> callback, Shortcut::Scope scope=Shortcut::Scope::kGlobal)
Register a command without keyboard shortcut (command palette only)
void RegisterShortcut(const std::string &name, const std::vector< ImGuiKey > &keys, Shortcut::Scope scope=Shortcut::Scope::kGlobal)
void RegisterShortcut(const std::string &name, ImGuiKey key, std::function< void()> callback, Shortcut::Scope scope=Shortcut::Scope::kGlobal)
std::function< void()> GetCallback(const std::string &name) const
std::vector< Shortcut > GetShortcutsByScope(Shortcut::Scope scope) const
void RegisterShortcut(const std::string &name, const std::vector< ImGuiKey > &keys, std::function< void()> callback, Shortcut::Scope scope=Shortcut::Scope::kGlobal)
void RegisterStandardShortcuts(std::function< void()> save_callback, std::function< void()> open_callback, std::function< void()> close_callback, std::function< void()> find_callback, std::function< void()> settings_callback)
auto GetShortcuts() const
void RegisterWindowNavigationShortcuts(std::function< void()> focus_left, std::function< void()> focus_right, std::function< void()> focus_up, std::function< void()> focus_down, std::function< void()> close_window, std::function< void()> split_horizontal, std::function< void()> split_vertical)
void ExecuteShortcut(const std::string &name) const
std::unordered_map< std::string, Shortcut > shortcuts_
bool UpdateShortcutKeys(const std::string &name, const std::vector< ImGuiKey > &keys)
std::vector< ImGuiKey > ParseShortcut(const std::string &shortcut)
std::string PrintShortcut(const std::vector< ImGuiKey > &keys)
void ExecuteShortcuts(const ShortcutManager &shortcut_manager)
std::function< void()> callback
std::vector< ImGuiKey > keys