62#include <unordered_map>
123 info.name =
"Settings…";
124 info.category =
"App";
146 virtual std::vector<CommandID>
commands()
const = 0;
179 std::size_t
size()
const {
return bindings_.size(); }
190 std::string_view key_prefix =
"shortcuts")
const;
192 std::string_view key_prefix =
"shortcuts");
196 using ChordKey = std::uint64_t;
197 static ChordKey make_key(
KeyCode k, std::uint16_t
m) {
198 return (
static_cast<ChordKey
>(
m) << 32) |
199 static_cast<ChordKey
>(
static_cast<std::uint32_t
>(
k));
201 std::unordered_map<ChordKey, CommandID> bindings_;
229 const std::vector<CommandInfo>&
commands()
const {
return commands_; }
267 std::vector<CommandInfo> commands_;
268 std::unordered_map<CommandID, std::size_t> command_index_;
269 std::vector<CommandHandler*> handlers_;
JSON-backed persistent settings file.
Definition properties_file.hpp:16
Interface implemented by any object that can perform commands.
Definition command_registry.hpp:137
virtual ~CommandHandler()=default
virtual bool perform_command(CommandID id)=0
Perform a command.
virtual std::vector< CommandID > commands() const =0
Report which commands this handler can perform.
Central command dispatcher.
Definition command_registry.hpp:207
void set_enabled(CommandID id, bool enabled)
Mutate a command's enabled flag (e.g.
CommandRegistry(const CommandRegistry &)=delete
void remove_handler(CommandHandler *handler)
Remove a handler from the chain.
void register_command(const CommandInfo &info)
Register a command.
CommandRegistry()=default
bool dispatch(CommandID id)
Dispatch a command id through the handler chain.
bool dispatch_key_event(const KeyEvent &event)
Dispatch a key event: look up the chord in the ShortcutMap, then dispatch the resulting command (if a...
std::size_t handler_count() const
Number of handlers currently in the chain.
Definition command_registry.hpp:247
CommandRegistry & operator=(const CommandRegistry &)=delete
void add_handler(CommandHandler *handler)
Add a handler to the front of the dispatch chain (highest priority).
~CommandRegistry()=default
ShortcutMap & shortcuts()
Definition command_registry.hpp:263
const std::vector< CommandInfo > & commands() const
All registered commands, in registration order.
Definition command_registry.hpp:229
const ShortcutMap & shortcuts() const
Definition command_registry.hpp:264
std::optional< CommandInfo > command_info(CommandID id) const
Look up a command by id. Returns nullopt if unknown.
(KeyCode, modifiers) → CommandID lookup table.
Definition command_registry.hpp:155
void unbind_command(CommandID id)
Remove every chord that points to the given command.
bool load_from(const pulp::state::PropertiesFile &props, std::string_view key_prefix="shortcuts")
void save_to(pulp::state::PropertiesFile &props, std::string_view key_prefix="shortcuts") const
Serialize / restore through a pulp::state::PropertiesFile.
void unbind(KeyCode key, std::uint16_t modifiers)
Remove any binding for the given chord. No-op if unbound.
void clear()
Clear all bindings.
Definition command_registry.hpp:182
std::size_t size() const
Number of bound chords.
Definition command_registry.hpp:179
CommandID find(KeyCode key, std::uint16_t modifiers) const
Look up a chord. Returns kInvalidCommandID if unbound.
std::vector< Chord > chords_for(CommandID id) const
void bind(KeyCode key, std::uint16_t modifiers, CommandID id)
Associate a (key, modifier) chord with a command.
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ kModCmd
Command (macOS) — alias for platform primary modifier.
Definition input_events.hpp:21
@ kModCtrl
Control key (Ctrl on Windows/Linux).
Definition input_events.hpp:18
constexpr std::uint16_t kOpenSettingsModifiers
The platform-standard open-settings chord: Cmd+, on macOS, Ctrl+, elsewhere.
Definition command_registry.hpp:95
uint32_t CommandID
A unique command identifier.
Definition app_framework.hpp:20
CommandInfo make_open_settings_command_info()
CommandInfo for kCommandOpenSettings with the platform-standard chord as its default binding.
Definition command_registry.hpp:120
void route_global_keys(View &root, CommandRegistry ®istry)
Install registry as the root view's single global-key dispatcher: assigns root.on_global_key to forwa...
constexpr CommandID kCommandOpenSettings
Framework-reserved CommandID for "open the app's settings / preferences" (ASCII 'PLST').
Definition command_registry.hpp:88
KeyCode
Definition input_events.hpp:35
@ m
Definition input_events.hpp:40
@ k
Definition input_events.hpp:40
@ unknown
Definition input_events.hpp:36
constexpr CommandID kInvalidCommandID
Definition command_registry.hpp:76
@ info
Definition design_ir.hpp:695
constexpr KeyCode kKeyComma
ASCII comma as a KeyCode.
Definition command_registry.hpp:81
Metadata for one command.
Definition command_registry.hpp:102
std::uint16_t default_modifiers
Definition command_registry.hpp:107
KeyCode default_key
Definition command_registry.hpp:106
bool enabled
False = greyed out / not dispatched.
Definition command_registry.hpp:108
std::string name
User-facing display name ("Open File…").
Definition command_registry.hpp:104
std::string category
Group ("File", "Edit", "View") for the editor.
Definition command_registry.hpp:105
CommandID id
Definition command_registry.hpp:103
Rich key event with key code, modifiers, and repeat state.
Definition input_events.hpp:193
All chords currently bound to the given command.
Definition command_registry.hpp:172
KeyCode key
Definition command_registry.hpp:173
std::uint16_t modifiers
Definition command_registry.hpp:174