yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::ShortcutManager Class Reference

#include <shortcut_manager.h>

Public Types

using ActiveEditorProvider = std::function<std::optional<EditorType>()>
 

Public Member Functions

void RegisterShortcut (const std::string &name, const std::vector< ImGuiKey > &keys, Shortcut::Scope scope=Shortcut::Scope::kGlobal)
 
void RegisterShortcut (const std::string &name, const std::vector< ImGuiKey > &keys, std::function< void()> callback, Shortcut::Scope scope=Shortcut::Scope::kGlobal)
 
void RegisterShortcut (const std::string &name, ImGuiKey key, std::function< void()> callback, Shortcut::Scope scope=Shortcut::Scope::kGlobal)
 
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).
 
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)
 
bool SetShortcutEditor (const std::string &name, std::optional< EditorType > editor_type)
 Restrict an existing shortcut to one editor. Returns false if unknown.
 
bool SetShortcutEnabled (const std::string &name, std::function< bool()> enabled)
 Attach an applicability predicate. Returns false if unknown.
 
void SetActiveEditorProvider (ActiveEditorProvider provider)
 
std::optional< EditorType > GetActiveEditorType () const
 
bool IsShortcutApplicable (const Shortcut &shortcut) const
 True when the shortcut may fire now (editor owner + enabled predicate).
 
void ExecuteShortcut (const std::string &name) const
 
const Shortcut & GetShortcut (const std::string &name) const
 
const Shortcut * FindShortcut (const std::string &name) const
 
std::function< void()> GetCallback (const std::string &name) const
 
const std::string GetKeys (const std::string &name) const
 
std::string GetDisplayString (const std::string &name) const
 Live, platform-formatted binding for a shortcut name.
 
const std::unordered_map< std::string, Shortcut > & GetShortcuts () const
 
bool UpdateShortcutKeys (const std::string &name, const std::vector< ImGuiKey > &keys)
 
bool ResetShortcutKeys (const std::string &name)
 Restore the keys the shortcut was registered with.
 
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 owner, or either one unowned). Sorted by name. Keyless shortcuts never conflict.
 
std::vector< std::string > FindConflicts (const std::vector< ImGuiKey > &keys, std::optional< EditorType > editor_type, const std::string &exclude_name="") const
 
std::vector< Shortcut > GetShortcutsByScope (Shortcut::Scope scope) const
 
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)
 
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)
 

Private Member Functions

void Store (Shortcut shortcut)
 

Private Attributes

std::unordered_map< std::string, Shortcut > shortcuts_
 
ActiveEditorProvider active_editor_provider_
 

Detailed Description

Definition at line 52 of file shortcut_manager.h.

Member Typedef Documentation

◆ ActiveEditorProvider

using yaze::editor::ShortcutManager::ActiveEditorProvider = std::function<std::optional<EditorType>()>

Definition at line 54 of file shortcut_manager.h.

Member Function Documentation

◆ RegisterShortcut() [1/3]

void yaze::editor::ShortcutManager::RegisterShortcut ( const std::string & name,
const std::vector< ImGuiKey > & keys,
Shortcut::Scope scope = Shortcut::Scope::kGlobal )
inline

◆ RegisterShortcut() [2/3]

void yaze::editor::ShortcutManager::RegisterShortcut ( const std::string & name,
const std::vector< ImGuiKey > & keys,
std::function< void()> callback,
Shortcut::Scope scope = Shortcut::Scope::kGlobal )
inline

Definition at line 61 of file shortcut_manager.h.

References Store().

Here is the call graph for this function:

◆ RegisterShortcut() [3/3]

void yaze::editor::ShortcutManager::RegisterShortcut ( const std::string & name,
ImGuiKey key,
std::function< void()> callback,
Shortcut::Scope scope = Shortcut::Scope::kGlobal )
inline

Definition at line 68 of file shortcut_manager.h.

References Store().

Here is the call graph for this function:

◆ RegisterEditorShortcut()

void yaze::editor::ShortcutManager::RegisterEditorShortcut ( const std::string & name,
const std::vector< ImGuiKey > & keys,
std::function< void()> callback,
EditorType editor_type )
inline

Register an editor-owned shortcut (Scope::kEditor).

The shortcut is ignored during arbitration unless editor_type is the active editor, so another editor's binding for the same chord can win.

Definition at line 80 of file shortcut_manager.h.

References yaze::editor::Shortcut::kEditor, and Store().

Referenced by yaze::editor::anonymous_namespace{shortcut_configurator.cc}::RegisterEditorIfValid().

Here is the call graph for this function:

◆ RegisterCommand()

void yaze::editor::ShortcutManager::RegisterCommand ( const std::string & name,
std::function< void()> callback,
Shortcut::Scope scope = Shortcut::Scope::kGlobal )
inline

Register a command without keyboard shortcut (command palette only)

These commands appear in the command palette but have no keyboard binding. Useful for layout presets and other infrequently used commands.

Definition at line 96 of file shortcut_manager.h.

References Store().

Referenced by yaze::editor::ConfigureEditorShortcuts(), and yaze::editor::anonymous_namespace{shortcut_configurator.cc}::RegisterAlias().

Here is the call graph for this function:

◆ SetShortcutEditor()

bool yaze::editor::ShortcutManager::SetShortcutEditor ( const std::string & name,
std::optional< EditorType > editor_type )

Restrict an existing shortcut to one editor. Returns false if unknown.

Definition at line 472 of file shortcut_manager.cc.

References shortcuts_.

Referenced by yaze::editor::ConfigurePanelShortcuts().

◆ SetShortcutEnabled()

