diff --git a/NEWS b/NEWS index f3621909..ea5557ae 100644 --- a/NEWS +++ b/NEWS @@ -33,7 +33,7 @@ * add 'helpfile' option * add 'wildignore' option * add :finish command - * new events BookmarkAdd, ShellCmdPost, VimperatorLeavePre + * new events BookmarkAdd, ShellCmdPost, VimperatorLeavePre, DownloadPost * add 'cdpath' option * allow :dialog to open the cookies manager * add 'loadplugins' option diff --git a/content/io.js b/content/io.js index cff079e0..ba011a8a 100644 --- a/content/io.js +++ b/content/io.js @@ -37,10 +37,12 @@ function IO() //{{{ const WINDOWS = navigator.platform == "Win32"; const EXTENSION_NAME = config.name.toLowerCase(); // "vimperator" or "muttator" - var environmentService = Components.classes["@mozilla.org/process/environment;1"] - .getService(Components.interfaces.nsIEnvironment); - var directoryService = Components.classes["@mozilla.org/file/directory_service;1"] - .getService(Components.interfaces.nsIProperties); + const environmentService = Components.classes["@mozilla.org/process/environment;1"] + .getService(Components.interfaces.nsIEnvironment); + const directoryService = Components.classes["@mozilla.org/file/directory_service;1"] + .getService(Components.interfaces.nsIProperties); + const downloadManager = Components.classes["@mozilla.org/download-manager;1"] + .createInstance(Components.interfaces.nsIDownloadManager); var processDir = directoryService.get("CurWorkD", Components.interfaces.nsIFile); var cwd = processDir.path; @@ -67,10 +69,7 @@ function IO() //{{{ shellcmdflag = "-c"; } - function expandPathList(list) - { - return list.split(",").map(io.expandPath).join(","); - } + function expandPathList(list) list.split(",").map(io.expandPath).join(",") // TODO: why are we passing around so many strings? I know that the XPCOM // file API is limited but... @@ -85,6 +84,28 @@ function IO() //{{{ return head + pathSeparator + tail; } + var downloadListener = { + onDownloadStateChange: function (state, download) + { + if (download.state == downloadManager.DOWNLOAD_FINISHED) + { + autocommands.trigger("DownloadPost", + { + url: download.source.spec, + file: download.targetFile.path, + title: download.displayName, + size: download.size + } + ); + } + } + }; + + downloadManager.addListener(downloadListener); + liberator.registerObserver("shutdown", function () { + downloadManager.removeListener(downloadListener); + }); + /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// OPTIONS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ diff --git a/content/vimperator.js b/content/vimperator.js index e9564f73..295b7e18 100644 --- a/content/vimperator.js +++ b/content/vimperator.js @@ -40,6 +40,7 @@ const config = { //{{{ autocommands: [["BookmarkAdd", "Triggered after a page is bookmarked"], ["DOMLoad", "Triggered when a page's DOM content has fully loaded"], + ["DownloadPost", "Triggered when a download has completed"], ["LocationChange", "Triggered when changing tabs or when naviagtion to a new location"], ["PageLoadPre", "Triggered after a page load is initiated"], ["PageLoad", "Triggered when a page gets (re)loaded/opened"], diff --git a/locale/en-US/autocommands.txt b/locale/en-US/autocommands.txt index f160728d..022536dd 100644 --- a/locale/en-US/autocommands.txt +++ b/locale/en-US/autocommands.txt @@ -22,6 +22,7 @@ Available {events}: `--------------------`---------------------------------------- *BookmarkAdd* Triggered after a page is bookmarked *DOMLoad* Triggered when a page's DOM content has fully loaded +*DownloadPost* Triggered when a download has completed *LocationChange* Triggered when changing tabs or when navigating to a new location *PageLoadPre* Triggered after a page load is initiated. *PageLoad* Triggered when a page gets (re)loaded/opened @@ -36,18 +37,17 @@ differs from Vim which uses a glob rather than a regexp for {pat}. The following keywords are available where relevant: -`--------------------`---------------------------------------- - The URL against which the event was selected. - The page or bookmark title. -<tab> The index tab in which the event occurred. -<tags> The tags applied to <url>. Only for *BookmarkAdd*. -<keyword> The keywords applied to the bookmark. Only for *BookmarkAdd*. -<icon> The icon associated with <url>. Only for *BookmarkAdd*. +`-----------`------------------------------------------------- +*<url>* The URL against which the event was selected. +*<title>* The page, bookmark or download title. +*<tab>* The index tab in which the event occurred. +*<tags>* The tags applied to <url>. Only for *BookmarkAdd*. +*<keyword>* The keywords applied to the bookmark. Only for *BookmarkAdd*. +*<icon>* The icon associated with <url>. Only for *BookmarkAdd*. +*<size>* The size of a downloaded file. +*<file>* The target destination of a download. -------------------------------------------------------------- -Warning: Autocommand events are, in general, currently only fired when -Vimperator commands are executed. - ________________________________________________________________________________