Class: Lich::Common::GUI::FrontendSelector
- Inherits:
-
Object
- Object
- Lich::Common::GUI::FrontendSelector
- Defined in:
- documented/common/gui/frontend_selector.rb
Overview
Shared GTK frontend selector backed by the frontend catalog. Discovery annotates choices but never removes configurable frontends.
Instance Attribute Summary collapse
-
#resolutions ⇒ Object
readonly
Returns the value of attribute resolutions.
-
#widget ⇒ Object
readonly
Returns the value of attribute widget.
Instance Method Summary collapse
-
#choices ⇒ Array<Array<String>>
Stable ids and annotated labels shared by form and inline selectors.
-
#empty? ⇒ Boolean
Returns whether the frontend catalog has no selectable definitions.
-
#initialize(selected_id: nil, refresh: true, locator: FrontendLocator, frontend: Frontend) ⇒ FrontendSelector
constructor
Initializes a catalog-backed frontend dropdown.
-
#launchable?(refresh: true) ⇒ Boolean
Returns whether the selected frontend has enough configuration to attempt a launch.
-
#native_launch_only? ⇒ Boolean
Returns whether the selected frontend disallows custom launch.
-
#on_change {|FrontendSelector| ... } ⇒ void
Registers a callback for changes to the selected frontend option.
-
#reload!(refresh: true) ⇒ FrontendSelector
Reloads configured definitions and executable status in-place so callers do not need to replace widgets after the Frontends tab saves.
-
#resolve_selected(refresh: true) ⇒ FrontendLocator::Resolution?
Revalidates the selected executable immediately before launch.
-
#selected_id ⇒ String?
Returns the selected stable frontend identifier.
Constructor Details
#initialize(selected_id: nil, refresh: true, locator: FrontendLocator, frontend: Frontend) ⇒ FrontendSelector
Initializes a catalog-backed frontend dropdown.
25 26 27 28 29 30 |
# File 'documented/common/gui/frontend_selector.rb', line 25 def initialize(selected_id: nil, refresh: true, locator: FrontendLocator, frontend: Frontend) @locator = locator @frontend = frontend refresh_catalog(refresh: refresh) @widget = (selected_id) end |
Instance Attribute Details
#resolutions ⇒ Object (readonly)
Returns the value of attribute resolutions.
16 17 18 |
# File 'documented/common/gui/frontend_selector.rb', line 16 def resolutions @resolutions end |
#widget ⇒ Object (readonly)
Returns the value of attribute widget.
16 17 18 |
# File 'documented/common/gui/frontend_selector.rb', line 16 def @widget end |
Instance Method Details
#choices ⇒ Array<Array<String>>
Stable ids and annotated labels shared by form and inline selectors.
109 110 111 |
# File 'documented/common/gui/frontend_selector.rb', line 109 def choices @definitions.map { |definition| [definition[:id], option_label(definition)] } end |
#empty? ⇒ Boolean
Returns whether the frontend catalog has no selectable definitions.
103 104 105 |
# File 'documented/common/gui/frontend_selector.rb', line 103 def empty? @definitions.empty? end |
#launchable?(refresh: true) ⇒ Boolean
Returns whether the selected frontend has enough configuration to attempt a launch. Custom commands may resolve through PATH or a shell, so executable discovery is intentionally limited to native adapters.
89 90 91 92 93 94 95 96 97 98 |
# File 'documented/common/gui/frontend_selector.rb', line 89 def launchable?(refresh: true) return false unless selected_id FrontendLauncher.launchable?( selected_id, locator: @locator, frontend: @frontend, refresh: refresh ) end |
#native_launch_only? ⇒ Boolean
Returns whether the selected frontend disallows custom launch.
60 61 62 63 64 |
# File 'documented/common/gui/frontend_selector.rb', line 60 def native_launch_only? return false unless selected_id @frontend.definition_for(selected_id).dig(:metadata, :native_launch_only) == true end |
#on_change {|FrontendSelector| ... } ⇒ void
This method returns an undefined value.
Registers a callback for changes to the selected frontend option.
69 70 71 72 |
# File 'documented/common/gui/frontend_selector.rb', line 69 def on_change(&callback) @widget.signal_connect('changed') { callback.call(self) } nil end |
#reload!(refresh: true) ⇒ FrontendSelector
Reloads configured definitions and executable status in-place so callers do not need to replace widgets after the Frontends tab saves. The current stable frontend id is retained when it remains selectable.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'documented/common/gui/frontend_selector.rb', line 38 def reload!(refresh: true) selected_id = self.selected_id refresh_catalog(refresh: refresh) @widget.remove_all @definitions.each do |definition| @widget.append(definition[:id], option_label(definition)) end @widget.active_id = preferred_id(selected_id) update_tooltip(@widget) self end |
#resolve_selected(refresh: true) ⇒ FrontendLocator::Resolution?
Revalidates the selected executable immediately before launch.
77 78 79 80 81 |
# File 'documented/common/gui/frontend_selector.rb', line 77 def resolve_selected(refresh: true) return nil unless selected_id @locator.resolve(selected_id, refresh: refresh) end |
#selected_id ⇒ String?
Returns the selected stable frontend identifier.
53 54 55 |
# File 'documented/common/gui/frontend_selector.rb', line 53 def selected_id @widget.active_id end |