mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 16:17:59 +01:00
Allow exporting to a directory as well as an archive with dactyl.exportHelp.
This commit is contained in:
@@ -60,6 +60,7 @@
|
|||||||
"prefs",
|
"prefs",
|
||||||
"storage",
|
"storage",
|
||||||
"util",
|
"util",
|
||||||
|
"javascript",
|
||||||
"dactyl",
|
"dactyl",
|
||||||
"modes",
|
"modes",
|
||||||
"abbreviations",
|
"abbreviations",
|
||||||
@@ -76,7 +77,6 @@
|
|||||||
"highlight",
|
"highlight",
|
||||||
"hints",
|
"hints",
|
||||||
"io",
|
"io",
|
||||||
"javascript",
|
|
||||||
"mappings",
|
"mappings",
|
||||||
"marks",
|
"marks",
|
||||||
"options",
|
"options",
|
||||||
|
|||||||
@@ -538,19 +538,29 @@ const Dactyl = Module("dactyl", {
|
|||||||
return UTF8(xml.toXMLString());
|
return UTF8(xml.toXMLString());
|
||||||
},
|
},
|
||||||
|
|
||||||
exportHelp: function (path) {
|
|
||||||
|
exportHelp: JavaScript.setCompleter(function (path) {
|
||||||
const FILE = io.File(path);
|
const FILE = io.File(path);
|
||||||
const PATH = FILE.leafName.replace(/\..*/, "") + "/";
|
const PATH = FILE.leafName.replace(/\..*/, "") + "/";
|
||||||
const TIME = Date.now();
|
const TIME = Date.now();
|
||||||
|
|
||||||
|
if (!FILE.exists() && (/\/$/.test(path) && !/\./.test(FILE.leafName)))
|
||||||
|
FILE.create(FILE.DIRECTORY_TYPE, octal(755));
|
||||||
|
|
||||||
dactyl.initHelp();
|
dactyl.initHelp();
|
||||||
let zip = services.ZipWriter();
|
if (FILE.isDirectory()) {
|
||||||
zip.open(FILE, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
|
function addDataEntry(file, data) FILE.child(file).write(data);
|
||||||
function addURIEntry(file, uri)
|
function addURIEntry(file, uri) addDataEntry(file, util.httpGet(uri).responseText);
|
||||||
zip.addEntryChannel(PATH + file, TIME, 9,
|
}
|
||||||
services.io.newChannel(uri, null, null), false);
|
else {
|
||||||
function addDataEntry(file, data) // Unideal to an extreme.
|
var zip = services.ZipWriter();
|
||||||
addURIEntry(file, "data:text/plain;charset=UTF-8," + encodeURI(data));
|
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"
|
let empty = set("area base basefont br col frame hr img input isindex link meta param"
|
||||||
.split(" "));
|
.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))]
|
let data = [h for (h in highlight) if (set.has(styles, h.class) || /^Help/.test(h.class))]
|
||||||
.map(function (h)
|
.map(function (h) h.selector
|
||||||
h.selector.replace(/^\[.*?=(.*?)\]/, ".hl-$1").replace(/html\|/, "") + "\t" +
|
.replace(/^\[.*?=(.*?)\]/, ".hl-$1")
|
||||||
"{" + h.value + "}")
|
.replace(/html\|/, "") + "\t" + "{" + h.value + "}")
|
||||||
.join("\n");
|
.join("\n");
|
||||||
addDataEntry("help.css", data.replace(/chrome:[^ ")]+\//g, ""));
|
addDataEntry("help.css", data.replace(/chrome:[^ ")]+\//g, ""));
|
||||||
|
|
||||||
@@ -632,8 +642,9 @@ const Dactyl = Module("dactyl", {
|
|||||||
for (let [uri, leaf] in Iterator(chrome))
|
for (let [uri, leaf] in Iterator(chrome))
|
||||||
addURIEntry(leaf, uri);
|
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.
|
* Generates a help entry and writes it to the clipboard.
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ const IO = Module("io", {
|
|||||||
let file = services.directory.get("TmpD", Ci.nsIFile);
|
let file = services.directory.get("TmpD", Ci.nsIFile);
|
||||||
|
|
||||||
file.append(config.tempFile);
|
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"]
|
Cc["@mozilla.org/uriloader/external-helper-app-service;1"]
|
||||||
.getService(Ci.nsPIExternalAppLauncher).deleteTemporaryFileOnExit(file);
|
.getService(Ci.nsPIExternalAppLauncher).deleteTemporaryFileOnExit(file);
|
||||||
|
|
||||||
|
|||||||
@@ -655,6 +655,7 @@ const JavaScript = Module("javascript", {
|
|||||||
return completer.call(obj, context, obj, args);
|
return completer.call(obj, context, obj, args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
return arguments[0];
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
completion: function () {
|
completion: function () {
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ defineModule("base", {
|
|||||||
"call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule",
|
"call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule",
|
||||||
"endModule", "forEach", "isArray", "isGenerator", "isinstance",
|
"endModule", "forEach", "isArray", "isGenerator", "isinstance",
|
||||||
"isObject", "isString", "isSubclass", "iter", "iterAll", "keys",
|
"isObject", "isString", "isSubclass", "iter", "iterAll", "keys",
|
||||||
"memoize", "properties", "set", "update", "values",
|
"memoize", "octal", "properties", "set", "update", "values",
|
||||||
"withCallerGlobal"
|
"withCallerGlobal"
|
||||||
],
|
],
|
||||||
use: ["services", "util"]
|
use: ["services", "util"]
|
||||||
@@ -1008,6 +1008,8 @@ function UTF8(str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function octal(decimal) parseInt(decimal, 8);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array utility methods.
|
* Array utility methods.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,16 +16,10 @@ defineModule("storage", {
|
|||||||
|
|
||||||
const win32 = /^win(32|nt)$/i.test(services.runtime.OS);
|
const win32 = /^win(32|nt)$/i.test(services.runtime.OS);
|
||||||
|
|
||||||
function getFile(name) {
|
|
||||||
let file = storage.infoPath.clone();
|
|
||||||
file.append(name);
|
|
||||||
return File(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadData(name, store, type) {
|
function loadData(name, store, type) {
|
||||||
try {
|
try {
|
||||||
if (storage.infoPath)
|
if (storage.infoPath)
|
||||||
var file = getFile(name).read();
|
var file = storage.infoPath.child(name);
|
||||||
if (file)
|
if (file)
|
||||||
var result = services.json.decode(file);
|
var result = services.json.decode(file);
|
||||||
if (result instanceof type)
|
if (result instanceof type)
|
||||||
@@ -38,7 +32,7 @@ function saveData(obj) {
|
|||||||
if (obj.privateData && storage.privateMode)
|
if (obj.privateData && storage.privateMode)
|
||||||
return;
|
return;
|
||||||
if (obj.store && storage.infoPath)
|
if (obj.store && storage.infoPath)
|
||||||
getFile(obj.name).write(obj.serial);
|
storage.infoPath.child(obj.name).write(obj.serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
const StoreBase = Class("StoreBase", {
|
const StoreBase = Class("StoreBase", {
|
||||||
@@ -246,12 +240,8 @@ const Storage = Module("Storage", {
|
|||||||
}, {
|
}, {
|
||||||
}, {
|
}, {
|
||||||
init: function (dactyl, modules) {
|
init: function (dactyl, modules) {
|
||||||
let infoPath = File(modules.IO.runtimePath.replace(/,.*/, ""));
|
storage.infoPath = File(modules.IO.runtimePath.replace(/,.*/, ""))
|
||||||
if (infoPath) {
|
.child("info").child(dactyl.profileName);
|
||||||
infoPath.append("info");
|
|
||||||
infoPath.append(dactyl.profileName);
|
|
||||||
storage.infoPath = infoPath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -268,7 +258,7 @@ const File = Class("File", {
|
|||||||
let file = services.File();
|
let file = services.File();
|
||||||
|
|
||||||
if (path instanceof Ci.nsIFile)
|
if (path instanceof Ci.nsIFile)
|
||||||
file = path.QueryInterface(Ci.nsIFile);
|
file = path.QueryInterface(Ci.nsIFile).clone();
|
||||||
else if (/file:\/\//.test(path))
|
else if (/file:\/\//.test(path))
|
||||||
file = services["File:"]().getFileFromURLSpec(path);
|
file = services["File:"]().getFileFromURLSpec(path);
|
||||||
else {
|
else {
|
||||||
@@ -300,6 +290,15 @@ const File = Class("File", {
|
|||||||
yield File(file);
|
yield File(file);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new file for the given child of this directory entry.
|
||||||
|
*/
|
||||||
|
child: function (name) {
|
||||||
|
let f = this.constructor(this);
|
||||||
|
f.append(name);
|
||||||
|
return f;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads this file's entire contents in "text" mode and returns the
|
* Reads this file's entire contents in "text" mode and returns the
|
||||||
* content as a string.
|
* content as a string.
|
||||||
@@ -398,7 +397,7 @@ const File = Class("File", {
|
|||||||
mode = File.MODE_WRONLY | File.MODE_CREATE | File.MODE_TRUNCATE;
|
mode = File.MODE_WRONLY | File.MODE_CREATE | File.MODE_TRUNCATE;
|
||||||
|
|
||||||
if (!perms)
|
if (!perms)
|
||||||
perms = parseInt('0644', 8);
|
perms = octal(644);
|
||||||
if (!this.exists()) // OCREAT won't create the directory
|
if (!this.exists()) // OCREAT won't create the directory
|
||||||
this.create(this.NORMAL_FILE_TYPE, perms);
|
this.create(this.NORMAL_FILE_TYPE, perms);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user