1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-07 11:25:46 +01:00

add DownloadPost autocmd event

This commit is contained in:
Doug Kearns
2008-10-15 01:52:59 +00:00
parent 50a5eeea56
commit 7770adb4af
4 changed files with 41 additions and 19 deletions

2
NEWS
View File

@@ -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

View File

@@ -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 ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{

View File

@@ -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"],

View File

@@ -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:
`--------------------`----------------------------------------
<url> The URL against which the event was selected.
<title> 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.
________________________________________________________________________________