menu-motion 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 017c1789cf0bfe842b95fd4da3e14ab67fe563d1
4
- data.tar.gz: 6a6d164c184310adfedf3dda0a938c28b32808fd
3
+ metadata.gz: 81a470e891e3ef0dc469a6184e66a3fc9261a6a0
4
+ data.tar.gz: 47c198b68132494dc529a7a7bcb622825bc4caf3
5
5
  SHA512:
6
- metadata.gz: b9ea50176c4efd7f6ae481d2972bcc35115b9f66cb6a8b8d849984546c5dbadd838d044b793cc4c66fd9f17851843441c93c67957d62ca8a38fbd79d2463761f
7
- data.tar.gz: 67dd921c1153d5cbfc0ac8aeac270243537f1d2045d67e3af336846ea88fd2c407e4c2dc666aef27e1b7da1c894752eff8729d8ef089e16db8c51654eba1e9b0
6
+ metadata.gz: 376ab57eac16f013695eb5fde29f28281ee6d6f73e5378ac32401be718f7313d2b13801fb5039d9fcbbae0109a702e033ecb42acba33e73b826193ca3ce68fd5
7
+ data.tar.gz: abbef473c9bd1ce0a81dfaa90ee98e20cce65abea2aac33c11c22f9e803f25ccb86a537f7e2cfd46efa9254552b61a3cb19e850f6c36d591b6244c2ecbd0b06c
data/README.md CHANGED
@@ -32,10 +32,10 @@ Here's an awesome graphic of a menu:
32
32
  ```
33
33
  |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
34
34
  | [icon] First Item > |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
35
- |---------------------| First Subitem > |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
36
- | About MenuMotion |-----------------| First Action |
37
- | Quit | Some Action | Second Action |
38
- |_____________________|_________________|_______________|
35
+ |---------------------| First Subitem > |‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|
36
+ | About MenuMotion |-----------------| First Action |
37
+ | Quit | Some Action | Second Action |
38
+ |_____________________|_________________|_________________|
39
39
  ```
40
40
 
41
41
  And the Ruby to generate this menu:
@@ -57,14 +57,15 @@ menu = MenuMotion::Menu.new({
57
57
  }, {
58
58
  title: "Second Action",
59
59
  target: self,
60
- action: "second_action"
60
+ action: "second_action",
61
+ checked: true
61
62
  }]
62
63
  }]
63
64
  }, {
64
65
  rows: [{
65
66
  title: "Some Action",
66
67
  target: self,
67
- action: "some_action"
68
+ action: :some_action
68
69
  }]
69
70
  }]
70
71
  }]
@@ -115,14 +116,14 @@ menu = MenuMotion::Menu.new({
115
116
  ### Actions
116
117
 
117
118
  Adding an action to a menu item is easy. Just define the
118
- target and action parameters.
119
+ target and action parameters. Actions that don't require the `sender` to be passed can be defined as a `String` or a `:symbol`.
119
120
 
120
121
  ```ruby
121
122
  menu = MenuMotion::Menu.new({
122
123
  rows: [{
123
124
  title: "Basic Action",
124
125
  target: self,
125
- action: "basic_action"
126
+ action: :basic_action
126
127
  }, {
127
128
  title: "Pass the menu item to the action",
128
129
  target: self,
@@ -17,6 +17,11 @@ module MenuMotion
17
17
  self.state = (value ? NSOnState : NSOffState)
18
18
  end
19
19
 
20
+ def image=(value)
21
+ value = NSImage.imageNamed(value) unless value.is_a?(NSImage)
22
+ self.setImage(value)
23
+ end
24
+
20
25
  def initialize(params = {})
21
26
  super()
22
27
  update(params)
@@ -34,13 +39,10 @@ module MenuMotion
34
39
  end
35
40
 
36
41
  def update(params)
37
- self.checked = params[:checked] if params.has_key?(:checked)
38
- self.item_action = params[:action] if params.has_key?(:action)
39
- self.item_target = params[:target] if params.has_key?(:target)
40
- self.object = params[:object] if params.has_key?(:object)
41
- self.root_menu = params[:root_menu] if params.has_key?(:root_menu)
42
- self.title = params[:title] if params.has_key?(:title)
43
- self.validate = params[:validate] if params.has_key?(:validate)
42
+ assign_attributes(params)
43
+
44
+ self.item_action = params[:action] if params.has_key?(:action)
45
+ self.item_target = params[:target] if params.has_key?(:target)
44
46
 
45
47
  # Set NSApp as the default target if no other target is given
46
48
  if self.item_action && self.item_target.nil?
@@ -116,6 +118,14 @@ module MenuMotion
116
118
  end
117
119
  end
118
120
 
121
+ private
122
+
123
+ def assign_attributes(params)
124
+ [:image, :view, :checked, :object, :root_menu, :title, :validate].each do |key|
125
+ self.send("#{key}=", params[key]) if params.has_key?(key)
126
+ end
127
+ end
128
+
119
129
  end
120
130
 
121
131
  end
@@ -1,3 +1,3 @@
1
1
  module MenuMotion
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: menu-motion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Pattison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake