everyday-menu 1.2.0 → 1.3.0

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: 66daeba8da989301477c3d0b2474c5d32ad19011
4
- data.tar.gz: 9d47532f129aaea7c5057dba34872fd588b19401
3
+ metadata.gz: 070446116cd1b8619df4634a2615d0fe56bd54b7
4
+ data.tar.gz: 625c092f45698dab96d3fe6bc50218eeb3dbeba7
5
5
  SHA512:
6
- metadata.gz: cf969107f17c26e64f3e19e64ddb1e9b251f8c432c7f563cc6633fac82cf8a98375d9b7fb065b08a6883e65a3a19e0019e604dff2925c7b217d145d59cb78e05
7
- data.tar.gz: 3b34fa1275f028cda1ae152809f0f559b89a5663d3c13574636852eda8b2d1a29079943633dd0f58e599c0c74874d4a072804231ab0081a7e08c24f47d969ac7
6
+ metadata.gz: 1b692b467c2bcf26a9c4a31f83003135a8766cf36ab80968f7237f28d22196d0a1d788e5cdf53854948e5bdea9e6497a18da5fb8cd4e0f780de84478f11e90e1
7
+ data.tar.gz: 17a5b9ada1e707ada94b4406cd51591ba423db275e3ce31436cf1e2ff256ae1bd87ce422c35f141376975f433411dbaded4804ed1ed7464e56061c1db1e7ceac
data/.gitignore CHANGED
@@ -23,3 +23,5 @@ vendor
23
23
  /projectFilesBackup/
24
24
 
25
25
  /.repl_history
26
+
27
+ /.dat3715.000
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in drink-menu.gemspec
4
4
  gemspec
5
+
6
+ gem 'rm-digest'
data/README.md CHANGED
@@ -1,18 +1,34 @@
1
1
  # EverydayMenu
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/everyday-menu.png)](http://badge.fury.io/rb/everyday-menu)
4
+
3
5
  ## Updates
6
+ * 0.2.0:
7
+ * Create `EverydayCommand` to allow control of enablement of menu items
8
+ * 0.2.1:
9
+ * Fix a set method issue and resolve the error messages about missing methods
10
+ * 0.3.0:
11
+ * Add handling for `NSApp.servicesMenu`, `NSApp.windowsMenu`, and `NSApp.helpMenu`
4
12
  * 0.4.0:
5
13
  * Please see the "Introducing Presets!" section below for an awesome new feature!
6
14
  * 1.0.0:
7
15
  * Please see the "Introducing Statusbar Menus!" section below for another awesome new feature!
16
+ * 1.1.0:
17
+ * Added reference to parent `MenuItem` instance to `EverydayCommand`
18
+ * 1.2.0:
19
+ * Added the ability to have individual ids for each command
20
+ * 1.3.0:
21
+ * Commands now get a random id if you don't give them one
22
+ * You can now access a command by id
23
+ * I now have a runtime dependency, the gem `rm-digest`, but it has the necessary objective-c code built-in, so there shouldn't be any extra work for users of `everyday-menu`
8
24
 
9
25
  ## Issue Tracking
10
26
  Please use <https://everydayprogramminggenius.atlassian.net/browse/EM> for issue tracking.
11
27
 
12
28
  ## Credit
13
- Please note that this gem is strongly based off of Joe Fiorini's `drink-menu` gem (with a little code copy-paste and lots of test and readme copy-paste), which I couldn't get to work for me.
29
+ Please note that this gem is based off of Joe Fiorini's `drink-menu` gem (with a little code copy-paste and lots of test and readme copy-paste), which I couldn't get to work for me.
14
30
 
15
- You can find his gem at <https://github.com/joefiorini/drink-menu>. He doesn't get all of the credit, but he gets a lot of it.
31
+ You can find his gem at <https://github.com/joefiorini/drink-menu>. He doesn't get all of the credit, but he gets a fair amount of it.
16
32
 
17
33
  ## Installation
18
34
 
@@ -104,10 +120,15 @@ class AppDelegate
104
120
  puts 'close'
105
121
  }.canExecuteBlock { |_| @has_open }
106
122
 
