Bug 1580545 - Convert ResponsiveUI and ResponsiveUIManager to ES6 classes. r=mtigley
[gecko.git] / devtools / client / menus.js
blob1e756867208da3012712e250219403d284e5b56b
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/. */
5 "use strict";
7 /**
8  * This module defines the sorted list of menuitems inserted into the
9  * "Web Developer" menu.
10  * It also defines the key shortcuts that relates to them.
11  *
12  * Various fields are necessary for historical compatiblity with XUL/addons:
13  * - id:
14  *   used as <xul:menuitem> id attribute
15  * - l10nKey:
16  *   prefix used to locale localization strings from menus.properties
17  * - oncommand:
18  *   function called when the menu item or key shortcut are fired
19  * - keyId:
20  *   Identifier used in devtools/client/devtools-startup.js
21  *   Helps figuring out the DOM id for the related <xul:key>
22  *   in order to have the key text displayed in menus.
23  * - checkbox:
24  *   If true, the menuitem is prefixed by a checkbox and runtime code can
25  *   toggle it.
26  */
28 const { Cu } = require("chrome");
30 loader.lazyRequireGetter(
31   this,
32   "gDevToolsBrowser",
33   "devtools/client/framework/devtools-browser",
34   true
36 loader.lazyRequireGetter(
37   this,
38   "TargetFactory",
39   "devtools/client/framework/target",
40   true
42 loader.lazyRequireGetter(
43   this,
44   "ResponsiveUIManager",
45   "devtools/client/responsive/manager"
47 loader.lazyRequireGetter(
48   this,
49   "openDocLink",
50   "devtools/client/shared/link",
51   true
54 loader.lazyImporter(
55   this,
56   "BrowserToolboxProcess",
57   "resource://devtools/client/framework/ToolboxProcess.jsm"
59 loader.lazyImporter(
60   this,
61   "ScratchpadManager",
62   "resource://devtools/client/scratchpad/scratchpad-manager.jsm"
64 loader.lazyImporter(
65   this,
66   "ProfilerMenuButton",
67   "resource://devtools/client/performance-new/popup/menu-button.jsm"
70 exports.menuitems = [
71   {
72     id: "menu_devToolbox",
73     l10nKey: "devToolboxMenuItem",
74     async oncommand(event) {
75       try {
76         const window = event.target.ownerDocument.defaultView;
77         await gDevToolsBrowser.toggleToolboxCommand(window.gBrowser, Cu.now());
78       } catch (e) {
79         console.error(`Exception while opening the toolbox: ${e}\n${e.stack}`);
80       }
81     },
82     keyId: "toggleToolbox",
83     checkbox: true,
84   },
85   { id: "menu_devtools_separator", separator: true },
86   {
87     id: "menu_devtools_remotedebugging",
88     l10nKey: "devtoolsRemoteDebugging",
89     oncommand(event) {
90       const window = event.target.ownerDocument.defaultView;
91       gDevToolsBrowser.openAboutDebugging(window.gBrowser);
92     },
93   },
94   {
95     id: "menu_webide",
96     l10nKey: "webide",
97     oncommand() {
98       gDevToolsBrowser.openWebIDE();
99     },
100     keyId: "webide",
101   },
102   {
103     id: "menu_browserToolbox",
104     l10nKey: "browserToolboxMenu",
105     oncommand() {
106       BrowserToolboxProcess.init();
107     },
108     keyId: "browserToolbox",
109   },
110   {
111     id: "menu_browserContentToolbox",
112     l10nKey: "browserContentToolboxMenu",
113     oncommand(event) {
114       const window = event.target.ownerDocument.defaultView;
115       gDevToolsBrowser.openContentProcessToolbox(window.gBrowser);
116     },
117   },
118   {
119     id: "menu_browserConsole",
120     l10nKey: "browserConsoleCmd",
121     oncommand() {
122       const {
123         BrowserConsoleManager,
124       } = require("devtools/client/webconsole/browser-console-manager");
125       BrowserConsoleManager.openBrowserConsoleOrFocus();
126     },
127     keyId: "browserConsole",
128   },
129   {
130     id: "menu_toggleProfilerButtonMenu",
131     l10nKey: "toggleProfilerButtonMenu",
132     checkbox: true,
133     oncommand(event) {
134       ProfilerMenuButton.toggle(event.target.ownerDocument);
135     },
136   },
137   {
138     id: "menu_responsiveUI",
139     l10nKey: "responsiveDesignMode",
140     oncommand(event) {
141       const window = event.target.ownerDocument.defaultView;
142       ResponsiveUIManager.toggle(window, window.gBrowser.selectedTab, {
143         trigger: "menu",
144       });
145     },
146     keyId: "responsiveDesignMode",
147     checkbox: true,
148   },
149   {
150     id: "menu_eyedropper",
151     l10nKey: "eyedropper",
152     async oncommand(event) {
153       const window = event.target.ownerDocument.defaultView;
154       const target = await TargetFactory.forTab(window.gBrowser.selectedTab);
155       await target.attach();
156       const inspectorFront = await target.getFront("inspector");
157       inspectorFront.pickColorFromPage({ copyOnSelect: true, fromMenu: true });
158     },
159     checkbox: true,
160   },
161   {
162     id: "menu_scratchpad",
163     l10nKey: "scratchpad",
164     oncommand() {
165       ScratchpadManager.openScratchpad();
166     },
167     keyId: "scratchpad",
168   },
169   {
170     id: "menu_devtools_connect",
171     l10nKey: "devtoolsConnect",
172     oncommand(event) {
173       const window = event.target.ownerDocument.defaultView;
174       gDevToolsBrowser.openConnectScreen(window.gBrowser);
175     },
176   },
177   { separator: true, id: "devToolsEndSeparator" },
178   {
179     id: "getMoreDevtools",
180     l10nKey: "getMoreDevtoolsCmd",
181     oncommand(event) {
182       openDocLink(
183         "https://addons.mozilla.org/firefox/collections/mozilla/webdeveloper/"
184       );
185     },
186   },