This repository was archived by the owner on Sep 21, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +49
-2
lines changed
packages/devtools-modules/src Expand file tree Collapse file tree 3 files changed +49
-2
lines changed Original file line number Diff line number Diff line change 22 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
5+ const { formatKeyShortcut } = require ( "../utils/text" ) ;
56const EventEmitter = require ( "../utils/event-emitter" ) ;
67
78function inToolbox ( ) {
@@ -138,6 +139,9 @@ Menu.prototype._createMenuItems = function(parent) {
138139 if ( item . id ) {
139140 menu . id = item . id ;
140141 }
142+ if ( item . accelerator ) {
143+ menuitem . setAttribute ( "acceltext" , formatKeyShortcut ( item . accelerator ) ) ;
144+ }
141145 parent . appendChild ( menu ) ;
142146 } else if ( item . type === "separator" ) {
143147 let menusep = doc . createElement ( "menuseparator" ) ;
@@ -170,7 +174,9 @@ Menu.prototype._createMenuItems = function(parent) {
170174 if ( item . id ) {
171175 menuitem . id = item . id ;
172176 }
173-
177+ if ( item . accelerator ) {
178+ menuitem . setAttribute ( "acceltext" , formatKeyShortcut ( item . accelerator ) ) ;
179+ }
174180 parent . appendChild ( menuitem ) ;
175181 }
176182 } ) ;
Original file line number Diff line number Diff line change 1212 * - role String - Define the action of the menu item; when specified the
1313 * click property will be ignored
1414 * - sublabel String
15- * - accelerator Accelerator
1615 * - icon NativeImage
1716 * - position String - This field allows fine-grained definition of the
1817 * specific location within a given menu.
3534 * will be automatically converted to one using Menu.buildFromTemplate.
3635 * Boolean visible
3736 * If false, the menu item will be entirely hidden.
37+ * String accelerator
38+ * If specified, will be used as accelerator text for MenuItem
3839 */
3940function MenuItem ( {
4041 accesskey = null ,
@@ -46,6 +47,7 @@ function MenuItem({
4647 submenu = null ,
4748 type = "normal" ,
4849 visible = true ,
50+ accelerator = "" ,
4951} = { } ) {
5052 this . accesskey = accesskey ;
5153 this . checked = checked ;
@@ -56,6 +58,7 @@ function MenuItem({
5658 this . submenu = submenu ;
5759 this . type = type ;
5860 this . visible = visible ;
61+ this . accelerator = accelerator ;
5962}
6063
6164module . exports = MenuItem ;
Original file line number Diff line number Diff line change 1+ /* This Source Code Form is subject to the terms of the Mozilla Public
2+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
4+
5+ /**
6+ * Utils for keyboard command strings
7+ * @module utils/text
8+ */
9+ import Services from "devtools-services" ;
10+ const { appinfo } = Services ;
11+
12+ const isMacOS = appinfo . OS === "Darwin" ;
13+
14+ /**
15+ * Formats key for use in tooltips
16+ * For macOS we use the following unicode
17+ *
18+ * cmd ⌘ = \u2318
19+ * shift ⇧ – \u21E7
20+ * option (alt) ⌥ \u2325
21+ *
22+ * For Win/Lin this replaces CommandOrControl or CmdOrCtrl with Ctrl
23+ *
24+ * @memberof utils/text
25+ * @static
26+ */
27+ export function formatKeyShortcut ( shortcut ) {
28+ if ( isMacOS ) {
29+ return shortcut
30+ . replace ( / S h i f t \+ / g, "\u21E7" )
31+ . replace ( / C o m m a n d \+ | C m d \+ / g, "\u2318" )
32+ . replace ( / C o m m a n d O r C o n t r o l \+ | C m d O r C t r l \+ / g, "\u2318" )
33+ . replace ( / A l t \+ / g, "\u2325" ) ;
34+ }
35+ return shortcut
36+ . replace ( / C o m m a n d O r C o n t r o l \+ | C m d O r C t r l \+ / g, "Ctrl" )
37+ . replace ( / S h i f t \+ / g, "Shift" ) ;
38+ }
You can’t perform that action at this time.
0 commit comments