menu-motion 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 934a02195b3c68b51b5bcfdf5f0907d7d3717995
4
+ data.tar.gz: 5f6f318336f94e483f9cc58d2d7c17f1e42583f6
5
+ SHA512:
6
+ metadata.gz: 833c111856c289a0c5b3d977640e3d65cb92b9d02daeb6385164349b79d03582b3925b3ad1ca19888579d38039db043bd2715b6bdeefc21d46449555e5630555
7
+ data.tar.gz: 815b050b4d22bbbda7601e30417897d897e75a268dd1235b03f6cde46ad4e1a773f0bfe47b5cc0088851d926fb9ee9c1d036f964c45e0fcd93b6293f2dc58adf
data/README.md ADDED
@@ -0,0 +1,185 @@
1
+ # MenuMotion
2
+
3
+ MenuMotion is a RubyMotion wrapper inspired by Formotion for creating OS X status bar menus with a syntax that should feel familiar if you've used Formotion.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "menu-motion"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```sh
22
+ $ gem install menu-motion
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Here's an awesome graphic of a menu:
28
+
29
+ ```
30
+ |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
31
+ | [icon] First Item > |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
32
+ |---------------------| First Subitem > |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
33
+ | About MenuMotion |-----------------| First Action |
34
+ | Quit | Some Action | Second Action |
35
+ |_____________________|_________________|_______________|
36
+ ```
37
+
38
+ And the Ruby to generate this menu:
39
+
40
+ ```ruby
41
+ menu = MenuMotion::Menu.new({
42
+ sections: [{
43
+ rows: [{
44
+ icon: "icon.png",
45
+ title: "First Item",
46
+ sections: [{
47
+ rows: [{
48
+ title: "First Subitem",
49
+ rows: [{
50
+ title: "First Action",
51
+ target: self,
52
+ action: "first_action"
53
+ }, {
54
+ title: "Second Action",
55
+ target: self,
56
+ action: "second_action"
57
+ }]
58
+ }]
59
+ }, {
60
+ rows: [{
61
+ title: "Some Action",
62
+ target: self,
63
+ action: "some_action"
64
+ }]
65
+ }]
66
+ }]
67
+ }, {
68
+ rows: [{
69
+ title: "About MenuMotion",
70
+ target: self,
71
+ action: "about"
72
+ }, {
73
+ title: "Quit",
74
+ target: self,
75
+ action: "quit"
76
+ }]
77
+ }]
78
+ })
79
+ ```
80
+
81
+ ### Sections
82
+
83
+ Sections are used to add dividers between sets of "rows" (menu items).
84
+
85
+ ```ruby
86
+ menu = MenuMotion::Menu.new({
87
+ sections: [{
88
+ rows: []
89
+ }, {
90
+ rows: []
91
+ }
92
+ })
93
+ ```
94
+
95
+ ### Submenus
96
+
97
+ To link a menu item to a submenu, simply define sections
98
+ or rows within the row item that should display the submenu.
99
+
100
+ ```ruby
101
+ menu = MenuMotion::Menu.new({
102
+ rows: [{
103
+ title: "Menu item",
104
+ rows: [{
105
+ title: "Submenu item 1"
106
+ }, {
107
+ title: "Submenu item 2"
108
+ }]
109
+ }]
110
+ })
111
+ ```
112
+
113
+ ### Actions
114
+
115
+ Adding an action to a menu item is easy. Just define the
116
+ target and action.
117
+
118
+ ```ruby
119
+ menu = MenuMotion::Menu.new({
120
+ rows: [{
121
+ title: "Basic Action",
122
+ target: self,
123
+ action: "basic_action"
124
+ }, {
125
+ title: "Pass the menu item to the action",
126
+ target: self,
127
+ action: "action_with_sender:"
128
+ }]
129
+ })
130
+
131
+ def basic_action
132
+ puts "Hello World"
133
+ end
134
+
135
+ def action_with_sender(sender)
136
+ puts "Hello from #{sender}"
137
+ end
138
+ ```
139
+
140
+ ### Updating Menu Items
141
+
142
+ Assign keys to menu items that will need to be updated.
143
+
144
+ ```ruby
145
+ menu = MenuMotion::Menu.new({
146
+ rows: [{
147
+ title: "Menu item",
148
+ key: :main_item
149
+ rows: [{
150
+ title: "Submenu item 1",
151
+ key: :submenu_item1,
152
+ target: self,
153
+ action: "do_something:"
154
+ }, {
155
+ title: "Submenu item 2",
156
+ key: :submenu_item2,
157
+ target: self,
158
+ action: "do_something:"
159
+ }]
160
+ }]
161
+ })
162
+
163
+ # Let's update the first item's title:
164
+ menu.update(:main_item, {
165
+ title: "Hello World"
166
+ })
167
+
168
+ # And give the first submenu item a submenu.
169
+ # The target and action will not be used if a submenu is defined.
170
+ menu.update(:submenu_item1, {
171
+ rows: [{
172
+ title: "Click me",
173
+ target: self,
174
+ action: "clicked"
175
+ }]
176
+ })
177
+ ```
178
+
179
+ ## Contributing
180
+
181
+ 1. Fork it
182
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
183
+ 3. Commit your changes (`git commit -am "Add some feature"`)
184
+ 4. Push to the branch (`git push origin my-new-feature`)
185
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ unless defined?(Motion::Project::Config)
4
+ raise "This file must be required within a RubyMotion project Rakefile."
5
+ end
6
+
7
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
8
+ Motion::Project::App.setup do |app|
9
+ app.files.unshift(Dir.glob(File.join(lib_dir_path, "menu_motion/**/*.rb")))
10
+ end
@@ -0,0 +1,88 @@
1
+ module MenuMotion
2
+
3
+ class Menu < NSMenu
4
+
5
+ attr_accessor :menu_items
6
+ attr_accessor :root_menu
7
+
8
+ def add_rows_to_menu(menu, rows)
9
+ rows.each do |row|
10
+ menu_item = NSMenuItem.alloc.initWithTitle(row[:title], action: row[:action], keyEquivalent:"")
11
+ menu_item.target = row[:target]
12
+
13
+ # Add sections and/or rows to a submenu
14
+ if row[:sections]
15
+ submenu = MenuMotion::Menu.new({
16
+ sections: row[:sections]
17
+ }, self.root_menu || self)
18
+ menu_item.setSubmenu(submenu)
19
+ elsif row[:rows]
20
+ submenu = MenuMotion::Menu.new({
21
+ rows: row[:rows]
22
+ }, self.root_menu || self)
23
+ menu_item.setSubmenu(submenu)
24
+ end
25
+
26
+ if row[:key]
27
+ if self.root_menu
28
+ self.root_menu.menu_items ||= {}
29
+ self.root_menu.menu_items[row[:key].to_sym] = WeakRef.new(menu_item)
30
+ else
31
+ self.menu_items ||= {}
32
+ self.menu_items[row[:key].to_sym] = WeakRef.new(menu_item)
33
+ end
34
+ end
35
+
36
+ menu.addItem(menu_item)
37
+ end
38
+ end
39
+
40
+ def add_sections_to_menu(menu, sections)
41
+ sections.each_with_index do |section, index|
42
+ if section[:rows]
43
+ if index > 0
44
+ # Add the separator before the new section,
45
+ # skipping the first section
46
+ menu.addItem(NSMenuItem.separatorItem)
47
+ end
48
+ add_rows_to_menu(menu, section[:rows])
49
+ end
50
+ end
51
+ end
52
+
53
+ def build_menu_from_params(menu, params)
54
+ if params[:sections]
55
+ add_sections_to_menu(menu, params[:sections])
56
+ elsif params[:rows]
57
+ add_rows_to_menu(menu, params[:rows])
58
+ end
59
+ end
60
+
61
+ def initialize(params = {}, root_menu = nil)
62
+ super()
63
+
64
+ self.root_menu = root_menu
65
+ self.build_menu_from_params(self, params)
66
+
67
+ self
68
+ end
69
+
70
+ def item_with_key(key)
71
+ @menu_items ||= {}
72
+ @menu_items[key.to_sym]
73
+ end
74
+
75
+ def update(key, params)
76
+ menu_item = self.item_with_key(key)
77
+
78
+ menu_item.title = params[:title] if params[:title]
79
+ menu_item.target = params[:target] if params[:target]
80
+ menu_item.action = params[:action] if params[:action]
81
+
82
+ self
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
@@ -0,0 +1,3 @@
1
+ module MenuMotion
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: menu-motion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Brian Pattison
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: MenuMotion is a RubyMotion wrapper inspired by Formotion for creating
28
+ OS X status bar menus with a syntax that should feel familiar if you've used Formotion.
29
+ email:
30
+ - brian@brianpattison.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - lib/menu_motion.rb
37
+ - lib/menu_motion/menu.rb
38
+ - lib/menu_motion/version.rb
39
+ homepage: https://github.com/codelation/menu-motion
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.2.2
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: A RubyMotion wrapper for creating OS X status bar menus
63
+ test_files: []
64
+ has_rdoc: