Class: MotionKit::NSMenuLayout
- Inherits:
-
MenuLayout
show all
- Defined in:
- lib/motion-kit-osx/layouts/nsmenu_layout.rb,
lib/motion-kit-osx/layouts/nsmenu_extensions.rb,
lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb
Instance Attribute Summary
Attributes inherited from BaseLayout
#parent
Instance Method Summary
collapse
-
#_menu_title_and_options(title, options, default_title = nil, default_options = {}) ⇒ Object
-
#about_item(title = nil, options = {}) ⇒ Object
-
#app_menu(title = nil, options = {}) ⇒ Object
-
#app_name ⇒ Object
useful when writing menus.
-
#attributed_title(value) ⇒ Object
-
#attributedTitle(value) ⇒ Object
-
#bring_all_to_front_item(title = nil, options = {}) ⇒ Object
-
#close_item(title = nil, options = {}) ⇒ Object
-
#file_menu(title = nil, options = {}) ⇒ Object
-
#help_item(title = nil, options = {}) ⇒ Object
-
#help_menu(title = nil, options = {}) ⇒ Object
-
#hide_item(title = nil, options = {}) ⇒ Object
-
#hide_others_item(title = nil, options = {}) ⇒ Object
-
#key_equivalent_modifier_mask(value) ⇒ Object
-
#keyEquivalentModifierMask(value) ⇒ Object
-
#minimize_item(title = nil, options = {}) ⇒ Object
-
#new_item(title = nil, options = {}) ⇒ Object
-
#open_item(title = nil, options = {}) ⇒ Object
-
#page_setup_item(title = nil, options = {}) ⇒ Object
-
#preferences_item(title = nil, options = {}) ⇒ Object
-
#print_item(title = nil, options = {}) ⇒ Object
-
#quit_item(title = nil, options = {}) ⇒ Object
-
#revert_to_save_item(title = nil, options = {}) ⇒ Object
-
#save_as_item(title = nil, options = {}) ⇒ Object
-
#save_item(title = nil, options = {}) ⇒ Object
-
#separator_item ⇒ Object
-
#services_item(title = nil, options = {}) ⇒ Object
-
#show_all_item(title = nil, options = {}) ⇒ Object
-
#state(value) ⇒ Object
-
#tag(value) ⇒ Object
-
#title(value) ⇒ Object
sets the title of the current NSMenu AND it’s parent NSMenuItem.
-
#window_menu(title = nil, options = {}) ⇒ Object
-
#zoom_item(title = nil, options = {}) ⇒ Object
Methods inherited from MenuLayout
#add, #add_child, #create, #default_root, #item, #menu, #remove_child, #root
Methods inherited from TreeLayout
#add, #all, #call_style_method, #create, #create_default_root_context, #first, #get, #initial, #last, #nth, #reapply, #reapply!, #remove, #root, #view, view
Methods inherited from BaseLayout
#add_deferred_block, #apply, #apply_with_context, #apply_with_target, #context, #deferred, #deferred_blocks, delegate_method_fix, #initialize, #ipad?, #iphone35?, #iphone4?, #iphone?, method_added, #method_missing, #orientation?, overridden_methods, override_start, override_stop, overrides, #retina?, #run_deferred, #set_layout, #target, #v
#layout_for, #memoize, #new_child, #target_klasses, #targets
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class MotionKit::BaseLayout
Instance Method Details
#_menu_title_and_options(title, options, default_title = nil, default_options = {}) ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 10
def _menu_title_and_options(title, options, default_title=nil, default_options={})
if title.is_a?(NSDictionary)
options = title
title = options[:title]
end
title ||= default_title
return title, default_options.merge(options)
end
|
#about_item(title = nil, options = {}) ⇒ Object
90
91
92
93
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 90
def about_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, "About #{app_name}", { action: 'orderFrontStandardAboutPanel:' })
return self.item(title, options)
end
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 19
def (title=nil, options={})
title, options = _menu_title_and_options(title, options, app_name)
exclude = Array(options.fetch(:exclude, []))
return create(title) do
unless exclude.include?(:about)
add about_item
add separator_item
end
unless exclude.include?(:prefs)
add preferences_item
add separator_item
end
unless exclude.include?(:services)
add services_item
add separator_item
end
unless exclude.include?(:hide)
add hide_item
add hide_others_item
end
add show_all_item unless exclude.include?(:show)
add quit_item unless exclude.include?(:quit)
end
end
|
useful when writing menus
6
7
8
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 6
def app_name
NSBundle.mainBundle.infoDictionary['CFBundleName']
end
|
#attributed_title(value) ⇒ Object
23
24
25
26
|
# File 'lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb', line 23
def attributed_title(value)
target.title = value.to_s
.attributedTitle = value
end
|
#attributedTitle(value) ⇒ Object
18
19
20
21
|
# File 'lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb', line 18
def attributedTitle(value)
target.title = value.to_s
.attributedTitle = value
end
|
#bring_all_to_front_item(title = nil, options = {}) ⇒ Object
175
176
177
178
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 175
def bring_all_to_front_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Bring All To Front', { action: 'arrangeInFront:' })
return self.item(title, options)
end
|
#close_item(title = nil, options = {}) ⇒ Object
135
136
137
138
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 135
def close_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Close', { key: 'w', action: 'performClose:' })
return self.item(title, options)
end
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 45
def (title=nil, options={})
title, options = _menu_title_and_options(title, options, 'File')
exclude = Array(options.fetch(:exclude, []))
return create(title) do
add new_item unless exclude.include?(:new)
add open_item unless exclude.include?(:open)
add separator_item unless [:new, :open].all? { || exclude.include?() }
add close_item unless exclude.include?(:close)
add save_item unless exclude.include?(:save)
add revert_to_save_item unless exclude.include?(:revert)
add separator_item unless [:close, :save, :revert].all? { || exclude.include?() }
add page_setup_item unless exclude.include?(:page_setup)
add print_item unless exclude.include?(:print)
end
end
|
#help_item(title = nil, options = {}) ⇒ Object
180
181
182
183
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 180
def help_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, "#{app_name} Help", { key: '?', action: 'showHelp:' })
return self.item("#{app_name} Help", options)
end
|
77
78
79
80
81
82
83
84
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 77
def (title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Help')
exclude = Array(options.fetch(:exclude, []))
return create(title) do
add help_item
end
end
|
#hide_item(title = nil, options = {}) ⇒ Object
105
106
107
108
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 105
def hide_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, "Hide #{app_name}", { key: 'h', action: 'hide:' })
return self.item(title, options)
end
|
#hide_others_item(title = nil, options = {}) ⇒ Object
110
111
112
113
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 110
def hide_others_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Hide Others', { key: 'h', action: 'hideOtherApplications:', mask: NSCommandKeyMask | NSAlternateKeyMask })
return self.item(title, options)
end
|
#key_equivalent_modifier_mask(value) ⇒ Object
40
41
42
|
# File 'lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb', line 40
def key_equivalent_modifier_mask(value)
.keyEquivalentModifierMask = value
end
|
#keyEquivalentModifierMask(value) ⇒ Object
36
37
38
|
# File 'lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb', line 36
def keyEquivalentModifierMask(value)
.keyEquivalentModifierMask = value
end
|
#minimize_item(title = nil, options = {}) ⇒ Object
165
166
167
168
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 165
def minimize_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Minimize', { key: 'm', action: 'performMiniaturize:' })
return self.item(title, options)
end
|
#new_item(title = nil, options = {}) ⇒ Object
125
126
127
128
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 125
def new_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'New', { key: 'n', action: 'newDocument:' })
return self.item(title, options)
end
|
#open_item(title = nil, options = {}) ⇒ Object
130
131
132
133
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 130
def open_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Open…', { key: 'o', action: 'openDocument:' })
return self.item(title, options)
end
|
#page_setup_item(title = nil, options = {}) ⇒ Object
155
156
157
158
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 155
def page_setup_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Page Setup…', { key: 'P', action: 'runPageLayout:' })
return self.item(title, options)
end
|
#preferences_item(title = nil, options = {}) ⇒ Object
95
96
97
98
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 95
def preferences_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Preferences', { key: ',', action: 'openPreferences:' })
return self.item(title, options)
end
|
#print_item(title = nil, options = {}) ⇒ Object
160
161
162
163
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 160
def print_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Print…', { key: 'p', action: 'printDocument:' })
return self.item(title, options)
end
|
#quit_item(title = nil, options = {}) ⇒ Object
120
121
122
123
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 120
def quit_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, "Quit #{app_name}", { key: 'q', action: 'terminate:' })
return self.item(title, options)
end
|
#revert_to_save_item(title = nil, options = {}) ⇒ Object
150
151
152
153
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 150
def revert_to_save_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Revert to Saved', { action: 'revertDocumentToSaved:' })
return self.item(title, options)
end
|
#save_as_item(title = nil, options = {}) ⇒ Object
145
146
147
148
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 145
def save_as_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Save as…', { key: 'S', action: 'saveDocumentAs:' })
return self.item(title, options)
end
|
#save_item(title = nil, options = {}) ⇒ Object
140
141
142
143
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 140
def save_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Save…', { key: 's', action: 'saveDocument:' })
return self.item(title, options)
end
|
#separator_item ⇒ Object
86
87
88
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 86
def separator_item
.separatorItem
end
|
#services_item(title = nil, options = {}) ⇒ Object
100
101
102
103
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 100
def services_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Services')
return self.item(title, options)
end
|
#show_all_item(title = nil, options = {}) ⇒ Object
115
116
117
118
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 115
def show_all_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Show All', { action: 'unhideAllApplications:' })
return self.item(title, options)
end
|
#state(value) ⇒ Object
28
29
30
|
# File 'lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb', line 28
def state(value)
.state = value
end
|
#tag(value) ⇒ Object
32
33
34
|
# File 'lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb', line 32
def tag(value)
.tag = value
end
|
#title(value) ⇒ Object
sets the title of the current NSMenu AND it’s parent NSMenuItem
13
14
15
16
|
# File 'lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb', line 13
def title(value)
target.title = value
.title = value
end
|
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 64
def (title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Window')
exclude = Array(options.fetch(:exclude, []))
return create(title) do
add minimize_item unless exclude.include?(:minimize)
add zoom_item unless exclude.include?(:zoom)
add separator_item unless [:minimize, :zoom].all? { || exclude.include?() }
add bring_all_to_front_item unless exclude.include?(:bring_all_to_front)
end
end
|
#zoom_item(title = nil, options = {}) ⇒ Object
170
171
172
173
|
# File 'lib/motion-kit-osx/layouts/nsmenu_extensions.rb', line 170
def zoom_item(title=nil, options={})
title, options = _menu_title_and_options(title, options, 'Zoom', { action: 'performMiniaturize:' })
return self.item(title, options)
end
|