mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 14:57:59 +01:00
Fix temporary file filename extensions and host annotation.
Fixes issue #791.
This commit is contained in:
@@ -470,7 +470,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var tmpfile = io.createTempFile();
|
var tmpfile = io.createTempFile("txt", "." + buffer.uri.host);
|
||||||
if (!tmpfile)
|
if (!tmpfile)
|
||||||
throw Error(_("io.cantCreateTempFile"));
|
throw Error(_("io.cantCreateTempFile"));
|
||||||
|
|
||||||
|
|||||||
@@ -568,12 +568,6 @@ var ConfigBase = Class("ConfigBase", {
|
|||||||
|
|
||||||
sidebars: {},
|
sidebars: {},
|
||||||
|
|
||||||
/**
|
|
||||||
* @property {string} The leaf name of any temp files created by
|
|
||||||
* {@link io.createTempFile}.
|
|
||||||
*/
|
|
||||||
get tempFile() this.name + ".txt",
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @property {string} The default highlighting rules.
|
* @property {string} The default highlighting rules.
|
||||||
|
|||||||
@@ -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}
|
* @returns {File}
|
||||||
*/
|
*/
|
||||||
createTempFile: function createTempFile(name, type) {
|
createTempFile: function createTempFile(ext = "txt", label = "") {
|
||||||
if (name instanceof Ci.nsIFile) {
|
let file = services.directory.get("TmpD", Ci.nsIFile);
|
||||||
var file = name.clone();
|
file.append(config.name + label + "." + ext);
|
||||||
if (!type || type == "file")
|
|
||||||
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(666));
|
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
services.externalApp.deleteTemporaryFileOnExit(file);
|
services.externalApp.deleteTemporaryFileOnExit(file);
|
||||||
|
|
||||||
@@ -543,9 +540,9 @@ var IO = Module("io", {
|
|||||||
* @returns {boolean} false if temp files couldn't be created,
|
* @returns {boolean} false if temp files couldn't be created,
|
||||||
* otherwise, the return value of *func*.
|
* 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))
|
let args = array(util.range(0, func.length))
|
||||||
.map(bind("createTempFile", this, ext)).array;
|
.map(bind("createTempFile", this, ext, label)).array;
|
||||||
try {
|
try {
|
||||||
if (!args.every(util.identity))
|
if (!args.every(util.identity))
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -79,16 +79,6 @@ var Config = Module("config", ConfigBase, {
|
|||||||
else
|
else
|
||||||
dactyl.beep();
|
dactyl.beep();
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
get tempFile() {
|
|
||||||
let prefix = this.name;
|
|
||||||
try {
|
|
||||||
prefix += "-" + window.content.document.location.hostname;
|
|
||||||
}
|
|
||||||
catch (e) {}
|
|
||||||
|
|
||||||
return prefix + ".txt";
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -116,10 +116,7 @@ var Config = Module("config", ConfigBase, {
|
|||||||
modes.main = modes.MESSAGE;
|
modes.main = modes.MESSAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
// to allow Vim to :set ft=mail automatically
|
|
||||||
tempFile: "teledactyl.eml"
|
|
||||||
}, {
|
}, {
|
||||||
}, {
|
}, {
|
||||||
commands: function initCommands(dactyl, modules, window) {
|
commands: function initCommands(dactyl, modules, window) {
|
||||||
|
|||||||
Reference in New Issue
Block a user