1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 19:07:58 +01:00

Add filtering to :addons and :downloads. Add -type flag to :addons.

--HG--
extra : transplant_source : %06i65%11-C%E7b%12%C0%8E%8C%8Ed%C9%ED8I%13
This commit is contained in:
Kris Maglione
2011-01-24 05:05:57 -05:00
parent fb4aafc21e
commit 74b6710484
6 changed files with 70 additions and 14 deletions

View File

@@ -916,7 +916,7 @@ var Commands = Module("commands", {
} }
} }
if (arg != null || opt.type == CommandOption.NOARG) if (arg != null || opt.type == CommandOption.NOARG) {
// option allowed multiple times // option allowed multiple times
if (opt.multiple) if (opt.multiple)
args[opt.names[0]] = (args[opt.names[0]] || []).concat(arg); args[opt.names[0]] = (args[opt.names[0]] || []).concat(arg);
@@ -924,6 +924,7 @@ var Commands = Module("commands", {
Class.replaceProperty(args, opt.names[0], opt.type == CommandOption.NOARG || arg); Class.replaceProperty(args, opt.names[0], opt.type == CommandOption.NOARG || arg);
args.explicitOpts[opt.names[0]] = args[opt.names[0]]; args.explicitOpts[opt.names[0]] = args[opt.names[0]];
}
i += optname.length + count; i += optname.length + count;
if (i == str.length) if (i == str.length)
@@ -989,14 +990,17 @@ var Commands = Module("commands", {
if (args.completeOpt) { if (args.completeOpt) {
let opt = args.completeOpt; let opt = args.completeOpt;
let context = complete.fork(opt.names[0], args.completeStart); let context = complete.fork(opt.names[0], args.completeStart);
let arg = args[opt.names[0]]; let arg = args.explicitOpts[opt.names[0]];
context.filter = args.completeFilter; context.filter = args.completeFilter;
if (isArray(arg)) if (isArray(arg))
context.filters.push(function (item) arg.indexOf(item.text) === -1); context.filters.push(function (item) arg.indexOf(item.text) === -1);
if (typeof opt.completer == "function") if (typeof opt.completer == "function")
var compl = opt.completer(context, args); var compl = opt.completer(context, args);
else else
compl = opt.completer || []; compl = opt.completer || [];
context.title = [opt.names[0]]; context.title = [opt.names[0]];
context.quote = args.quote; context.quote = args.quote;
if (compl) if (compl)

View File

@@ -10,7 +10,7 @@ Components.utils.import("resource://dactyl/bootstrap.jsm");
defineModule("addons", { defineModule("addons", {
exports: ["AddonManager", "Addons", "Addon", "addons"], exports: ["AddonManager", "Addons", "Addon", "addons"],
require: ["services"], require: ["services"],
use: ["config", "io", "prefs", "template", "util"] use: ["completion", "config", "io", "prefs", "template", "util"]
}, this); }, this);
var callResult = function callResult(method) { var callResult = function callResult(method) {
@@ -235,8 +235,9 @@ var Addon = Class("Addon", {
}); });
var AddonList = Class("AddonList", { var AddonList = Class("AddonList", {
init: function init(modules, types) { init: function init(modules, types, filter) {
this.modules = modules; this.modules = modules;
this.filter = filter && filter.toLowerCase();
this.nodes = {}; this.nodes = {};
this.addons = []; this.addons = [];
this.ready = false; this.ready = false;
@@ -271,6 +272,9 @@ var AddonList = Class("AddonList", {
if (addon.id in this.addons) if (addon.id in this.addons)
this.update(addon); this.update(addon);
else { else {
if (this.filter && addon.name.toLowerCase().indexOf(this.filter) === -1)
return;
addon = Addon(addon, this); addon = Addon(addon, this);
this.addons[addon.id] = addon; this.addons[addon.id] = addon;
@@ -318,7 +322,7 @@ var Addons = Module("addons", {
}, { }, {
}, { }, {
commands: function (dactyl, modules, window) { commands: function (dactyl, modules, window) {
const { commands, completion } = modules; const { CommandOption, commands, completion } = modules;
let addonListener = AddonListener(modules); let addonListener = AddonListener(modules);
@@ -414,12 +418,44 @@ var Addons = Module("addons", {
commands.add(["addo[ns]", "ao"], commands.add(["addo[ns]", "ao"],
"List installed extensions", "List installed extensions",
function (args) { function (args) {
let addons = AddonList(modules, ["extension"]); let addons = AddonList(modules, args["-types"], args[0]);
modules.commandline.echo(addons); modules.commandline.echo(addons);
if (modules.commandline.savingOutput) if (modules.commandline.savingOutput)
util.waitFor(function () addons.ready); util.waitFor(function () addons.ready);
},
{
argCount: "?",
options: [
{
names: ["-types", "-type", "-t"],
description: "The add-on types to list",
default: ["extension"],
completer: function (context, args) completion.addonType(context),
type: CommandOption.LIST
}
]
}); });
},
completion: function (dactyl, modules, window) {
completion.addonType = function addonType(context) {
let base = ["extension", "theme"];
function update(types) {
context.completions = types.map(function (t) [t, util.capitalize(t)]);
}
context.generate = function generate() {
update(base);
if (AddonManager.getAllAddons) {
context.incomplete = true;
AddonManager.getAllAddons(function (addons) {
context.incomplete = false;
update(array.uniq(base.concat(addons.map(function (a) a.type)),
true));
});
}
}
}
} }
}); });

View File

@@ -297,11 +297,11 @@ function deprecated(alternative, fn) {
* @param {object} obj The object to inspect. * @param {object} obj The object to inspect.
* @returns {Generator} * @returns {Generator}
*/ */
function keys(obj) { function keys(obj) iter(function keys() {
for (var k in obj) for (var k in obj)
if (hasOwnProperty.call(obj, k)) if (hasOwnProperty.call(obj, k))
yield k; yield k;
} }());
/** /**
* Iterates over all of the top-level, iterable property values of an * Iterates over all of the top-level, iterable property values of an
* object. * object.

View File

@@ -481,6 +481,13 @@ var CompletionContext = Class("CompletionContext", {
let filtered = this.filterFunc(this._cache.constructed); let filtered = this.filterFunc(this._cache.constructed);
if (this.maxItems) if (this.maxItems)
filtered = filtered.slice(0, this.maxItems); filtered = filtered.slice(0, this.maxItems);
if (/types/.test(this.name)) {
let self = this;
util.dump(this.filters[1]);
util.dump("FILTERED", this._cache.constructed.map(function (item) [item.text.quote(), self.filters[0].call(self, item.text)]));
util.dump("FILTERED", this._cache.constructed.map(function (item)
self.filters.map(function (filter) filter.call(self, item))));
}
// Sorting // Sorting
if (this.sortResults && this.compare) if (this.sortResults && this.compare)

View File

@@ -424,6 +424,7 @@ var ConfigBase = Class("ConfigBase", {
Link position: relative; padding-right: 2em; Link position: relative; padding-right: 2em;
Link:not(:hover)>LinkInfo opacity: 0; left: 0; width: 1px; height: 1px; overflow: hidden; Link:not(:hover)>LinkInfo opacity: 0; left: 0; width: 1px; height: 1px; overflow: hidden;
LinkInfo { LinkInfo {
color: black;
position: absolute; position: absolute;
left: 100%; left: 100%;
padding: 1ex; padding: 1ex;
@@ -518,6 +519,7 @@ var ConfigBase = Class("ConfigBase", {
DownloadState;;;DownloadCell DownloadState;;;DownloadCell
DownloadTime;;;DownloadCell DownloadTime;;;DownloadCell
DownloadTitle;;;DownloadCell,URL DownloadTitle;;;DownloadCell,URL
DownloadTitle>Link>a max-width: 48ex; overflow: hidden; display: inline-block;
AddonCell display: table-cell; padding: 0 1ex; AddonCell display: table-cell; padding: 0 1ex;
@@ -530,7 +532,7 @@ var ConfigBase = Class("ConfigBase", {
Addon>*;;;AddonCell Addon>*;;;AddonCell
AddonButtons AddonButtons
AddonDescription AddonDescription
AddonName AddonName max-width: 48ex; overflow: hidden;
AddonStatus AddonStatus
AddonVersion AddonVersion

View File

@@ -178,9 +178,10 @@ var DownloadList = Class("DownloadList",
XPCOM([Ci.nsIDownloadProgressListener, XPCOM([Ci.nsIDownloadProgressListener,
Ci.nsIObserver, Ci.nsIObserver,
Ci.nsISupportsWeakReference]), { Ci.nsISupportsWeakReference]), {
init: function init(modules) { init: function init(modules, filter) {
this.modules = modules; this.modules = modules;
this.nodes = {}; this.nodes = {};
this.filter = filter && filter.toLowerCase();
this.downloads = {}; this.downloads = {};
}, },
cleanup: function cleanup() { cleanup: function cleanup() {
@@ -213,12 +214,15 @@ var DownloadList = Class("DownloadList",
addDownload: function addDownload(id) { addDownload: function addDownload(id) {
if (!(id in this.downloads)) { if (!(id in this.downloads)) {
this.downloads[id] = Download(id, this); let download = Download(id, this);
if (this.filter && download.displayName.indexOf(this.filter) === -1)
return;
this.downloads[id] = download;
let index = values(this.downloads).sort(function (a, b) a.compare(b)) let index = values(this.downloads).sort(function (a, b) a.compare(b))
.indexOf(this.downloads[id]); .indexOf(download);
this.nodes.list.insertBefore(this.downloads[id].nodes.row, this.nodes.list.insertBefore(download.nodes.row,
this.nodes.list.childNodes[index + 1]); this.nodes.list.childNodes[index + 1]);
} }
}, },
@@ -283,8 +287,11 @@ var Downloads = Module("downloads", {
commands.add(["downl[oads]", "dl"], commands.add(["downl[oads]", "dl"],
"Display the downloads list", "Display the downloads list",
function (args) { function (args) {
let downloads = DownloadList(modules); let downloads = DownloadList(modules, args[0]);
modules.commandline.echo(downloads); modules.commandline.echo(downloads);
},
{
argCount: "?"
}); });
}, },
dactyl: function (dactyl, modules, window) { dactyl: function (dactyl, modules, window) {