|
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 "use strict"; |
|
6 |
|
7 const gcli = require("gcli/index"); |
|
8 const EventEmitter = require("devtools/toolkit/event-emitter"); |
|
9 const { gDevTools } = require("resource:///modules/devtools/gDevTools.jsm"); |
|
10 |
|
11 const eventEmitter = new EventEmitter(); |
|
12 |
|
13 gDevTools.on("toolbox-ready", (e, toolbox) => { |
|
14 if (!toolbox.target) { |
|
15 return; |
|
16 } |
|
17 |
|
18 let fireChangeForTab = () => { |
|
19 eventEmitter.emit("changed", toolbox.target.tab); |
|
20 }; |
|
21 |
|
22 toolbox.on("split-console", fireChangeForTab); |
|
23 toolbox.on("select", fireChangeForTab); |
|
24 |
|
25 toolbox.once("destroyed", () => { |
|
26 toolbox.off("split-console", fireChangeForTab); |
|
27 toolbox.off("select", fireChangeForTab); |
|
28 }); |
|
29 }); |
|
30 |
|
31 exports.items = [ |
|
32 { |
|
33 name: 'splitconsole', |
|
34 hidden: true, |
|
35 buttonId: "command-button-splitconsole", |
|
36 buttonClass: "command-button command-button-invertable", |
|
37 tooltipText: gcli.lookup("splitconsoleTooltip"), |
|
38 state: { |
|
39 isChecked: function(target) { |
|
40 let toolbox = gDevTools.getToolbox(target); |
|
41 return toolbox && toolbox.splitConsole; |
|
42 }, |
|
43 onChange: function(target, changeHandler) { |
|
44 eventEmitter.on("changed", changeHandler); |
|
45 }, |
|
46 offChange: function(target, changeHandler) { |
|
47 eventEmitter.off("changed", changeHandler); |
|
48 }, |
|
49 }, |
|
50 exec: function(args, context) { |
|
51 let target = context.environment.target; |
|
52 let toolbox = gDevTools.getToolbox(target); |
|
53 |
|
54 if (!toolbox) { |
|
55 return gDevTools.showToolbox(target, "inspector").then((toolbox) => { |
|
56 toolbox.toggleSplitConsole(); |
|
57 }); |
|
58 } else { |
|
59 toolbox.toggleSplitConsole(); |
|
60 } |
|
61 } |
|
62 }, |
|
63 { |
|
64 name: "console", |
|
65 description: gcli.lookup("consoleDesc"), |
|
66 manual: gcli.lookup("consoleManual") |
|
67 }, |
|
68 { |
|
69 name: "console clear", |
|
70 description: gcli.lookup("consoleclearDesc"), |
|
71 exec: function(args, context) { |
|
72 let toolbox = gDevTools.getToolbox(context.environment.target); |
|
73 if (toolbox == null) { |
|
74 return; |
|
75 } |
|
76 |
|
77 let panel = toolbox.getPanel("webconsole"); |
|
78 if (panel == null) { |
|
79 return; |
|
80 } |
|
81 |
|
82 panel.hud.jsterm.clearOutput(); |
|
83 } |
|
84 }, |
|
85 { |
|
86 name: "console close", |
|
87 description: gcli.lookup("consolecloseDesc"), |
|
88 exec: function(args, context) { |
|
89 return gDevTools.closeToolbox(context.environment.target); |
|
90 } |
|
91 }, |
|
92 { |
|
93 name: "console open", |
|
94 description: gcli.lookup("consoleopenDesc"), |
|
95 exec: function(args, context) { |
|
96 return gDevTools.showToolbox(context.environment.target, "webconsole"); |
|
97 } |
|
98 } |
|
99 ]; |