Module: Charming::Controller::CommandPalette
- Included in:
- Charming::Controller
- Defined in:
- lib/charming/controller/command_palette.rb
Overview
Command palette helpers mixed into Controller. Opens/closes the palette, builds the palette from registered command bindings or theme list, and routes key/mouse events through it. Supports both the standard command palette (:commands) and the theme picker (:themes) via a discriminated ‘session` state hash.
Instance Method Summary collapse
-
#close_command_palette ⇒ Object
Closes the command palette, pops its focus scope, and renders the current action.
-
#command_palette ⇒ Object
Returns the active CommandPalette component, or nil when the palette is closed.
-
#command_palette_open? ⇒ Boolean
True when either the command palette or theme picker is currently open.
-
#open_command_palette ⇒ Object
Opens the command palette populated with the controller’s ‘command_bindings`.
Instance Method Details
#close_command_palette ⇒ Object
Closes the command palette, pops its focus scope, and renders the current action.
19 20 21 22 23 |
# File 'lib/charming/controller/command_palette.rb', line 19 def close_command_palette session.delete(:command_palette) pop_command_palette_scope render_default_action end |
#command_palette ⇒ Object
Returns the active CommandPalette component, or nil when the palette is closed.
31 32 33 |
# File 'lib/charming/controller/command_palette.rb', line 31 def command_palette build_command_palette_from_state(session[:command_palette]) if command_palette_open? end |
#command_palette_open? ⇒ Boolean
True when either the command palette or theme picker is currently open.
26 27 28 |
# File 'lib/charming/controller/command_palette.rb', line 26 def command_palette_open? session.key?(:command_palette) end |
#open_command_palette ⇒ Object
Opens the command palette populated with the controller’s ‘command_bindings`. Pushes a focus scope so subsequent keys are routed to the palette.
12 13 14 15 16 |
# File 'lib/charming/controller/command_palette.rb', line 12 def open_command_palette session[:command_palette] = command_palette_state(:commands) focus.push_scope([:command_palette], origin: :command_palette) render_default_action end |