Class: MenuMotion::MenuItem
- Inherits:
-
NSMenuItem
- Object
- NSMenuItem
- MenuMotion::MenuItem
- Defined in:
- lib/menu-motion/menu_item.rb
Instance Attribute Summary collapse
-
#item_action ⇒ Object
Returns the value of attribute item_action.
-
#item_target ⇒ Object
Returns the value of attribute item_target.
-
#root_menu ⇒ Object
Returns the value of attribute root_menu.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#validate ⇒ Object
Returns the value of attribute validate.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ MenuItem
constructor
A new instance of MenuItem.
- #perform_action ⇒ Object
- #update(params) ⇒ Object
- #valid? ⇒ Boolean
- #valid_target_and_action? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ MenuItem
Returns a new instance of MenuItem.
11 12 13 14 15 |
# File 'lib/menu-motion/menu_item.rb', line 11 def initialize(params = {}) super() update(params) self end |
Instance Attribute Details
#item_action ⇒ Object
Returns the value of attribute item_action.
5 6 7 |
# File 'lib/menu-motion/menu_item.rb', line 5 def item_action @item_action end |
#item_target ⇒ Object
Returns the value of attribute item_target.
5 6 7 |
# File 'lib/menu-motion/menu_item.rb', line 5 def item_target @item_target end |
#root_menu ⇒ Object
Returns the value of attribute root_menu.
5 6 7 |
# File 'lib/menu-motion/menu_item.rb', line 5 def end |
#tag ⇒ Object
Returns the value of attribute tag.
5 6 7 |
# File 'lib/menu-motion/menu_item.rb', line 5 def tag @tag end |
#validate ⇒ Object
Returns the value of attribute validate.
5 6 7 |
# File 'lib/menu-motion/menu_item.rb', line 5 def validate @validate end |
Instance Method Details
#perform_action ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/menu-motion/menu_item.rb', line 17 def perform_action if self.valid? && self.valid_target_and_action? if self.item_action.to_s.end_with?(":") self.item_target.performSelector(self.item_action, withObject: self) else self.item_target.performSelector(self.item_action) end end end |
#update(params) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/menu-motion/menu_item.rb', line 27 def update(params) self.item_action = params[:action] if params.has_key?(:action) self.item_target = params[:target] if params.has_key?(:target) self.object = params[:object] if params.has_key?(:object) self. = params[:root_menu] if params.has_key?(:root_menu) self.title = params[:title] if params.has_key?(:title) self.validate = params[:validate] if params.has_key?(:validate) # Set NSApp as the default target if no other target is given if self.item_action && self.item_target.nil? self.item_target = NSApp end # Setup submenu and keyboard shortcut (params) set_keyboard_shortcut(params[:shortcut]) if params.has_key?(:shortcut) self end |
#valid? ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/menu-motion/menu_item.rb', line 47 def valid? if self. || self.valid_target_and_action? if self.validate.nil? true else self.validate.call(self) end else false end end |
#valid_target_and_action? ⇒ Boolean
59 60 61 |
# File 'lib/menu-motion/menu_item.rb', line 59 def valid_target_and_action? self.item_target && self.item_action && self.item_target.respond_to?(self.item_action.gsub(":", "")) end |