Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::view::CommandRegistry Class Reference

Central command dispatcher. More...

#include <command_registry.hpp>

Public Member Functions

 CommandRegistry ()=default
 ~CommandRegistry ()=default
 CommandRegistry (const CommandRegistry &)=delete
CommandRegistry & operator= (const CommandRegistry &)=delete
void register_command (const CommandInfo &info)
 Register a command.
std::optional< CommandInfo > command_info (CommandID id) const
 Look up a command by id. Returns nullopt if unknown.
const std::vector< CommandInfo > & commands () const
 All registered commands, in registration order.
void set_enabled (CommandID id, bool enabled)
 Mutate a command's enabled flag (e.g.
void add_handler (CommandHandler *handler)
 Add a handler to the front of the dispatch chain (highest priority).
void remove_handler (CommandHandler *handler)
 Remove a handler from the chain.
std::size_t handler_count () const
 Number of handlers currently in the chain.
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 any).
ShortcutMap & shortcuts ()
const ShortcutMap & shortcuts () const

Detailed Description

Central command dispatcher.

One per application (or per window, if you want per-window scopes). Owns the ShortcutMap and a chain of registered CommandHandler pointers.

Constructor & Destructor Documentation

◆ CommandRegistry() [1/2]

pulp::view::CommandRegistry::CommandRegistry ( )
default

◆ ~CommandRegistry()

pulp::view::CommandRegistry::~CommandRegistry ( )
default

◆ CommandRegistry() [2/2]

pulp::view::CommandRegistry::CommandRegistry ( const CommandRegistry & )
delete

Member Function Documentation

◆ add_handler()

void pulp::view::CommandRegistry::add_handler ( CommandHandler * handler)

Add a handler to the front of the dispatch chain (highest priority).

Caller retains ownership; must call remove_handler before the handler is destroyed.

◆ command_info()

std::optional< CommandInfo > pulp::view::CommandRegistry::command_info ( CommandID id) const

Look up a command by id. Returns nullopt if unknown.

◆ commands()

const std::vector< CommandInfo > & pulp::view::CommandRegistry::commands ( ) const
inline

All registered commands, in registration order.

◆ dispatch()

bool pulp::view::CommandRegistry::dispatch ( CommandID id)

Dispatch a command id through the handler chain.

Returns true if some handler claimed it. Commands marked enabled=false are not dispatched and the call returns false.

◆ dispatch_key_event()

bool pulp::view::CommandRegistry::dispatch_key_event ( const KeyEvent & event)

Dispatch a key event: look up the chord in the ShortcutMap, then dispatch the resulting command (if any).

Returns true iff a command was found AND a handler claimed it.

◆ handler_count()

std::size_t pulp::view::CommandRegistry::handler_count ( ) const
inline

Number of handlers currently in the chain.

◆ operator=()

CommandRegistry & pulp::view::CommandRegistry::operator= ( const CommandRegistry & )
delete

◆ register_command()

void pulp::view::CommandRegistry::register_command ( const CommandInfo & info)

Register a command.

If the info's default_key is non-unknown, the registry also binds the default chord in the ShortcutMap (unless that chord is already bound — user-loaded rebindings take priority, which is why apps should load the shortcut map from disk BEFORE calling register_command).

◆ remove_handler()

void pulp::view::CommandRegistry::remove_handler ( CommandHandler * handler)

Remove a handler from the chain.

Safe to call with an unknown pointer (no-op).

◆ set_enabled()

void pulp::view::CommandRegistry::set_enabled ( CommandID id,
bool enabled )

Mutate a command's enabled flag (e.g.

greys out "Undo" when the stack is empty). Does not change shortcut bindings.

◆ shortcuts() [1/2]

ShortcutMap & pulp::view::CommandRegistry::shortcuts ( )
inline

◆ shortcuts() [2/2]

const ShortcutMap & pulp::view::CommandRegistry::shortcuts ( ) const
inline

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