1#ifndef YAZE_APP_EDITOR_SYSTEM_SHORTCUT_MANAGER_H
2#define YAZE_APP_EDITOR_SYSTEM_SHORTCUT_MANAGER_H
7#include <unordered_map>
11#include "absl/strings/string_view.h"
14#ifndef IMGUI_DEFINE_MATH_OPERATORS
15#define IMGUI_DEFINE_MATH_OPERATORS
18#include "imgui/imgui.h"
29 std::vector<ImGuiKey>
keys;
40std::vector<ImGuiKey>
ParseShortcut(
const std::string& shortcut);
57 const std::vector<ImGuiKey>& keys,
59 Store({name, scope, keys});
62 const std::vector<ImGuiKey>& keys,
63 std::function<
void()> callback,
65 Store({name, scope, keys, std::move(callback)});
69 std::function<
void()> callback,
71 Store({name, scope, {key}, std::move(callback)});
81 const std::vector<ImGuiKey>& keys,
82 std::function<
void()> callback,
86 shortcut.editor_type = editor_type;
87 Store(std::move(shortcut));
98 Store({name, scope, {}, std::move(callback)});
103 std::optional<EditorType> editor_type);
106 std::function<
bool()> enabled);
131 return it !=
shortcuts_.end() ? &it->second :
nullptr;
135 std::function<void()>
GetCallback(
const std::string& name)
const {
139 const std::string
GetKeys(
const std::string& name)
const {
152 const std::unordered_map<std::string, Shortcut>&
GetShortcuts()
const {
156 const std::vector<ImGuiKey>& keys);
165 std::vector<std::string>
FindConflicts(
const std::string& name)
const;
167 const std::vector<ImGuiKey>& keys, std::optional<EditorType> editor_type,
168 const std::string& exclude_name =
"")
const;
171 std::vector<Shortcut> result;
174 if (sc.scope == scope)
175 result.push_back(sc);
182 std::function<
void()> open_callback,
183 std::function<
void()> close_callback,
184 std::function<
void()> find_callback,
185 std::function<
void()> settings_callback);
188 std::function<
void()> focus_right,
189 std::function<
void()> focus_up,
190 std::function<
void()> focus_down,
191 std::function<
void()> close_window,
192 std::function<
void()> split_horizontal,
193 std::function<
void()> split_vertical);
198 std::string name = shortcut.
name;
207bool SameChord(
const std::vector<ImGuiKey>& a,
const std::vector<ImGuiKey>& b);
const Shortcut & GetShortcut(const std::string &name) const
const Shortcut * FindShortcut(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)
std::function< std::optional< EditorType >()> ActiveEditorProvider
bool SetShortcutEditor(const std::string &name, std::optional< EditorType > editor_type)
Restrict an existing shortcut to one editor. Returns false if unknown.
ActiveEditorProvider active_editor_provider_
void RegisterShortcut(const std::string &name, const std::vector< ImGuiKey > &keys, Shortcut::Scope scope=Shortcut::Scope::kGlobal)
bool IsShortcutApplicable(const Shortcut &shortcut) const
True when the shortcut may fire now (editor owner + enabled predicate).
void SetActiveEditorProvider(ActiveEditorProvider provider)
void RegisterShortcut(const std::string &name, ImGuiKey key, std::function< void()> callback, Shortcut::Scope scope=Shortcut::Scope::kGlobal)
void Store(Shortcut shortcut)
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)
bool SetShortcutEnabled(const std::string &name, std::function< bool()> enabled)
Attach an applicability predicate. Returns false if unknown.
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)
std::string GetDisplayString(const std::string &name) const
Live, platform-formatted binding for a shortcut name.
bool ResetShortcutKeys(const std::string &name)
Restore the keys the shortcut was registered with.
void ExecuteShortcut(const std::string &name) const
std::unordered_map< std::string, Shortcut > shortcuts_
void RegisterEditorShortcut(const std::string &name, const std::vector< ImGuiKey > &keys, std::function< void()> callback, EditorType editor_type)
Register an editor-owned shortcut (Scope::kEditor).
const std::unordered_map< std::string, Shortcut > & GetShortcuts() const
std::vector< std::string > FindConflicts(const std::string &name) const
Names of other shortcuts bound to the same chord that can be active at the same time (same editor own...
std::optional< EditorType > GetActiveEditorType() const
bool UpdateShortcutKeys(const std::string &name, const std::vector< ImGuiKey > &keys)
std::string InferShortcutGroup(absl::string_view name)
Menu-IA group for a shortcut/command name (File, View, Drawers, …).
bool SameChord(const std::vector< ImGuiKey > &a, const std::vector< ImGuiKey > &b)
True when two key lists describe the same chord (order-insensitive).
std::vector< ImGuiKey > ParseShortcut(const std::string &shortcut)
std::string PrintShortcut(const std::vector< ImGuiKey > &keys)
void ExecuteShortcuts(const ShortcutManager &shortcut_manager)
Fire at most one shortcut for this frame's key press.
std::function< void()> callback
std::vector< ImGuiKey > keys
std::function< bool()> enabled
std::vector< ImGuiKey > default_keys
std::optional< EditorType > editor_type