1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-11 12:35:47 +01:00

Allow exporting to a directory as well as an archive with dactyl.exportHelp.

This commit is contained in:
Kris Maglione
2010-12-02 19:18:32 -05:00
parent c8f18d8d62
commit becbd989e9
6 changed files with 45 additions and 32 deletions

View File

@@ -60,6 +60,7 @@
"prefs",
"storage",
"util",
"javascript",
"dactyl",
"modes",
"abbreviations",
@@ -76,7 +77,6 @@
"highlight",
"hints",
"io",
"javascript",
"mappings",
"marks",
"options",

View File

@@ -538,19 +538,29 @@ const Dactyl = Module("dactyl", {
return UTF8(xml.toXMLString());
},
exportHelp: function (path) {
exportHelp: JavaScript.setCompleter(function (path) {
const FILE = io.File(path);
const PATH = FILE.leafName.replace(/\..*/, "") + "/";
const TIME = Date.now();
if (!FILE.exists() && (/\/$/.test(path) && !/\./.test(FILE.leafName)))
FILE.create(FILE.DIRECTORY_TYPE, octal(755));
dactyl.initHelp();
let zip = services.ZipWriter();
zip.open(FILE, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
function addURIEntry(file, uri)
zip.addEntryChannel(PATH + file, TIME, 9,
services.io.newChannel(uri, null, null), false);
function addDataEntry(file, data) // Unideal to an extreme.
addURIEntry(file, "data:text/plain;charset=UTF-8," + encodeURI(data));
if (FILE.isDirectory()) {
function addDataEntry(file, data) FILE.child(file).write(data);
function addURIEntry(file, uri) addDataEntry(file, util.httpGet(uri).responseText);
}
else {
var zip = services.ZipWriter();
zip.open(FILE, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
function addURIEntry(file, uri)
zip.addEntryChannel(PATH + file, TIME, 9,
services.io.newChannel(uri, null, null), false);
function addDataEntry(file, data) // Unideal to an extreme.
addURIEntry(file, "data:text/plain;charset=UTF-8," + encodeURI(data));
}
let empty = set("area base basefont br col frame hr img input isindex link meta param"
.split(" "));
@@ -619,9 +629,9 @@ const Dactyl = Module("dactyl", {
}
let data = [h for (h in highlight) if (set.has(styles, h.class) || /^Help/.test(h.class))]
.map(function (h)
h.selector.replace(/^\[.*?=(.*?)\]/, ".hl-$1").replace(/html\|/, "") + "\t" +
"{" + h.value + "}")
.map(function (h) h.selector
.replace(/^\[.*?=(.*?)\]/, ".hl-$1")
.replace(/html\|/, "") + "\t" + "{" + h.value + "}")
.join("\n");
addDataEntry("help.css", data.replace(/chrome:[^ ")]+\//g, ""));
@@ -632,8 +642,9 @@ const Dactyl = Module("dactyl", {
for (let [uri, leaf] in Iterator(chrome))
addURIEntry(leaf, uri);
zip.close();
},
if (zip)
zip.close();
}, [function (context, args) completion.file(context)]),
/**
* Generates a help entry and writes it to the clipboard.

View File

@@ -202,7 +202,7 @@ const IO = Module("io", {
let file = services.directory.get("TmpD", Ci.nsIFile);
file.append(config.tempFile);
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt('0600', 8));
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(600));
Cc["@mozilla.org/uriloader/external-helper-app-service;1"]
.getService(Ci.nsPIExternalAppLauncher).deleteTemporaryFileOnExit(file);

View File

@@ -655,6 +655,7 @@ const JavaScript = Module("javascript", {
return completer.call(obj, context, obj, args);
};
}
return arguments[0];
}
}, {
completion: function () {