Class: QDA::GUI::EasyMenu
- Inherits:
-
Wx::Menu
- Object
- Wx::Menu
- QDA::GUI::EasyMenu
- Defined in:
- lib/weft/wxgui/workarea.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#add_item(command_str, command_key = '', itemtype = Wx::ITEM_NORMAL) ⇒ Object
adds the item
command_str
to the menu, with the optional shortcut keycommand_key
, and sets it to run the associated block when the menu item is chosen. - #check_items(*idents) ⇒ Object (also: #check_item)
- #disable_items(*idents) ⇒ Object (also: #disable_item)
-
#enable_items(*idents) ⇒ Object
(also: #enable_item)
pass a series of symbol idents eg :save_project, :close.
-
#initialize(target) ⇒ EasyMenu
constructor
A new instance of EasyMenu.
- #uncheck_items(*idents) ⇒ Object (also: #uncheck_item)
Constructor Details
#initialize(target) ⇒ EasyMenu
Returns a new instance of EasyMenu.
310 311 312 313 314 315 316 317 |
# File 'lib/weft/wxgui/workarea.rb', line 310 def initialize(target) super() @target = target @base_id = EasyMenu.next_base() @commands = Hash.new do | hash, key | Kernel.raise ArgumentError.new("No such menu item #{key}") end end |
Class Method Details
.next_base ⇒ Object
305 306 307 308 |
# File 'lib/weft/wxgui/workarea.rb', line 305 def EasyMenu.next_base() @base_id ||= 0 @base_id += 100 end |
Instance Method Details
#add_item(command_str, command_key = '', itemtype = Wx::ITEM_NORMAL) ⇒ Object
adds the item command_str
to the menu, with the optional shortcut key command_key
, and sets it to run the associated block when the menu item is chosen. The menu item can later be referred to by the symbol with the commands name with special characters removed andspaces turned to underscores. For example, “Save Project” becomes :save_project
325 326 327 328 329 330 331 332 |
# File 'lib/weft/wxgui/workarea.rb', line 325 def add_item(command_str, command_key = '', itemtype = Wx::ITEM_NORMAL) const = ( @base_id += 1 ) ident = command_str.gsub(/\s+/, "_").gsub(/\W/, "").downcase.to_sym @commands[ident] = const append(const, "#{command_str}\t#{command_key}", "", itemtype) @target.(const) { | e | yield(e) } return ident end |
#check_items(*idents) ⇒ Object Also known as: check_item
345 346 347 |
# File 'lib/weft/wxgui/workarea.rb', line 345 def check_items(*idents) idents.each { | ident | check( @commands[ident], true ) } end |
#disable_items(*idents) ⇒ Object Also known as: disable_item
340 341 342 |
# File 'lib/weft/wxgui/workarea.rb', line 340 def disable_items(*idents) idents.each { | ident | enable( @commands[ident], false ) } end |
#enable_items(*idents) ⇒ Object Also known as: enable_item
pass a series of symbol idents eg :save_project, :close
335 336 337 |
# File 'lib/weft/wxgui/workarea.rb', line 335 def enable_items(*idents) idents.each { | ident | enable( @commands[ident], true ) } end |
#uncheck_items(*idents) ⇒ Object Also known as: uncheck_item
350 351 352 |
# File 'lib/weft/wxgui/workarea.rb', line 350 def uncheck_items(*idents) idents.each { | ident | check( @commands[ident], false ) } end |