Class: XRC2Ruby::ObjectTypes::Menu

Inherits:
Window show all
Includes:
Parent
Defined in:
lib/wx_sugar/xrc/xrc2ruby_types/menu.rb

Constant Summary

Constants inherited from Window

Window::BASE_NAME

Instance Attribute Summary collapse

Attributes included from Parent

#children, #main_sizer, #sizer_items

Attributes inherited from Window

#bg, #enabled, #exstyle, #fg, #help, #hidden, #tooltip

Attributes inherited from Object

#centered, #name, #parent, #sub_class, #win_class

Instance Method Summary collapse

Methods included from Parent

#add_child, #child_output, #named_windows, #size_child

Methods inherited from Window

#args, #setup

Methods included from InitArgs

#inherited, #init_arg, #init_args, #translatable_string_init_arg

Methods inherited from Object

#initialize, #inspect, next_id, #var_name

Constructor Details

This class inherits a constructor from XRC2Ruby::ObjectTypes::Object

Instance Attribute Details

#labelObject

Returns the value of attribute label.



13
14
15
# File 'lib/wx_sugar/xrc/xrc2ruby_types/menu.rb', line 13

def label
  @label
end

Instance Method Details

#outputObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wx_sugar/xrc/xrc2ruby_types/menu.rb', line 15

def output
  if XRC2Ruby.use_gettext
    the_label = "_(" + label.inspect + ")"
  else
    the_label = label.inspect
  end
  # A standard menu attached to menubar; NB - call to append must
  # come after all menu items have been created
  if parent.kind_of?(MenuBar)
    "#{var_name} = Wx::Menu.new\n" +
    child_output +
    "#{parent.var_name}.append(#{var_name}, #{the_label})\n"
  # If a submenu
  elsif parent.kind_of?(Menu)
    output_as_submenu(the_label)
  else
    Kernel.raise("Menu shouldn't be attached to a #{parent.class}")
  end
end

#output_as_submenu(label) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/wx_sugar/xrc/xrc2ruby_types/menu.rb', line 35

def output_as_submenu(label)
  
  menu_item = MenuItem.new(parent, 'wxMenuItem', 'wxMenuItem', '')
  menu_item.label = self.label
  menu_item.submenu = self.var_name
  submenu = "#{var_name} = Wx::Menu.new\n" + child_output + menu_item.output
end