107
- MainMenu[:file].subscribe(:open) { |_, _|
123
+ MainMenu[:file].subscribe(:open) { |command, _|
108
124
  @has_open = true
109
125
  puts 'open'
126
+ puts "open subscribe 1 command id: #{command.command_id}"
127
+ }
128
+ MainMenu[:file].subscribe(:open) { |command, _|
129
+ puts "open subscribe 2 command id: #{command.command_id}"
110
130
  }
131
+ puts "start_stop subscribe 1 parent label: #{MainMenu[:file].items[:start_stop][:commands][:start_stop_command_id].label}"
111
132
  end
112
133
  end
113
134
  ```
@@ -19,4 +19,6 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency 'bundler', '~> 1.3'
21
21
  spec.add_development_dependency 'rake', '~> 10.0'
22
+
23
+ spec.add_dependency 'rm-digest'
22
24
  end
@@ -12,17 +12,21 @@ class AppDelegate
12
12
  @has_open = false
13
13
  puts 'close'
14
14
  }.canExecuteBlock { |_| @has_open }
15
- MainMenu[:file].subscribe(:open) { |_, _|
15
+ MainMenu[:file].subscribe(:open) { |command, _|
16
16
  @has_open = true
17
17
  puts 'open'
18
+ puts "open subscribe 1 command id: #{command.command_id}"
19
+ }
20
+ MainMenu[:file].subscribe(:open) { |command, _|
21
+ puts "open subscribe 2 command id: #{command.command_id}"
18
22
  }
19
23
  MainMenu[:file].subscribe(:start_stop, :start_stop_command_id) { |command, _|
20
24
  @started = !@started
21
25
  command.parent[:title] = @started ? 'Stop' : 'Start'
22
- puts "subscribe 1 command id: #{command.command_id}"
26
+ puts "start_stop subscribe 1 command id: #{command.command_id}"
23
27
  }
24
28
  MainMenu[:file].subscribe(:start_stop, :start_stop_command_id2) { |command, _|
25
- puts "subscribe 2 command id: #{command.command_id}"
29
+ puts "start_stop subscribe 2 command id: #{command.command_id}"
26
30
  }
27
31
  MainMenu[:statusbar].subscribe(:status_new) { |_, _|
28
32
  @has_open = true
@@ -36,5 +40,6 @@ class AppDelegate
36
40
  @has_open = true
37
41
  puts 'status-open'
38
42
  }
43
+ puts "start_stop subscribe 1 parent label: #{MainMenu[:file].items[:start_stop][:commands][:start_stop_command_id].label}"
39
44
  end
40
45
  end
@@ -127,6 +127,10 @@ module EverydayMenu
127
127
  def execute
128
128
  @menuItem.runBlock(self)
129
129
  end
130
+
131
+ def commands
132
+ @commands ||= EverydayMenu::CommandList.new(self, self.label)
133
+ end
130
134
  end
131
135
  end
132
136
 
@@ -134,10 +138,9 @@ class NSMenuItem
134
138
  attr_reader :commands
135
139
 
136
140
  def subscribe(parent, label, command_id = nil, &block)
137
- @commands ||= EverydayMenu::CommandList.new(parent, label)
138
- @commands.add command_id, &block
139
- command = @commands.last
140
- self.enabled = @commands.canExecute
141
+ @commands ||= parent.commands
142
+ command = parent.commands.add command_id, &block
143
+ self.enabled = parent.commands.canExecute
141
144
  unless @boundEnabled
142
145
  @boundEnabled = true
143
146
  self.bind(NSEnabledBinding, toObject: self.commands, withKeyPath: 'canExecute', options: nil)
@@ -1,3 +1,7 @@
1
+ class EverydayRmDigest
2
+ include RmDigest
3
+ end
4
+
1
5
  module EverydayMenu
2
6
  class EverydayCommand
3
7
  attr_reader :label, :parent, :command_id
@@ -32,11 +36,25 @@ module EverydayMenu
32
36
  def initialize(parent, label)
33
37
  @parent = parent
34
38
  @label = label
35
- @items = []
39
+ @items = {}
40
+ @rand = Random.new
41
+ end
42
+
43
+ def unique_id
44
+ EverydayRmDigest::MD5.hexdigest("#{@rand.rand}#{@rand.rand}")
45
+ end
46
+
47
+ def rand_id
48
+ :"command_id_#{unique_id}"
36
49
  end
37
50
 
38
51
  def add(command_id = nil, &block)
39
- @items << EverydayCommand.new(@parent, @label, command_id, &block)
52
+ id = command_id || rand_id
53
+ @items[id] = EverydayCommand.new(@parent, @label, id, &block)
54
+ end
55
+
56
+ def [](id)
57
+ @items[id]
40
58
  end
41
59
 
42
60
  def last
@@ -44,11 +62,11 @@ module EverydayMenu
44
62
  end
45
63
 
46
64
  def execute(sender)
47
- @items.each { |item| item.execute(sender) }
65
+ @items.values.each { |item| item.execute(sender) }
48
66
  end
49
67
 
50
68
  def canExecute
51
- @items.any? { |item| item.canExecute }
69
+ @items.values.any? { |item| item.canExecute }
52
70
  end
53
71
  end
54
72
 
@@ -1,3 +1,3 @@
1
1
  module EverydayMenu
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everyday-menu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Henderson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-20 00:00:00.000000000 Z
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rm-digest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: An easy way to define menu items and visually lay out menus for your
42
56
  OSX apps. Based strongly on the drink-menu gem that I couldn't get to work for me.
43
57
  email: