mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-13 09:35:45 +01:00
add DownloadPost autocmd event
This commit is contained in:
2
NEWS
2
NEWS
@@ -33,7 +33,7 @@
|
|||||||
* add 'helpfile' option
|
* add 'helpfile' option
|
||||||
* add 'wildignore' option
|
* add 'wildignore' option
|
||||||
* add :finish command
|
* add :finish command
|
||||||
* new events BookmarkAdd, ShellCmdPost, VimperatorLeavePre
|
* new events BookmarkAdd, ShellCmdPost, VimperatorLeavePre, DownloadPost
|
||||||
* add 'cdpath' option
|
* add 'cdpath' option
|
||||||
* allow :dialog to open the cookies manager
|
* allow :dialog to open the cookies manager
|
||||||
* add 'loadplugins' option
|
* add 'loadplugins' option
|
||||||
|
|||||||
@@ -37,10 +37,12 @@ function IO() //{{{
|
|||||||
const WINDOWS = navigator.platform == "Win32";
|
const WINDOWS = navigator.platform == "Win32";
|
||||||
const EXTENSION_NAME = config.name.toLowerCase(); // "vimperator" or "muttator"
|
const EXTENSION_NAME = config.name.toLowerCase(); // "vimperator" or "muttator"
|
||||||
|
|
||||||
var environmentService = Components.classes["@mozilla.org/process/environment;1"]
|
const environmentService = Components.classes["@mozilla.org/process/environment;1"]
|
||||||
.getService(Components.interfaces.nsIEnvironment);
|
.getService(Components.interfaces.nsIEnvironment);
|
||||||
var directoryService = Components.classes["@mozilla.org/file/directory_service;1"]
|
const directoryService = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||||
.getService(Components.interfaces.nsIProperties);
|
.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 processDir = directoryService.get("CurWorkD", Components.interfaces.nsIFile);
|
||||||
var cwd = processDir.path;
|
var cwd = processDir.path;
|
||||||
@@ -67,10 +69,7 @@ function IO() //{{{
|
|||||||
shellcmdflag = "-c";
|
shellcmdflag = "-c";
|
||||||
}
|
}
|
||||||
|
|
||||||
function expandPathList(list)
|
function expandPathList(list) list.split(",").map(io.expandPath).join(",")
|
||||||
{
|
|
||||||
return list.split(",").map(io.expandPath).join(",");
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: why are we passing around so many strings? I know that the XPCOM
|
// TODO: why are we passing around so many strings? I know that the XPCOM
|
||||||
// file API is limited but...
|
// file API is limited but...
|
||||||
@@ -85,6 +84,28 @@ function IO() //{{{
|
|||||||
return head + pathSeparator + tail;
|
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 ////////////////////////////////////////////////
|
////////////////////// OPTIONS ////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ const config = { //{{{
|
|||||||
|
|
||||||
autocommands: [["BookmarkAdd", "Triggered after a page is bookmarked"],
|
autocommands: [["BookmarkAdd", "Triggered after a page is bookmarked"],
|
||||||
["DOMLoad", "Triggered when a page's DOM content has fully loaded"],
|
["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"],
|
["LocationChange", "Triggered when changing tabs or when naviagtion to a new location"],
|
||||||
["PageLoadPre", "Triggered after a page load is initiated"],
|
["PageLoadPre", "Triggered after a page load is initiated"],
|
||||||
["PageLoad", "Triggered when a page gets (re)loaded/opened"],
|
["PageLoad", "Triggered when a page gets (re)loaded/opened"],
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ Available {events}:
|
|||||||
`--------------------`----------------------------------------
|
`--------------------`----------------------------------------
|
||||||
*BookmarkAdd* Triggered after a page is bookmarked
|
*BookmarkAdd* Triggered after a page is bookmarked
|
||||||
*DOMLoad* Triggered when a page's DOM content has fully loaded
|
*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
|
*LocationChange* Triggered when changing tabs or when navigating to a new location
|
||||||
*PageLoadPre* Triggered after a page load is initiated.
|
*PageLoadPre* Triggered after a page load is initiated.
|
||||||
*PageLoad* Triggered when a page gets (re)loaded/opened
|
*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 following keywords are available where relevant:
|
||||||
|
|
||||||
`--------------------`----------------------------------------
|
`-----------`-------------------------------------------------
|
||||||
<url> The URL against which the event was selected.
|
*<url>* The URL against which the event was selected.
|
||||||
<title> The page or bookmark title.
|
*<title>* The page, bookmark or download title.
|
||||||
<tab> The index tab in which the event occurred.
|
*<tab>* The index tab in which the event occurred.
|
||||||
<tags> The tags applied to <url>. Only for *BookmarkAdd*.
|
*<tags>* The tags applied to <url>. Only for *BookmarkAdd*.
|
||||||
<keyword> The keywords applied to the bookmark. Only for *BookmarkAdd*.
|
*<keyword>* The keywords applied to the bookmark. Only for *BookmarkAdd*.
|
||||||
<icon> The icon associated with <url>. 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.
|
|
||||||
|
|
||||||
________________________________________________________________________________
|
________________________________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user