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: const gcli = require("gcli/index"); michael@0: const EventEmitter = require("devtools/toolkit/event-emitter"); michael@0: const eventEmitter = new EventEmitter(); michael@0: michael@0: let { Eyedropper, EyedropperManager } = require("devtools/eyedropper/eyedropper"); michael@0: michael@0: /** michael@0: * 'eyedropper' command michael@0: */ michael@0: exports.items = [{ michael@0: name: "eyedropper", michael@0: description: gcli.lookup("eyedropperDesc"), michael@0: manual: gcli.lookup("eyedropperManual"), michael@0: buttonId: "command-button-eyedropper", michael@0: buttonClass: "command-button command-button-invertable", michael@0: tooltipText: gcli.lookup("eyedropperTooltip"), michael@0: state: { michael@0: isChecked: function(target) { michael@0: let chromeWindow = target.tab.ownerDocument.defaultView; michael@0: let dropper = EyedropperManager.getInstance(chromeWindow); michael@0: if (dropper) { michael@0: return true; michael@0: } michael@0: return false; 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 chromeWindow = context.environment.chromeWindow; michael@0: let target = context.environment.target; michael@0: michael@0: let dropper = EyedropperManager.createInstance(chromeWindow); michael@0: dropper.open(); michael@0: michael@0: eventEmitter.emit("changed", target.tab); michael@0: michael@0: dropper.once("destroy", () => { michael@0: eventEmitter.emit("changed", target.tab); michael@0: }); michael@0: } michael@0: }];