Skip to content

Commit a66aac8

Browse files
committed
enhance disabled state of menubar items
1 parent bc10515 commit a66aac8

File tree

4 files changed

+57
-20
lines changed

4 files changed

+57
-20
lines changed

src/renderer/document/subs.cljs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
::recent
99
:-> :recent)
1010

11+
(rf/reg-sub
12+
::documents?
13+
:<- [:documents]
14+
(fn [documents _]
15+
(seq documents)))
16+
1117
(rf/reg-sub
1218
::recent?
1319
:<- [::recent]
1420
(fn [recent _]
1521
(seq recent)))
1622

17-
(rf/reg-sub
18-
::recent-disabled?
19-
:<- [::recent?]
20-
(fn [recent? _]
21-
(not recent?)))
22-
2323
(rf/reg-sub
2424
::active
2525
:<- [:documents]

src/renderer/menubar/styles.css

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
user-select: none;
4848
}
4949

50-
.sub-menu-tem {
50+
.sub-menu-tem {
5151
padding-right: 15px !important;
5252
}
5353

@@ -67,9 +67,14 @@
6767
.menu-item[data-disabled],
6868
.menu-sub-trigger[data-disabled],
6969
.menu-checkbox-item[data-disabled],
70-
.menu-radio-item[data-disabled] {
71-
color: var(--font-color-muted);
70+
.menu-radio-item[data-disabled],
71+
.menubar-trigger[data-disabled] {
72+
color: var(--font-color-disabled);
7273
pointer-events: none;
74+
75+
.right-slot {
76+
@apply opacity-50;
77+
}
7378
}
7479

7580
.menu-item-indicator {
@@ -95,7 +100,7 @@
95100
color: inherit;
96101
}
97102

98-
[data-highlighted] > .right-slot {
103+
[data-highlighted]>.right-slot {
99104
color: var(--font-color-active);
100105
}
101106

src/renderer/menubar/views.cljs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
[renderer.document.events :as-alias document.e]
99
[renderer.document.subs :as-alias document.s]
1010
[renderer.element.events :as-alias element.e]
11+
[renderer.element.subs :as-alias element.s]
1112
[renderer.frame.events :as-alias frame.e]
1213
[renderer.history.events :as-alias history.e]
14+
[renderer.history.subs :as-alias history.s]
1315
[renderer.window.events :as-alias window.e]
1416
[renderer.window.subs :as-alias window.s]))
1517

@@ -47,34 +49,39 @@
4749
{:key :recent
4850
:label "Recent"
4951
:type :sub-menu
50-
:disabled? [::document.s/recent-disabled?]
52+
:disabled? (not @(rf/subscribe [::document.s/recent?]))
5153
:items (recent-submenu)}
5254
{:key :divider-2
5355
:type :separator}
5456
{:key :save
5557
:label "Save"
5658
:icon "save"
5759
:action [::document.e/save]
58-
:disabled? [::document.s/active-saved?]}
60+
:disabled? (or (not @(rf/subscribe [::document.s/documents?]))
61+
@(rf/subscribe [::document.s/active-saved?]))}
5962
{:key :save-as
6063
:label "Save as…"
6164
:icon "save-as"
62-
:action [::document.e/save-as]}
65+
:action [::document.e/save-as]
66+
:disabled? (not @(rf/subscribe [::document.s/documents?]))}
6367
{:key :download
6468
:icon "download"
6569
:label "Download"
70+
:disabled? (not @(rf/subscribe [::document.s/documents?]))
6671
:action [::document.e/download]}
6772
{:key :divider-3
6873
:type :separator}
6974
{:key :export
7075
:label "Export as SVG"
7176
:icon "export"
77+
:disabled? (not @(rf/subscribe [::document.s/documents?]))
7278
:action [::element.e/export]}
7379
{:key :divider-4
7480
:type :separator}
7581
{:key :close
7682
:label "Close"
7783
:icon "times"
84+
:disabled? (not @(rf/subscribe [::document.s/documents?]))
7885
:action [::document.e/close-active]}
7986
{:key :exit
8087
:label "Exit"
@@ -86,22 +93,27 @@
8693
{:key :edit
8794
:label "Edit"
8895
:type :root
96+
:disabled? (not @(rf/subscribe [::document.s/documents?]))
8997
:items [{:key :undo
9098
:label "Undo"
9199
:icon "undo"
100+
:disabled? (not @(rf/subscribe [::history.s/undos?]))
92101
:action [::history.e/undo]}
93102
{:key :redo
94103
:label "Redo"
95104
:icon "redo"
105+
:disabled? (not @(rf/subscribe [::history.s/redos?]))
96106
:action [::history.e/redo]}
97107
{:key :divider-1
98108
:type :separator}
99109
{:key :cut
100110
:label "Cut"
111+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
101112
:action [::element.e/cut]}
102113
{:key :copy
103114
:icon "copy"
104115
:label "Copy"
116+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
105117
:action [::element.e/copy]}
106118
{:key :paste
107119
:label "Paste"
@@ -120,6 +132,7 @@
120132
{:key :duplicate
121133
:icon "copy"
122134
:label "Duplicate"
135+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
123136
:action [::element.e/duplicate-in-place]}
124137
{:key :divider-3
125138
:type :separator}
@@ -130,26 +143,30 @@
130143
{:key :deselect-all
131144
:icon "deselect-all"
132145
:label "Deselect all"
146+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
133147
:action [::element.e/deselect-all]}
134148
{:key :invert-selection
135149
:label "Invert selection"
136150
:action [::element.e/invert-selection]}
137151
{:key :select-same-tags
138152
:icon "select-same"
139153
:label "Select same tags"
154+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
140155
:action [::element.e/select-same-tags]}
141156
{:key :divider-4
142157
:type :separator}
143158
{:key :delete
144159
:icon "delete"
145160
:label "Delete"
161+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
146162
:action [::element.e/delete]}]})
147163

148164
(defn align-submenu
149165
[]
150166
[{:key :align-left
151167
:label "Left"
152168
:icon "objects-align-left"
169+
:disabled @(rf/subscribe [::element.s/top-level?])
153170
:action [::element.e/align :left]}
154171
{:key :align-center-horizontally
155172
:label "Center horizontally"
@@ -235,63 +252,77 @@
235252
{:key :object
236253
:label "Object"
237254
:type :root
255+
:disabled? (not @(rf/subscribe [::document.s/documents?]))
238256
:items [{:key :to-path
239257
:label "Object to path"
258+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
240259
:action [::element.e/->path]}
241260
{:key :stroke-to-path
242261
:label "Stroke to path"
262+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
243263
:action [::element.e/stroke->path]}
244264
{:key :divider-1
245265
:type :separator}
246266
{:key :group
247267
:label "Group"
248268
:icon "group"
269+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
249270
:action [::element.e/group]}
250271
{:key :ungroup
251272
:label "Ungroup"
252273
:icon "ungroup"
274+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
253275
:action [::element.e/ungroup]}
254276
{:key :divider-2
255277
:type :separator}
256278
{:key :lock
257279
:label "Lock"
258280
:icon "lock"
281+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
259282
:action [::element.e/lock]}
260283
{:key :unlock
261284
:label "Unlock"
262285
:icon "unlock"
286+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
263287
:action [::element.e/unlock]}
264288
{:key :divider-3
265289
:type :separator}
266290
{:key :path
267291
:label "Align"
268292
:type :sub-menu
293+
:disabled? @(rf/subscribe [::element.s/top-level?])
269294
:items (align-submenu)}
270295
{:key :boolean
271296
:label "Animate"
272297
:type :sub-menu
298+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
273299
:items (animate-submenu)}
274300
{:key :boolean
275301
:label "Boolean operation"
276302
:type :sub-menu
303+
:disabled? (not @(rf/subscribe [::element.s/multiple-selected?]))
277304
:items (boolean-submenu)}
278305
{:key :divider-4
279306
:type :separator}
280307
{:key :raise
281308
:label "Raise"
282309
:icon "bring-forward"
310+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
283311
:action [::element.e/raise]}
284312
{:key :lower
285313
:label "Lower"
286314
:icon "send-backward"
315+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
287316
:action [::element.e/lower]}
288317
{:key :raise-to-top
289318
:label "Raise to top"
290319
:icon "bring-front"
320+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
291321
:action [::element.e/raise-to-top]}
292322
{:key :lower-to-bottom
293323
:label "Lower to bottom"
294324
:icon "send-back"
325+
:disabled? (not @(rf/subscribe [::element.s/selected?]))
295326
:action [::element.e/lower-to-bottom]}
296327
{:key :divider-5
297328
:type :separator}
@@ -392,6 +423,7 @@
392423
{:key :view
393424
:label "View"
394425
:type :root
426+
:disabled? (not @(rf/subscribe [::document.s/documents?]))
395427
:items [{:key :zoom
396428
:label "Zoom"
397429
:type :sub-menu
@@ -497,7 +529,7 @@
497529
[:> Menubar/Sub
498530
[:> Menubar/SubTrigger
499531
{:class "sub-menu-item menu-item"
500-
:disabled (when disabled? @(rf/subscribe disabled?))}
532+
:disabled disabled?}
501533
label
502534
[:div.right-slot.sub-menu-chevron
503535
[comp/icon "chevron-right" {:class "icon small"}]]]
@@ -509,11 +541,12 @@
509541
(map menu-item items))]])
510542

511543
(defmethod menu-item :root
512-
[{:keys [label items key action]}]
544+
[{:keys [label items key action disabled?]}]
513545
[:> Menubar/Menu
514546
[:> Menubar/Trigger
515547
{:class "menubar-trigger"
516548
:id (name key)
549+
:disabled disabled?
517550
:on-click (when action #(rf/dispatch action))
518551
:on-key-down (fn [e]
519552
; FIXME: Doesn't work when the menu content is open.
@@ -534,7 +567,7 @@
534567
{:class "menu-item"
535568
:onSelect #(do (rf/dispatch action)
536569
(rf/dispatch [:focus nil]))
537-
:disabled (when disabled? @(rf/subscribe disabled?))}
570+
:disabled disabled?}
538571
label
539572
[:div.right-slot
540573
[comp/shortcuts action]]])

src/renderer/theme.css

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
:root {
32
--font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI (Custom)',
4-
'Roboto', 'Helvetica Neue', 'Open Sans (Custom)', system-ui, sans-serif,
5-
'Apple Color Emoji', 'Segoe UI Emoji';
3+
'Roboto', 'Helvetica Neue', 'Open Sans (Custom)', system-ui, sans-serif,
4+
'Apple Color Emoji', 'Segoe UI Emoji';
65
--font-mono: 'Consolas (Custom)', 'Bitstream Vera Sans Mono', monospace,
7-
'Apple Color Emoji', 'Segoe UI Emoji';
6+
'Apple Color Emoji', 'Segoe UI Emoji';
87
--font-size: 13px;
98

109
--bg-secondary: #222;

0 commit comments

Comments
 (0)