Module: Wx::Extensions::EasyMenuBar

Includes:
EasyMenuName
Included in:
MenuBar
Defined in:
lib/wx_sugar/menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EasyMenuName

#clean_name, #internal_name

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



14
15
16
# File 'lib/wx_sugar/menu.rb', line 14

def source
  @source
end

#targetObject

Returns the value of attribute target.



14
15
16
# File 'lib/wx_sugar/menu.rb', line 14

def target
  @target
end

Instance Method Details

#[](menu_id) ⇒ Object

Return the Menu item corresponding to menu_id. This can be a zero-based integer specifying the menu’s offset within the MenuBar, or a string title, with or without accelerator key.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/wx_sugar/menu.rb', line 54

def [](menu_id)
  case menu_id
  when Integer
    index = menu_id
  when String
    # a_MenuBar.find_menu missing in wxruby 0.6.0
    index = find_menu(menu_id)
    raise RuntimeError, "No menu called #{menu_id}" if index == Wx::NOT_FOUND
  else
    raise ArgumentError, "Bad menu specifier #{menu_id.inspect}"       
  end
  get_menu(index)
end

#add_menu(title) {|menu| ... } ⇒ Object

Yields:

  • (menu)


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/wx_sugar/menu.rb', line 21

def add_menu(title)
  menu = Wx::Menu.new()
  menu.target  = self.target
  menu.source  = self.source
  yield menu
  append(menu, title)
  # these are here because wxruby 0.6.0 doesn't 
  # support get_menu and find_menue
  menu_labels << internal_name(title)
  menu_menus << menu
  menu
end

#connect(source, target = source) ⇒ Object



15
16
17
18
19
# File 'lib/wx_sugar/menu.rb', line 15

def connect(source, target = source)
  self.source = source
  # source.set_menu_bar(self)
  self.target = target
end

#find_menu(str) ⇒ Object

only used if find_menu is not available in WxRuby



47
48
49
# File 'lib/wx_sugar/menu.rb', line 47

def find_menu(str)
  menu_labels.index( internal_name(str) ) || Wx::NOT_FOUND
end

#get_menu(idx) ⇒ Object



42
43
44
# File 'lib/wx_sugar/menu.rb', line 42

def get_menu(idx)
  menu_menus[idx]
end


38
39
40
# File 'lib/wx_sugar/menu.rb', line 38

def menu_labels()
  @menu_labels ||= []
end


34
35
36
# File 'lib/wx_sugar/menu.rb', line 34

def menu_menus()
  @menu_menus||= []
end