bool yaze::editor::ShortcutManager::SetShortcutEnabled ( const std::string & name,
std::function< bool()> enabled )

Attach an applicability predicate. Returns false if unknown.

Definition at line 482 of file shortcut_manager.cc.

References shortcuts_.

◆ SetActiveEditorProvider()

void yaze::editor::ShortcutManager::SetActiveEditorProvider ( ActiveEditorProvider provider)
inline

Supplies the active editor used to filter editor-owned shortcuts. When unset, editor-owned shortcuts are treated as applicable.

Definition at line 110 of file shortcut_manager.h.

References active_editor_provider_.

Referenced by yaze::editor::ConfigureEditorShortcuts().

◆ GetActiveEditorType()

std::optional< EditorType > yaze::editor::ShortcutManager::GetActiveEditorType ( ) const
inline

Definition at line 113 of file shortcut_manager.h.

References active_editor_provider_.

◆ IsShortcutApplicable()

bool yaze::editor::ShortcutManager::IsShortcutApplicable ( const Shortcut & shortcut) const

True when the shortcut may fire now (editor owner + enabled predicate).

Definition at line 492 of file shortcut_manager.cc.

References active_editor_provider_, yaze::editor::Shortcut::editor_type, and yaze::editor::Shortcut::enabled.

Referenced by yaze::editor::ExecuteShortcuts().

◆ ExecuteShortcut()

void yaze::editor::ShortcutManager::ExecuteShortcut ( const std::string & name) const
inline

Definition at line 120 of file shortcut_manager.h.

References shortcuts_.

◆ GetShortcut()

const Shortcut & yaze::editor::ShortcutManager::GetShortcut ( const std::string & name) const
inline

Definition at line 125 of file shortcut_manager.h.

References shortcuts_.

◆ FindShortcut()

◆ GetCallback()

std::function< void()> yaze::editor::ShortcutManager::GetCallback ( const std::string & name) const
inline

Definition at line 135 of file shortcut_manager.h.

References shortcuts_.

◆ GetKeys()

const std::string yaze::editor::ShortcutManager::GetKeys ( const std::string & name) const
inline

Definition at line 139 of file shortcut_manager.h.

References yaze::editor::PrintShortcut(), and shortcuts_.

Here is the call graph for this function:

◆ GetDisplayString()

std::string yaze::editor::ShortcutManager::GetDisplayString ( const std::string & name) const

Live, platform-formatted binding for a shortcut name.

Returns e.g. "Cmd+Shift+Z" on macOS or "Ctrl+Shift+Z" elsewhere, reflecting user rebinds. Returns an empty string for unknown or unbound names, so menus and the command palette can omit the hint.

Definition at line 505 of file shortcut_manager.cc.

References yaze::editor::PrintShortcut(), and shortcuts_.

Referenced by yaze::editor::OverworldToolbar::Draw(), yaze::editor::OverworldToolbar::DrawViewControls(), yaze::editor::DungeonEditorV2::Initialize(), yaze::editor::OverworldEditor::Initialize(), yaze::editor::LookupShortcutHint(), yaze::editor::ShortcutLabelForAction(), and yaze::editor::OverworldToolbar::WithHint().

Here is the call graph for this function:

◆ GetShortcuts()

◆ UpdateShortcutKeys()

bool yaze::editor::ShortcutManager::UpdateShortcutKeys ( const std::string & name,
const std::vector< ImGuiKey > & keys )

◆ ResetShortcutKeys()

bool yaze::editor::ShortcutManager::ResetShortcutKeys ( const std::string & name)

Restore the keys the shortcut was registered with.

Definition at line 463 of file shortcut_manager.cc.

References shortcuts_.

Referenced by yaze::editor::anonymous_namespace{settings_panel.cc}::DrawShortcutBindingRow().

◆ FindConflicts() [1/2]

std::vector< std::string > yaze::editor::ShortcutManager::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 owner, or either one unowned). Sorted by name. Keyless shortcuts never conflict.

Definition at line 513 of file shortcut_manager.cc.

References FindConflicts(), and shortcuts_.

Referenced by yaze::editor::ConfigurePanelShortcuts(), yaze::editor::anonymous_namespace{settings_panel.cc}::DrawShortcutBindingRow(), and FindConflicts().

Here is the call graph for this function:

◆ FindConflicts() [2/2]

std::vector< std::string > yaze::editor::ShortcutManager::FindConflicts ( const std::vector< ImGuiKey > & keys,
std::optional< EditorType > editor_type,
const std::string & exclude_name = "" ) const

Definition at line 522 of file shortcut_manager.cc.

References yaze::editor::SameChord(), and shortcuts_.

Here is the call graph for this function:

◆ GetShortcutsByScope()

std::vector< Shortcut > yaze::editor::ShortcutManager::GetShortcutsByScope ( Shortcut::Scope scope) const
inline

◆ RegisterStandardShortcuts()

void yaze::editor::ShortcutManager::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 )

Definition at line 553 of file shortcut_manager.cc.

References RegisterShortcut().

Here is the call graph for this function:

◆ RegisterWindowNavigationShortcuts()

void yaze::editor::ShortcutManager::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 )

Definition at line 587 of file shortcut_manager.cc.

References RegisterShortcut().

Here is the call graph for this function:

◆ Store()

void yaze::editor::ShortcutManager::Store ( Shortcut shortcut)
inlineprivate

Member Data Documentation

◆ shortcuts_

◆ active_editor_provider_

ActiveEditorProvider yaze::editor::ShortcutManager::active_editor_provider_
private

The documentation for this class was generated from the following files: