gecko/toolkit/devtools/gcli/commands/tools.js
Joe Walker ffa9c6e99c Bug 984365 - Refactor and split out BuiltinCommands.jsm; r=mratcliffe,robcee,panos
BuiltinCommands.jsm was huge to avoid slowing things down by having many
modules loading.

To avoid splitting it up from slowing things down we want to delay loading
commands. Create [add|remove]ItemsByModule to allow us to lazily add modules,
and convert all command modules to use this.

Then break up BuiltinCommands into a set of files, for each command, and do
some refactoring to use JS files rather than JSMs and use "use strict".

--HG--
rename : browser/devtools/commandline/Commands.jsm => browser/devtools/commandline/commands-index.js
rename : browser/devtools/debugger/CmdDebugger.jsm => browser/devtools/debugger/debugger-commands.js
rename : browser/devtools/inspector/CmdInspect.jsm => browser/devtools/inspector/inspector-commands.js
rename : browser/devtools/responsivedesign/CmdResize.jsm => browser/devtools/responsivedesign/resize-commands.js
rename : browser/devtools/scratchpad/CmdScratchpad.jsm => browser/devtools/scratchpad/scratchpad-commands.js
rename : browser/devtools/styleeditor/CmdEdit.jsm => browser/devtools/styleeditor/styleeditor-commands.js
rename : browser/devtools/tilt/CmdTilt.jsm => browser/devtools/tilt/tilt-commands.js
2014-04-13 07:47:27 +01:00

88 lines
2.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/. */
"use strict";
const { Cc, Ci, Cu } = require("chrome");
const Services = require("Services");
const { OS } = require("resource://gre/modules/osfile.jsm");
const { devtools } = require("resource://gre/modules/devtools/Loader.jsm");
const gcli = require("gcli/index");
const BRAND_SHORT_NAME = Cc["@mozilla.org/intl/stringbundle;1"]
.getService(Ci.nsIStringBundleService)
.createBundle("chrome://branding/locale/brand.properties")
.GetStringFromName("brandShortName");
exports.items = [
{
name: "tools",
description: gcli.lookupFormat("toolsDesc2", [ BRAND_SHORT_NAME ]),
manual: gcli.lookupFormat("toolsManual2", [ BRAND_SHORT_NAME ]),
get hidden() gcli.hiddenByChromePref(),
},
{
name: "tools srcdir",
description: gcli.lookup("toolsSrcdirDesc"),
manual: gcli.lookupFormat("toolsSrcdirManual2", [ BRAND_SHORT_NAME ]),
get hidden() gcli.hiddenByChromePref(),
params: [
{
name: "srcdir",
type: "string" /* {
name: "file",
filetype: "directory",
existing: "yes"
} */,
description: gcli.lookup("toolsSrcdirDir")
}
],
returnType: "string",
exec: function(args, context) {
let clobber = OS.Path.join(args.srcdir, "CLOBBER");
return OS.File.exists(clobber).then(function(exists) {
if (exists) {
let str = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString);
str.data = args.srcdir;
Services.prefs.setComplexValue("devtools.loader.srcdir",
Ci.nsISupportsString, str);
devtools.reload();
let msg = gcli.lookupFormat("toolsSrcdirReloaded", [ args.srcdir ]);
throw new Error(msg);
}
return gcli.lookupFormat("toolsSrcdirNotFound", [ args.srcdir ]);
});
}
},
{
name: "tools builtin",
description: gcli.lookup("toolsBuiltinDesc"),
manual: gcli.lookup("toolsBuiltinManual"),
get hidden() gcli.hiddenByChromePref(),
returnType: "string",
exec: function(args, context) {
Services.prefs.clearUserPref("devtools.loader.srcdir");
devtools.reload();
return gcli.lookup("toolsBuiltinReloaded");
}
},
{
name: "tools reload",
description: gcli.lookup("toolsReloadDesc"),
get hidden() {
return gcli.hiddenByChromePref() ||
!Services.prefs.prefHasUserValue("devtools.loader.srcdir");
},
returnType: "string",
exec: function(args, context) {
devtools.reload();
return gcli.lookup("toolsReloaded2");
}
}
];