gecko-dev/browser/devtools/eyedropper/commands.js
Joe Walker 9cc5a4d6b3 Bug 1128988 - runAt support for commands/converters; r=bgrins
--HG--
rename : browser/devtools/main.js => browser/devtools/definitions.js
2015-04-23 10:24:49 +01:00

58 lines
1.8 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const l10n = require("gcli/l10n");
const EventEmitter = require("devtools/toolkit/event-emitter");
const eventEmitter = new EventEmitter();
let { Eyedropper, EyedropperManager } = require("devtools/eyedropper/eyedropper");
/**
* 'eyedropper' command
*/
exports.items = [{
item: "command",
runAt: "client",
name: "eyedropper",
description: l10n.lookup("eyedropperDesc"),
manual: l10n.lookup("eyedropperManual"),
buttonId: "command-button-eyedropper",
buttonClass: "command-button command-button-invertable",
tooltipText: l10n.lookup("eyedropperTooltip"),
state: {
isChecked: function(target) {
if (!target.tab) {
return false;
}
let chromeWindow = target.tab.ownerDocument.defaultView;
let dropper = EyedropperManager.getInstance(chromeWindow);
if (dropper) {
return true;
}
return false;
},
onChange: function(target, changeHandler) {
eventEmitter.on("changed", changeHandler);
},
offChange: function(target, changeHandler) {
eventEmitter.off("changed", changeHandler);
},
},
exec: function(args, context) {
let chromeWindow = context.environment.chromeWindow;
let target = context.environment.target;
let dropper = EyedropperManager.createInstance(chromeWindow,
{ context: "command",
copyOnSelect: true });
dropper.open();
eventEmitter.emit("changed", { target: target });
dropper.once("destroy", () => {
eventEmitter.emit("changed", { target: target });
});
}
}];