1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-04-12 08:53:32 +02:00

Allow IDs instead of names in :ext* commands.

This commit is contained in:
Kris Maglione
2011-10-01 02:51:18 -04:00
parent 2f776eebe7
commit 435cadb1a0
2 changed files with 14 additions and 10 deletions

View File

@@ -424,11 +424,10 @@ var Addons = Module("addons", {
AddonManager.getAddonsByTypes(args["-types"], dactyl.wrapCallback(function (list) { AddonManager.getAddonsByTypes(args["-types"], dactyl.wrapCallback(function (list) {
if (!args.bang || command.bang) { if (!args.bang || command.bang) {
list = list.filter(function (extension) extension.name == name); list = list.filter(function (addon) addon.id == name || addon.name == name);
if (list.length == 0) dactyl.assert(list.length, _("error.invalidArgument", name));
return void dactyl.echoerr(_("error.invalidArgument", name)); dactyl.assert(list.some(ok), _("error.invalidOperation"));
if (!list.every(ok)) list = list.filter(ok);
return void dactyl.echoerr(_("error.invalidOperation"));
} }
if (command.actions) if (command.actions)
command.actions(list, this.modules); command.actions(list, this.modules);
@@ -439,7 +438,7 @@ var Addons = Module("addons", {
argCount: "?", // FIXME: should be "1" argCount: "?", // FIXME: should be "1"
bang: true, bang: true,
completer: function (context, args) { completer: function (context, args) {
completion.extension(context, args["-types"]); completion.addon(context, args["-types"]);
context.filters.push(function ({ item }) ok(item)); context.filters.push(function ({ item }) ok(item));
if (command.filter) if (command.filter)
context.filters.push(command.filter); context.filters.push(command.filter);
@@ -477,10 +476,14 @@ var Addons = Module("addons", {
}; };
}; };
completion.extension = function extension(context, types) { completion.addon = function addon(context, types) {
context.title = ["Extension"]; context.title = ["Add-on"];
context.anchored = false; context.anchored = false;
context.keys = { text: "name", description: "description", icon: "iconURL" }, context.keys = {
text: function (addon) [addon.name, addon.id],
description: "description",
icon: "iconURL"
};
context.generate = function () { context.generate = function () {
context.incomplete = true; context.incomplete = true;
AddonManager.getAddonsByTypes(types || ["extension"], function (addons) { AddonManager.getAddonsByTypes(types || ["extension"], function (addons) {

View File

@@ -842,9 +842,10 @@ var CompletionContext = Class("CompletionContext", {
Filter: { Filter: {
text: function (item) { text: function (item) {
let text = Array.concat(item.text); let text = item.texts || Array.concat(item.text);
for (let [i, str] in Iterator(text)) { for (let [i, str] in Iterator(text)) {
if (this.match(String(str))) { if (this.match(String(str))) {
item.texts = text;
item.text = String(text[i]); item.text = String(text[i]);
return true; return true;
} }