1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 13:07:59 +01:00

Fix temporary file filename extensions and host annotation.

Fixes issue #791.
This commit is contained in:
Doug Kearns
2013-09-05 20:55:01 +10:00
parent 4055392b49
commit 98af2b9ab0
5 changed files with 15 additions and 37 deletions

View File

@@ -470,7 +470,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
}
try {
var tmpfile = io.createTempFile();
var tmpfile = io.createTempFile("txt", "." + buffer.uri.host);
if (!tmpfile)
throw Error(_("io.cantCreateTempFile"));

View File

@@ -568,12 +568,6 @@ var ConfigBase = Class("ConfigBase", {
sidebars: {},
/**
* @property {string} The leaf name of any temp files created by
* {@link io.createTempFile}.
*/
get tempFile() this.name + ".txt",
/**
* @constant
* @property {string} The default highlighting rules.

View File

@@ -307,23 +307,20 @@ var IO = Module("io", {
},
/**
* Creates a temporary file.
* Returns a temporary file.
*
* @param {string} ext The filename extension.
* @default "txt"
* @param {string} label A metadata string appended to the filename. Useful
* for identifying the file, beyond its extension, to external
* applications.
* @default ""
* @returns {File}
*/
createTempFile: function createTempFile(name, type) {
if (name instanceof Ci.nsIFile) {
var file = name.clone();
if (!type || type == "file")
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(666));
else
file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, octal(777));
}
else {
file = services.directory.get("TmpD", Ci.nsIFile);
file.append(this.config.tempFile + (name ? "." + name : ""));
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(666));
}
createTempFile: function createTempFile(ext = "txt", label = "") {
let file = services.directory.get("TmpD", Ci.nsIFile);
file.append(config.name + label + "." + ext);
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(666));
services.externalApp.deleteTemporaryFileOnExit(file);
@@ -543,9 +540,9 @@ var IO = Module("io", {
* @returns {boolean} false if temp files couldn't be created,
* otherwise, the return value of *func*.
*/
withTempFiles: function withTempFiles(func, self, checked, ext) {
withTempFiles: function withTempFiles(func, self, checked, ext, label) {
let args = array(util.range(0, func.length))
.map(bind("createTempFile", this, ext)).array;
.map(bind("createTempFile", this, ext, label)).array;
try {
if (!args.every(util.identity))
return false;

View File

@@ -79,16 +79,6 @@ var Config = Module("config", ConfigBase, {
else
dactyl.beep();
}
},
get tempFile() {
let prefix = this.name;
try {
prefix += "-" + window.content.document.location.hostname;
}
catch (e) {}
return prefix + ".txt";
}
})

View File

@@ -116,10 +116,7 @@ var Config = Module("config", ConfigBase, {
modes.main = modes.MESSAGE;
}
}
},
// to allow Vim to :set ft=mail automatically
tempFile: "teledactyl.eml"
}
}, {
}, {
commands: function initCommands(dactyl, modules, window) {