everyday-menu 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e245af3b08954f17c48965a894d13e01b8335649
4
- data.tar.gz: 0ce77623e08bed86d0329e5e0d9a196e5261e7fe
3
+ metadata.gz: a54828a0a7db304a577074de86e42c80ce795a12
4
+ data.tar.gz: f82ed542d84b73465072a5e8c9c6b55d43924498
5
5
  SHA512:
6
- metadata.gz: 781454de5673aabd1a39be97feae58cb19dc1f2fd7fb21ac67e55ed0d12eadd3a8f7eb54a8f2145d34a0aac51a7c5d8c2b53a971124879f7a6a890e1fb837d59
7
- data.tar.gz: 8ee6356acd25e9ecc634fd900dc133f7a01c98a59e328c631aa1e928d6a5fdecb9fae745d126a2ca9ddc8c6a364ceb268b8ee2c68816b86170e9b91861767c7b
6
+ metadata.gz: e45812b9c587be046d51056505a761dd8a2439f082fca92cdee33700c8990e3d09c41a59e7b22706fc6695df774c63425e2e7bea399e62927b21d2754135561d
7
+ data.tar.gz: 411691c2aa1fc7a8aacd7636da4ffb6023f04bb45d244dde1b0801201acbd3506252c878451ffbffdd91bb4c75652501e5bc9233402ca4843e5cd8069a80d634
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # EverydayMenu
2
2
 
3
3
  ## Updates
4
- * Please see the "Introducing Presets!" section below for an awesome new feature!
5
- * Please see the "Introducing Statusbar Menus!" section below for another awesome new feature!
4
+ * 0.4.0:
5
+ * Please see the "Introducing Presets!" section below for an awesome new feature!
6
+ * 1.0.0:
7
+ * Please see the "Introducing Statusbar Menus!" section below for another awesome new feature!
6
8
 
7
9
  ## Issue Tracking
8
10
  Please use <https://everydayprogramminggenius.atlassian.net/browse/EM> for issue tracking.
@@ -44,6 +46,7 @@ class MainMenu
44
46
  menuItem :open, 'Open', key_equivalent: 'o'
45
47
  menuItem :new, 'New'
46
48
  menuItem :close, 'Close', key_equivalent: 'w'
49
+ menuItem :start_stop, 'Start'
47
50
  end
48
51
 
49
52
  ```
@@ -67,6 +70,8 @@ class MainMenu
67
70
  open
68
71
  ___
69
72
  close
73
+ ___
74
+ start_stop
70
75
  }
71
76
  end
72
77
  ```
@@ -79,8 +84,12 @@ class AppDelegate
79
84
  MainMenu.build!
80
85
 
81
86
  MainMenu[:app].subscribe(:hide_others) { |_, _| NSApp.hideOtherApplications(self) }
82
- MainMenu[:app].subscribe(:quit) { |_, _| NSApp.terminate(self) }
87
+ MainMenu[:app].subscribe(:quit) { |_, _| NSApp.terminate(self) }
83
88
 
89
+ MainMenu[:file].subscribe(:start_stop) { |command, _|
90
+ @started = !@started
91
+ command.parent[:title] = @started ? 'Stop' : 'Start'
92
+ }
84
93
  MainMenu[:file].subscribe(:new) { |_, _|
85
94
  @has_open = true
86
95
  puts 'new'
@@ -101,6 +110,8 @@ end
101
110
 
102
111
  You can even put multiple actions on a single item by calling subscribe multiple times.
103
112
 
113
+ The block passed to `subscribe` takes two parameters, the command instance and the sender. The command instance has knowledge of the label (`command.label`) and (as of version 1.1.0) the parent `EverydayMenu::MenuItem` instance (`command.parent`). In the above example, the parent instance is used to toggle the menu item text between 'Start' and 'Stop'.
114
+
104
115
  ## Introducing Presets!
105
116
  With version 0.4.0, I have added the capability to use some presets. Here is the above example with presets:
106
117
 
@@ -1,6 +1,7 @@
1
1
  class AppDelegate
2
2
  def applicationDidFinishLaunching(notification)
3
3
  @has_open = false
4
+ @started = false
4
5
  MainMenu.build!
5
6
 
6
7
  MainMenu[:file].subscribe(:new) { |_, _|
@@ -15,6 +16,10 @@ class AppDelegate
15
16
  @has_open = true
16
17
  puts 'open'
17
18
  }
19
+ MainMenu[:file].subscribe(:start_stop) { |command, _|
20
+ @started = !@started
21
+ command.parent[:title] = @started ? 'Stop' : 'Start'
22
+ }
18
23
  MainMenu[:statusbar].subscribe(:status_new) { |_, _|
19
24
  @has_open = true
20
25
  puts 'status-new'
@@ -10,6 +10,7 @@ class MainMenu
10
10
  menuItem :open, 'Open', key_equivalent: 'o'
11
11
  menuItem :new, 'New'
12
12
  menuItem :close, 'Close', key_equivalent: 'w'
13
+ menuItem :start_stop, 'Start'
13
14
 
14
15
  menuItem :status_open, 'Open', key_equivalent: 'o'
15
16
  menuItem :status_new, 'New'
@@ -31,6 +32,8 @@ class MainMenu
31
32
  open
32
33
  ___
33
34
  close
35
+ ___
36
+ start_stop
34
37
  }
35
38
 
36
39
  statusbarMenu(:statusbar, 'Statusbar Menu') {
@@ -121,7 +121,7 @@ module EverydayMenu
121
121
  end
122
122
 
123
123
  def subscribe(&block)
124
- @menuItem.subscribe(self.label, &block)
124
+ @menuItem.subscribe(self, self.label, &block)
125
125
  end
126
126
 
127
127
  def execute
@@ -133,8 +133,8 @@ end
133
133
  class NSMenuItem
134
134
  attr_reader :commands
135
135
 
136
- def subscribe(label, &block)
137
- @commands ||= EverydayMenu::CommandList.new(label)
136
+ def subscribe(parent, label, &block)
137
+ @commands ||= EverydayMenu::CommandList.new(parent, label)
138
138
  @commands.add &block
139
139
  command = @commands.last
140
140
  self.enabled = @commands.canExecute
@@ -1,9 +1,10 @@
1
1
  module EverydayMenu
2
2
  class EverydayCommand
3
- attr_reader :label
3
+ attr_reader :label, :parent
4
4
  attr_writer :canExecute
5
5
 
6
- def initialize(label, canExecute = true, &block)
6
+ def initialize(parent, label, canExecute = true, &block)
7
+ @parent = parent
7
8
  @label = label
8
9
  @block = block
9
10
  @canExecute = canExecute
@@ -26,13 +27,14 @@ module EverydayMenu
26
27
  class CommandList
27
28
  attr_accessor :label
28
29
 
29
- def initialize(label)
30
- @label = label
31
- @items = []
30
+ def initialize(parent, label)
31
+ @parent = parent
32
+ @label = label
33
+ @items = []
32
34
  end
33
35
 
34
36
  def add(&block)
35
- @items << EverydayCommand.new(@label, &block)
37
+ @items << EverydayCommand.new(@parent, @label, &block)
36
38
  end
37
39
 
38
40
  def last
@@ -1,3 +1,3 @@
1
1
  module EverydayMenu
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everyday-menu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Henderson