michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const gcli = require("gcli/index"); michael@0: const EventEmitter = require("devtools/toolkit/event-emitter"); michael@0: const { gDevTools } = require("resource:///modules/devtools/gDevTools.jsm"); michael@0: michael@0: const eventEmitter = new EventEmitter(); michael@0: michael@0: gDevTools.on("toolbox-ready", (e, toolbox) => { michael@0: if (!toolbox.target) { michael@0: return; michael@0: } michael@0: michael@0: let fireChangeForTab = () => { michael@0: eventEmitter.emit("changed", toolbox.target.tab); michael@0: }; michael@0: michael@0: toolbox.on("split-console", fireChangeForTab); michael@0: toolbox.on("select", fireChangeForTab); michael@0: michael@0: toolbox.once("destroyed", () => { michael@0: toolbox.off("split-console", fireChangeForTab); michael@0: toolbox.off("select", fireChangeForTab); michael@0: }); michael@0: }); michael@0: michael@0: exports.items = [ michael@0: { michael@0: name: 'splitconsole', michael@0: hidden: true, michael@0: buttonId: "command-button-splitconsole", michael@0: buttonClass: "command-button command-button-invertable", michael@0: tooltipText: gcli.lookup("splitconsoleTooltip"), michael@0: state: { michael@0: isChecked: function(target) { michael@0: let toolbox = gDevTools.getToolbox(target); michael@0: return toolbox && toolbox.splitConsole; michael@0: }, michael@0: onChange: function(target, changeHandler) { michael@0: eventEmitter.on("changed", changeHandler); michael@0: }, michael@0: offChange: function(target, changeHandler) { michael@0: eventEmitter.off("changed", changeHandler); michael@0: }, michael@0: }, michael@0: exec: function(args, context) { michael@0: let target = context.environment.target; michael@0: let toolbox = gDevTools.getToolbox(target); michael@0: michael@0: if (!toolbox) { michael@0: return gDevTools.showToolbox(target, "inspector").then((toolbox) => { michael@0: toolbox.toggleSplitConsole(); michael@0: }); michael@0: } else { michael@0: toolbox.toggleSplitConsole(); michael@0: } michael@0: } michael@0: }, michael@0: { michael@0: name: "console", michael@0: description: gcli.lookup("consoleDesc"), michael@0: manual: gcli.lookup("consoleManual") michael@0: }, michael@0: { michael@0: name: "console clear", michael@0: description: gcli.lookup("consoleclearDesc"), michael@0: exec: function(args, context) { michael@0: let toolbox = gDevTools.getToolbox(context.environment.target); michael@0: if (toolbox == null) { michael@0: return; michael@0: } michael@0: michael@0: let panel = toolbox.getPanel("webconsole"); michael@0: if (panel == null) { michael@0: return; michael@0: } michael@0: michael@0: panel.hud.jsterm.clearOutput(); michael@0: } michael@0: }, michael@0: { michael@0: name: "console close", michael@0: description: gcli.lookup("consolecloseDesc"), michael@0: exec: function(args, context) { michael@0: return gDevTools.closeToolbox(context.environment.target); michael@0: } michael@0: }, michael@0: { michael@0: name: "console open", michael@0: description: gcli.lookup("consoleopenDesc"), michael@0: exec: function(args, context) { michael@0: return gDevTools.showToolbox(context.environment.target, "webconsole"); michael@0: } michael@0: } michael@0: ];