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

Refactor download listeners a bit.

This commit is contained in:
Kris Maglione
2012-03-02 18:23:54 -05:00
parent bf8c86c7f4
commit 5c3330c7b4
3 changed files with 27 additions and 27 deletions

View File

@@ -757,8 +757,7 @@ var CommandLine = Module("commandline", {
} }
if ((flags & this.ACTIVE_WINDOW) && if ((flags & this.ACTIVE_WINDOW) &&
window != services.windowWatcher.activeWindow && window != overlay.activeWindow)
services.windowWatcher.activeWindow.dactyl)
return; return;
if ((flags & this.DISALLOW_MULTILINE) && !this.widgets.mowContainer.collapsed) if ((flags & this.DISALLOW_MULTILINE) && !this.widgets.mowContainer.collapsed)

View File

@@ -9,6 +9,8 @@ defineModule("downloads", {
exports: ["Download", "Downloads", "downloads"] exports: ["Download", "Downloads", "downloads"]
}, this); }, this);
this.lazyRequire("overlay", ["overlay"]);
Cu.import("resource://gre/modules/DownloadUtils.jsm", this); Cu.import("resource://gre/modules/DownloadUtils.jsm", this);
let prefix = "DOWNLOAD_"; let prefix = "DOWNLOAD_";
@@ -388,7 +390,30 @@ var DownloadList = Class("DownloadList",
} }
}); });
var Downloads = Module("downloads", { var Downloads = Module("downloads", XPCOM(Ci.nsIDownloadProgressListener), {
init: function () {
services.downloadManager.addListener(this);
},
destroy: function destroy() {
services.downloadManager.removeListener(this);
},
onDownloadStateChange: function (state, download) {
if (download.state == services.downloadManager.DOWNLOAD_FINISHED) {
let url = download.source.spec;
let title = download.displayName;
let file = download.targetFile.path;
let size = download.size;
overlay.modules.forEach(function (modules) {
modules.dactyl.echomsg({ domains: [util.getHost(url)], message: _("io.downloadFinished", title, file) },
1, modules.commandline.ACTIVE_WINDOW);
modules.autocommands.trigger("DownloadPost", { url: url, title: title, file: file, size: size });
});
}
}
}, { }, {
}, { }, {
commands: function initCommands(dactyl, modules, window) { commands: function initCommands(dactyl, modules, window) {

View File

@@ -41,26 +41,6 @@ var IO = Module("io", {
this._lastRunCommand = ""; // updated whenever the users runs a command with :! this._lastRunCommand = ""; // updated whenever the users runs a command with :!
this._scriptNames = []; this._scriptNames = [];
this.downloadListener = {
onDownloadStateChange: function (state, download) {
if (download.state == services.downloadManager.DOWNLOAD_FINISHED) {
let url = download.source.spec;
let title = download.displayName;
let file = download.targetFile.path;
let size = download.size;
dactyl.echomsg({ domains: [util.getHost(url)], message: _("io.downloadFinished", title, file) },
1, modules.commandline.ACTIVE_WINDOW);
modules.autocommands.trigger("DownloadPost", { url: url, title: title, file: file, size: size });
}
},
onStateChange: function () {},
onProgressChange: function () {},
onSecurityChange: function () {}
};
services.downloadManager.addListener(this.downloadListener);
}, },
CommandFileMode: Class("CommandFileMode", modules.CommandMode, { CommandFileMode: Class("CommandFileMode", modules.CommandMode, {
@@ -84,10 +64,6 @@ var IO = Module("io", {
} }
}), }),
destroy: function destroy() {
services.downloadManager.removeListener(this.downloadListener);
},
/** /**
* Returns all directories named *name* in 'runtimepath'. * Returns all directories named *name* in 'runtimepath'.
* *