Class: MotionKit::MenuLayout
- Inherits:
-
TreeLayout
- Object
- BaseLayout
- TreeLayout
- MotionKit::MenuLayout
- Defined in:
- lib/motion-kit-osx/helpers/nsmenu_helpers.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BaseLayout
Instance Method Summary collapse
-
#add(title_or_item, element_id = nil, options = {}, &block) ⇒ Object
override ‘add’; menus are just a horse of a different color.
- #add_child(submenu) ⇒ Object
- #create(title_or_item, element_id = nil, &block) ⇒ Object
-
#default_root ⇒ Object
platform specific default root view.
- #item(title, options = {}) ⇒ Object
-
#menu ⇒ Object
A more sensible name for the menu that is created.
- #remove_child(submenu) ⇒ Object
-
#root(element, element_id = nil, &block) ⇒ Object
override root to allow a menu title for the top level menu.
Methods inherited from TreeLayout
#all, #all_views, #build, #built?, #child_layouts, #create_default_root_context, #first, #forget, #get, #get_view, #initial, #initial?, #initialize, #last, #last_view, #name_element, #nearest, #next, #nth, #nth_view, #prev, #reapply, #reapply!, #reapply?, #remove, view, #view
Methods inherited from BaseLayout
#add_deferred_block, #apply, #apply_with_context, #apply_with_target, #context, #deferred, #deferred_blocks, delegate_method_fix, #has_context?, #initialize, #ipad?, #iphone35?, #iphone4?, #iphone?, #is_parent_layout?, #method_missing, #objc_version, #orientation?, #parent_layout, #retina?, #ruby_version, #run_deferred, #set_parent_layout, #target, #v
Methods included from BaseLayoutClassMethods
#layout_for, #memoize, #target_klasses, #targets
Constructor Details
This class inherits a constructor from MotionKit::TreeLayout
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class MotionKit::BaseLayout
Instance Method Details
#add(title_or_item, element_id = nil, options = {}, &block) ⇒ Object
override ‘add’; menus are just a horse of a different color.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/motion-kit-osx/helpers/nsmenu_helpers.rb', line 36 def add(title_or_item, element_id=nil, ={}, &block) if element_id.is_a?(NSDictionary) = element_id element_id = nil end if title_or_item.is_a?(NSMenuItem) item = title_or_item = nil retval = item elsif title_or_item.is_a?(NSMenu) = title_or_item item = self.item(.title, ) item. = retval = else title = title_or_item item = self.item(title, ) if block = create(title) item. = retval = else retval = item end end self.apply(:add_child, item) if && block = @menu_item @menu_item = item context(, &block) @menu_item = end if element_id create(retval, element_id) end return retval end |
#add_child(submenu) ⇒ Object
19 20 21 |
# File 'lib/motion-kit-osx/helpers/nsmenu_helpers.rb', line 19 def add_child() target.addItem() end |
#create(title_or_item, element_id = nil, &block) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/motion-kit-osx/helpers/nsmenu_helpers.rb', line 80 def create(title_or_item, element_id=nil, &block) if title_or_item.is_a?(NSString) item = NSMenu.alloc.initWithTitle(title_or_item) else item = title_or_item end return super(item, element_id, &block) end |
#default_root ⇒ Object
platform specific default root view
13 14 15 16 17 |
# File 'lib/motion-kit-osx/helpers/nsmenu_helpers.rb', line 13 def default_root # child WindowLayout classes can return *their* NSView subclass from self.nsview_class = self.class.targets || NSMenu .alloc.init end |
#item(title, options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/motion-kit-osx/helpers/nsmenu_helpers.rb', line 90 def item(title, ={}) action = .fetch(:action, nil) key = .fetch(:keyEquivalent, .fetch(:key, '')) key ||= '' # key must never be nil item = NSMenuItem.alloc.initWithTitle(title, action: action, keyEquivalent: key) mask = .fetch(:keyEquivalentModifierMask, .fetch(:mask, nil)) unless mask.nil? item.keyEquivalentModifierMask = mask end return item end |
#menu ⇒ Object
A more sensible name for the menu that is created.
8 9 10 |
# File 'lib/motion-kit-osx/helpers/nsmenu_helpers.rb', line 8 def self.view end |
#remove_child(submenu) ⇒ Object
23 24 25 |
# File 'lib/motion-kit-osx/helpers/nsmenu_helpers.rb', line 23 def remove_child() target.removeItem() end |
#root(element, element_id = nil, &block) ⇒ Object
override root to allow a menu title for the top level menu
28 29 30 31 32 33 |
# File 'lib/motion-kit-osx/helpers/nsmenu_helpers.rb', line 28 def root(element, element_id=nil, &block) if element && element.is_a?(NSString) element = NSMenu.alloc.initWithTitle(element) end super(element, element_id, &block) end |