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

better argument processing for :source, :mkvimperatorc, and :saveas

This commit is contained in:
Doug Kearns
2008-10-19 14:13:31 +00:00
parent 337f956323
commit 86460fd8c5
3 changed files with 42 additions and 34 deletions

View File

@@ -797,18 +797,33 @@ function Buffer() //{{{
argCount: "0"
});
// TODO: we're prompted if download.useDownloadDir isn't set and no arg specified - intentional?
commands.add(["sav[eas]", "w[rite]"],
"Save current document to disk",
function (args, special)
{
args = args.string;
let doc = window.content.document;
let file = io.getFile(args || "");
if (args && file.exists() && !special)
return liberator.echoerr("E13: File exists (add ! to override)");
let chosenData = null;
let filename = args.arguments[0];
if (filename)
{
let file = io.getFile(filename);
if (file.exists() && !special)
{
liberator.echoerr("E13: File exists (add ! to override)");
return;
}
chosenData = { file: file, uri: makeURI(doc.location.href, doc.characterSet) };
}
// if browser.download.useDownloadDir = false then the "Save As"
// dialog is used with this as the default directory
// TODO: if we're going to do this shouldn't it be done in setCWD or the value restored?
options.setPref("browser.download.lastDir", io.getCurrentDirectory());
try
{
var contentDisposition = window.content
@@ -818,12 +833,11 @@ function Buffer() //{{{
} catch (e) {}
internalSave(doc.location.href, doc, null, contentDisposition,
doc.contentType, false, null,
args && { file: file, uri: makeURI(doc.location.href, doc.characterSet) },
doc.referrer ? makeURI(doc.referrer) : null,
true);
doc.contentType, false, null, chosenData, doc.referrer ?
makeURI(doc.referrer) : null, true);
},
{
argCount: "?",
bang: true,
completer: function (filter) completion.file(filter)
});