1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-04 19:15:46 +01:00

Accept command line arguments in :rehash. Document :rehash, add :exttoggle, :extrehash.

--HG--
branch : bootstrapped
This commit is contained in:
Kris Maglione
2010-12-28 09:25:53 -05:00
parent 7b4e64f0bf
commit 83aa5e4857
6 changed files with 111 additions and 19 deletions

View File

@@ -162,7 +162,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
template.usage(results, params.format));
},
{
argCount: "*",
argCount: "0",
completer: function (context, args) {
context.keys.text = util.identity;
context.keys.description = function () seen[this.text] + " matching items";
@@ -1176,14 +1176,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
* @see Commands#parseArgs
*/
parseCommandLine: function (cmdline) {
const options = [
[["+u"], CommandOption.STRING],
[["++noplugin"], CommandOption.NOARG],
[["++cmd"], CommandOption.STRING, null, null, true],
[["+c"], CommandOption.STRING, null, null, true]
].map(CommandOption.fromArray, CommandOption);
try {
return commands.parseArgs(cmdline, { options: options, argCount: "*" });
return commands.get("rehash").parseArgs(cmdline);
}
catch (e) {
dactyl.reportError(e, true);
@@ -1688,15 +1682,32 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
filter: function ({ item }) !item.userDisabled,
perm: "disable"
},
{
name: "extr[ehash]",
description: "Reload an extension",
action: function (addon) {
dactyl.assert(dactyl.has("Gecko2"), "This command is not useful in this version of " + config.host);
util.timeout(function () {
addon.userDisabled = true;
addon.userDisabled = false;
});
},
filter: function ({ item }) !item.userDisabled,
perm: "disable"
},
{
name: "extt[oggle]",
description: "Toggle an extension's enabled status",
action: function (addon) addon.userDisabled = !addon.userDisabled
},
{
name: "extu[pdate]",
description: "Update an extension",
actions: updateAddons,
filter: function ({ item }) !item.userDisabled,
perm: "upgrade"
}
].forEach(function (command) {
let perm = AddonManager["PERM_CAN_" + command.perm.toUpperCase()];
let perm = command.perm && AddonManager["PERM_CAN_" + command.perm.toUpperCase()];
function ok(addon) !perm || addon.permissions & perm;
commands.add([command.name],
command.description,
@@ -1877,7 +1888,31 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
commands.add(["reh[ash]"],
"Reload the " + config.appName + " add-on",
function () { util.rehash(); });
function (args) { util.rehash(args); },
{
argCount: "0",
options: [
{
names: ["+u"],
description: "The initialization file to execute at startup",
type: CommandOption.STRING
},
{
names: ["++noplugin"],
description: "Do not automatically load plugins"
},
{
names: ["++cmd"],
description: "Ex commands to execute prior to initialization",
multiple: true
},
{
names: ["+c"],
description: "Ex commands to execute after initialization",
multiple: true
}
]
});
commands.add(["res[tart]"],
"Force " + config.appName + " to restart",
@@ -2106,10 +2141,15 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
if (!services.commandLineHandler)
services.add("commandLineHandler", "@mozilla.org/commandlinehandler/general-startup;1?type=" + config.name);
if (services.commandLineHandler) {
let commandline = services.commandLineHandler.optionValue;
if (commandline) {
let args = dactyl.parseCommandLine(commandline);
try {
if (services.fuel)
var args = services.fuel.storage.get("dactyl.commandlineArgs", null);
if (!args) {
let commandline = services.commandLineHandler.optionValue;
if (commandline)
args = dactyl.parseCommandLine(commandline);
}
if (args) {
dactyl.commandLineOptions.rcFile = args["+u"];
dactyl.commandLineOptions.noPlugins = "++noplugin" in args;
dactyl.commandLineOptions.postCommands = args["+c"];
@@ -2117,6 +2157,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
util.dump("Processing command-line option: " + commandline);
}
}
catch (e) {
dactyl.echoerr("Parsing command line options: " + e);
}
dactyl.log("Command-line options: " + util.objectToString(dactyl.commandLineOptions), 3);

View File

@@ -358,6 +358,28 @@ want to bypass &dactyl.appName;'s key handling and pass keys directly to
</description>
</item>
<item>
<tags>:reh :rehash</tags>
<spec>:reh<oa>ash</oa> <oa>arg</oa></spec>
<description>
<p>
Reload the &dactyl.appName; add-on, including all code, plugins,
and configuration. For users running directly from the development
repository, this is a good way to update to the latest version or
to test your changes.
</p>
<p>
Any arguments supplied are parsed as command line arguments as
specified in <t>startup-options</t>.
</p>
<warning>
Not all plugins are designed to cleanly un-apply during a rehash.
While official plugins are safe, beware of possibility instability
if you rehash while running third-party plugins.
</warning>
</description>
</item>
<item>
<tags>:re :reload</tags>
<spec>:re<oa>load</oa><oa>!</oa></spec>

View File

@@ -153,10 +153,33 @@
</description>
</item>
<item>
<tags>:extr :extrehash</tags>
<spec>:extr<oa>ehash</oa> <a>extension</a></spec>
<spec>:extr<oa>ehash</oa></spec>
<description>
<p>
Toggle an extension's enabled status twice. This is useful for rebooting
a restartless extension.
</p>
</description>
</item>
<item>
<tags>:extt :exttoggle</tags>
<spec>:extt<oa>oggle</oa> <a>extension</a></spec>
<spec>:extt<oa>oggle</oa></spec>
<description>
<p>
Toggle an extension's enabled status.
</p>
</description>
</item>
<item>
<tags>:extu :extupdate</tags>
<spec>:extu<oa>pdate</oa> <a>extension</a></spec>
<spec>:extu<oa>pdate</oa>!</spec>
<spec>:extu<oa>pdate</oa><oa>!</oa></spec>
<description>
<p>
Update an extension. When <oa>!</oa> is given, update all

View File

@@ -36,7 +36,7 @@ var Services = Module("Services", {
this.add("extensionManager", "@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager);
this.add("favicon", "@mozilla.org/browser/favicon-service;1", Ci.nsIFaviconService);
this.add("focus", "@mozilla.org/focus-manager;1", Ci.nsIFocusManager);
this.add("fuel", "@mozilla.org/fuel/application;1", Ci.fuelIApplication);
this.add("fuel", "@mozilla.org/fuel/application;1", Ci.extIApplication);
this.add("history", "@mozilla.org/browser/global-history;2", [Ci.nsIBrowserHistory, Ci.nsIGlobalHistory3,
Ci.nsINavHistoryService, Ci.nsPIPlacesDatabase]);
this.add("io", "@mozilla.org/network/io-service;1", Ci.nsIIOService);

View File

@@ -1187,7 +1187,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
getSource: function regexp_getSource(re) re.source.replace(/\\(.)/g, function (m0, m1) m1 === "/" ? "/" : m0)
}),
rehash: function () {
rehash: function (args) {
if (services.fuel)
services.fuel.storage.set("dactyl.commandlineArgs", args);
this.timeout(function () {
this.rehashing = true;
this.addon.userDisabled = true;
@@ -1443,6 +1445,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
*/
xmlToDom: function xmlToDom(node, doc, nodes) {
XML.prettyPrinting = false;
if (typeof node === "string") // Sandboxes can't currently pass us XML objects.
node = XML(node);
if (node.length() != 1) {
let domnode = doc.createDocumentFragment();
for each (let child in node)

View File

@@ -64,7 +64,7 @@
* :extadd now supports remote URLs as well as local files on Firefox 4.
* Added :if/:elseif/:else/:endif conditionals.
- Added -keyword, -tags, -title to :delbmarks.
- Added :extupdate command.
- Added :extrehash, :exttoggle, :extupdate, and :rehash commands.
- Added :feedkeys command.
- Added -sort option to :history.
- Added several new options, including -javascript, to :abbrev and :map.