Class: MenuMotion::Menu
- Inherits:
-
NSMenu
- Object
- NSMenu
- MenuMotion::Menu
- Defined in:
- lib/menu-motion/menu.rb
Instance Attribute Summary collapse
-
#menu_items ⇒ Object
Returns the value of attribute menu_items.
-
#root_menu ⇒ Object
Returns the value of attribute root_menu.
Instance Method Summary collapse
- #add_rows_to_menu(menu, rows) ⇒ Object
- #add_sections_to_menu(menu, sections) ⇒ Object
- #build_menu_from_params(menu, params) ⇒ Object
-
#initialize(params = {}, root_menu = nil) ⇒ Menu
constructor
A new instance of Menu.
- #item_with_tag(tag) ⇒ Object
- #perform_action(menu_item) ⇒ Object
- #update_item_with_tag(tag, params) ⇒ Object
- #validateMenuItem(menu_item) ⇒ Object
Constructor Details
#initialize(params = {}, root_menu = nil) ⇒ Menu
Returns a new instance of Menu.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/menu-motion/menu.rb', line 52 def initialize(params = {}, = nil) if params[:title] initWithTitle(params[:title]) else super() end self. = self.(self, params) self end |
Instance Attribute Details
#menu_items ⇒ Object
Returns the value of attribute menu_items.
5 6 7 |
# File 'lib/menu-motion/menu.rb', line 5 def @menu_items end |
#root_menu ⇒ Object
Returns the value of attribute root_menu.
5 6 7 |
# File 'lib/menu-motion/menu.rb', line 5 def @root_menu end |
Instance Method Details
#add_rows_to_menu(menu, rows) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/menu-motion/menu.rb', line 7 def (, rows) rows.each do |row| row[:root_menu] = WeakRef.new(self. || self) = MenuMotion::MenuItem.new(row) .target = self .action = "perform_action:" if tag = row[:tag] tag = tag.to_sym .tag = tag if self. self.. ||= {} self..[tag] = WeakRef.new() else self. ||= {} self.[tag] = WeakRef.new() end end .addItem() end end |
#add_sections_to_menu(menu, sections) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/menu-motion/menu.rb', line 31 def (, sections) sections.each_with_index do |section, index| if section[:rows] if index > 0 # Add the separator before the new section, # skipping the first section .addItem(NSMenuItem.separatorItem) end (, section[:rows]) end end end |
#build_menu_from_params(menu, params) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/menu-motion/menu.rb', line 44 def (, params) if params[:sections] (, params[:sections]) elsif params[:rows] (, params[:rows]) end end |
#item_with_tag(tag) ⇒ Object
65 66 67 68 |
# File 'lib/menu-motion/menu.rb', line 65 def item_with_tag(tag) @menu_items ||= {} @menu_items[tag.to_sym] end |
#perform_action(menu_item) ⇒ Object
70 71 72 |
# File 'lib/menu-motion/menu.rb', line 70 def perform_action() .perform_action end |
#update_item_with_tag(tag, params) ⇒ Object
74 75 76 77 |
# File 'lib/menu-motion/menu.rb', line 74 def update_item_with_tag(tag, params) = self.item_with_tag(tag) .update(params) end |
#validateMenuItem(menu_item) ⇒ Object
79 80 81 |
# File 'lib/menu-motion/menu.rb', line 79 def validateMenuItem() .valid? end |