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

Add Clear button to :downloads.

--HG--
branch : key-processing
This commit is contained in:
Kris Maglione
2011-01-24 00:37:32 -05:00
parent beb9d69eaa
commit 0a422502ba
4 changed files with 84 additions and 31 deletions

View File

@@ -893,20 +893,21 @@ var CommandLine = Module("commandline", {
*/ */
input: function _input(prompt, callback, extra) { input: function _input(prompt, callback, extra) {
extra = extra || {}; extra = extra || {};
let closure = extra.closure || extra;
this._input = { this._input = {
submit: callback || extra.onAccept, submit: callback || closure.onAccept,
change: extra.onChange, change: closure.onChange,
complete: extra.completer, complete: closure.completer,
cancel: extra.onCancel cancel: closure.onCancel
}; };
modes.push(modes.COMMAND_LINE, modes.PROMPT | extra.extended, modes.push(modes.COMMAND_LINE, modes.PROMPT | extra.extended,
update(Object.create(extra), { update(Object.create(extra), {
onEvent: extra.onEvent || this.closure.onEvent, onEvent: closure.onEvent || this.closure.onEvent,
leave: function leave(stack) { leave: function leave(stack) {
commandline.leave(stack); commandline.leave(stack);
leave.supercall(this, stack); leave.supercall(extra, stack);
}, },
keyModes: [extra.extended, modes.PROMPT] keyModes: [extra.extended, modes.PROMPT]
})); }));

View File

@@ -499,23 +499,25 @@ var ConfigBase = Class("ConfigBase", {
Button::after content: "]"; color: gray; text-decoration: none !important; Button::after content: "]"; color: gray; text-decoration: none !important;
Button:not([collapsed]) ~ Button:not([collapsed])::before content: "/["; Button:not([collapsed]) ~ Button:not([collapsed])::before content: "/[";
DownloadCell display: table-cell; padding: 0 1ex;
Downloads display: table; margin: 0; padding: 0; Downloads display: table; margin: 0; padding: 0;
DownloadHead;;;CompTitle display: table-row; DownloadHead;;;CompTitle display: table-row;
DownloadHead>*;;;DownloadCell display: table-cell; DownloadHead>*;;;DownloadCell
Download display: table-row; Download display: table-row;
Download:not([active]) color: gray; Download:not([active]) color: gray;
DownloadCell display: table-cell; padding: 0 1ex; Download>*;;;DownloadCell
DownloadButtons;;;DownloadCell DownloadButtons
DownloadPercent;;;DownloadCell DownloadPercent
DownloadProgress;;;DownloadCell DownloadProgress
DownloadProgressHave DownloadProgressHave
DownloadProgressTotal DownloadProgressTotal
DownloadSource;;;DownloadCell,URL DownloadSource
DownloadState;;;DownloadCell DownloadState
DownloadTime;;;DownloadCell DownloadTime
DownloadTitle;;;DownloadCell,URL DownloadTitle
// </css> // </css>
]]></>, /&#x0d;/g, "\n")), ]]></>, /&#x0d;/g, "\n")),

View File

@@ -66,7 +66,7 @@ var Download = Class("Download", {
get alive() this.inState(["downloading", "notstarted", "paused", "queued", "scanning"]), get alive() this.inState(["downloading", "notstarted", "paused", "queued", "scanning"]),
allowed: Class.memoize(function () let (self = this) ({ allowedCommands: Class.memoize(function () let (self = this) ({
get cancel() self.cancelable && self.inState(["downloading", "paused", "starting"]), get cancel() self.cancelable && self.inState(["downloading", "paused", "starting"]),
get delete() !this.cancel && self.targetFile.exists(), get delete() !this.cancel && self.targetFile.exists(),
get launch() self.targetFile.exists() && self.inState(["finished"]), get launch() self.targetFile.exists() && self.inState(["finished"]),
@@ -78,13 +78,10 @@ var Download = Class("Download", {
})), })),
command: function command(name) { command: function command(name) {
util.assert(set.has(this.allowed, name), "Unknown command"); util.assert(set.has(this.allowedCommands, name), "Unknown command");
util.assert(this.allowed[name], "Command not allowed"); util.assert(this.allowedCommands[name], "Command not allowed");
if (set.has(this.commands, name)) services.downloadManager[name + "Download"](this.id);
this.commands[name].call(this);
else
services.downloadManager[name + "Download"](this.id);
}, },
commands: { commands: {
@@ -154,8 +151,11 @@ var Download = Class("Download", {
this.nodes.row.setAttribute("status", this.status); this.nodes.row.setAttribute("status", this.status);
this.nodes.state.textContent = util.capitalize(this.status); this.nodes.state.textContent = util.capitalize(this.status);
for (let [command, enabled] in Iterator(this.allowed))
this.nodes[command].collapsed = !enabled; for (let node in values(this.nodes))
if (node.update)
node.update();
this.updateProgress(); this.updateProgress();
} }
}); });
@@ -166,7 +166,9 @@ var DownloadList = Class("DownloadList",
Ci.nsISupportsWeakReference]), { Ci.nsISupportsWeakReference]), {
init: function init(modules) { init: function init(modules) {
this.modules = modules; this.modules = modules;
this.nodes = {}; this.nodes = {
commandTarget: this
};
this.downloads = {}; this.downloads = {};
}, },
cleanup: function cleanup() { cleanup: function cleanup() {
@@ -180,17 +182,30 @@ var DownloadList = Class("DownloadList",
<li highlight="DownloadHead"> <li highlight="DownloadHead">
<span>Title</span> <span>Title</span>
<span>Status</span> <span>Status</span>
<span></span> <span/>
<span>Progress</span> <span>Progress</span>
<span></span> <span/>
<span>Time remaining</span> <span>Time remaining</span>
<span>Source</span> <span>Source</span>
</li> </li>
<li highlight="Download"><span><div style="min-height: 1ex; /* FIXME */"/></span></li>
<li highlight="Download" key="totals">
<span highlight="Title">Totals:</span>
<span/>
<span highlight="DownloadButtons">
<a highlight="Button" key="clear">Clear</a>
</span>
<span/>
<span/>
<span/>
<span/>
</li>
</ul>, this.document, this.nodes); </ul>, this.document, this.nodes);
for (let row in iter(services.downloadManager.DBConnection for (let row in iter(services.downloadManager.DBConnection
.createStatement("SELECT id FROM moz_downloads"))) .createStatement("SELECT id FROM moz_downloads")))
this.addDownload(row.id); this.addDownload(row.id);
this.update();
util.addObserver(this); util.addObserver(this);
services.downloadManager.addListener(this); services.downloadManager.addListener(this);
@@ -220,14 +235,31 @@ var DownloadList = Class("DownloadList",
this.cleanup(); this.cleanup();
}, },
allowedCommands: Class.memoize(function () let (self = this) ({
get clear() values(self.downloads).some(function (dl) dl.allowedCommands.remove)
})),
commands: {
clear: function () {
services.downloadManager.cleanUp();
}
},
update: function update() {
for (let node in values(this.nodes))
if (node.update && node.update != update)
node.update();
},
observers: { observers: {
"download-manager-remove-download": function (id) { "download-manager-remove-download": function (id) {
if (id == null) if (id == null)
id = [k for ([k, dl] in iter(this.downloads)) if (dl.allowed.remove)]; id = [k for ([k, dl] in iter(this.downloads)) if (dl.allowedCommands.remove)];
else else
id = [id.QueryInterface(Ci.nsISupportsPRUint32).data]; id = [id.QueryInterface(Ci.nsISupportsPRUint32).data];
Array.concat(id).map(this.closure.removeDownload); Array.concat(id).map(this.closure.removeDownload);
this.update();
} }
}, },
@@ -241,6 +273,7 @@ var DownloadList = Class("DownloadList",
this.modules.commandline.updateOutputHeight(false); this.modules.commandline.updateOutputHeight(false);
this.nodes.list.scrollIntoView(false); this.nodes.list.scrollIntoView(false);
} }
this.update();
} }
catch (e) { catch (e) {
util.reportError(e); util.reportError(e);

View File

@@ -104,15 +104,32 @@ var Template = Module("Template", {
init.supercall(this, node); init.supercall(this, node);
this.target = params.commandTarget; this.target = params.commandTarget;
if (callable(this.target))
this.target = { command: this.target }
}, },
get command() this.getAttribute("command") || this.getAttribute("key"),
events: { events: {
"click": function onClick(event) { "click": function onClick(event) {
event.preventDefault(); event.preventDefault();
this.target.command(this.getAttribute("key")); if (this.commandAllowed) {
if (set.has(this.target.commands || {}, this.command))
this.target.commands[this.command].call(this.target);
else
this.target.command(this.command);
}
} }
},
get commandAllowed() {
if (set.has(this.target.allowedCommands || {}, this.command))
return this.target.allowedCommands[this.command];
if ("commandAllowed" in this.target)
return this.target.commandAllowed(this.command);
return true;
},
update: function update() {
this.collapsed = !this.commandAllowed;
} }
}) })
}, },