class BBS::Application::ItemsBuilder
DSL inside menu(label) do ... end: collects the menuโs items.
Attributes
The BBS::Menubar::MenuItem objects added so far.
Public Class Methods
Source
# File lib/bbs/application/builder.rb, line 180 def initialize(app) @app = app @items = [] end
Creates an empty item list whose blocks run on app.
Public Instance Methods
Source
# File lib/bbs/application/builder.rb, line 213 def doors @app.doors.each_value do |door| item(door.label, hint: door.hint) { open_door(door.name) } end end
One item per declared door, in declaration order, each with the doorโs hint.
# File lib/bbs/application/builder.rb, line 194 def item(label, shortcut: nil, enabled: true, hint: nil, &block) if enabled.is_a?(Proc) check = enabled enabled = -> { @app.instance_exec(&check) } end @items << Menubar::MenuItem.new( label: label, shortcut: shortcut, enabled: enabled, separator: false, hint: hint, on_select: block ? ->(item) { @app.instance_exec(item, &block) } : nil ) end
Adds an item titled label, with an optional shortcut text shown beside it and an optional hint, a line the statusbar shows while the item is highlighted. The block runs on the application, with the item as its argument, when the item is chosen.
enabled is true, false, or a lambda the application answers each time the menu is drawn or used:
item('&Save', enabled: -> { current_doc }) { save }
Source
# File lib/bbs/application/builder.rb, line 206 def separator @items << Menubar::MenuItem.new(label: '', shortcut: nil, enabled: false, separator: true, on_select: nil) end
Adds a separator line between items.