1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-08 22:24:11 +01:00

Automagically generate option types and default value entities for options.xml.

This commit is contained in:
Kris Maglione
2011-03-15 23:12:28 -04:00
parent 2d03f3f9ca
commit f1965c81ff
8 changed files with 167 additions and 145 deletions

View File

@@ -27,12 +27,7 @@ var ConfigBase = Class("ConfigBase", {
set.add(this.features, "Gecko2");
this.timeout(function () {
services["dactyl:"].pages.dtd = function () [null,
iter(config.dtdExtra,
(["dactyl." + k, v] for ([k, v] in iter(config.dtd))),
(["dactyl." + s, config[s]] for each (s in config.dtdStrings)))
.map(function ([k, v]) ["<!ENTITY ", k, " '", String.replace(v || "null", /'/g, "&apos;"), "'>"].join(""))
.join("\n")]
services["dactyl:"].pages.dtd = function () [null, util.makeDTD(config.dtd)];
});
},
@@ -168,9 +163,15 @@ var ConfigBase = Class("ConfigBase", {
return version;
}),
get fileExt() this.name.slice(0, -5),
get fileExt() this.name.slice(0, -6),
dtd: memoize({
dtd: Class.memoize(function ()
iter(this.dtdExtra,
(["dactyl." + k, v] for ([k, v] in iter(config.dtdDactyl))),
(["dactyl." + s, config[s]] for each (s in config.dtdStrings)))
.toObject()),
dtdDactyl: memoize({
get name() config.name,
get home() "http://dactyl.sourceforge.net/",
get apphome() this.home + this.name,

View File

@@ -67,7 +67,7 @@ var Messages = Module("messages", {
catch (e) {}
// Report error so tests fail, but don't throw
if (arguments.length < 2)
if (arguments.length < 2) // Do *not* localize these strings
util.reportError(Error("Invalid locale string: " + value));
return arguments.length > 1 ? default_ : value;
},
@@ -80,7 +80,7 @@ var Messages = Module("messages", {
catch (e) {}
// Report error so tests fail, but don't throw
if (arguments.length < 3)
if (arguments.length < 3) // Do *not* localize these strings
util.reportError(Error("Invalid locale string: " + value));
return arguments.length > 2 ? default_ : value;
}

View File

@@ -748,6 +748,18 @@ var Options = Module("options", {
if (event == "change" && opt)
opt.set(opt.globalValue, Option.SCOPE_GLOBAL, true);
}, window);
services["dactyl:"].pages["options.dtd"] = function () [null,
util.makeDTD(
iter(([["option", o.name, "default"].join("."),
o.type === "string" ? o.value.replace(/'/g, "''") :
o.value === true ? "on" :
o.value === false ? "off" : o.stringDefaultValue]
for (o in self)),
([["option", o.name, "type"].join("."), o.type] for (o in self)),
config.dtd))];
},
dactyl: dactyl,

View File

@@ -171,7 +171,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
let saved = this.get(this.SAVED + name);
if (saved == null && curval != defval || saved != null && curval != saved) {
let msg = "Warning: setting preference " + name + ", but it's changed from its default value.";
let msg = _("pref.safeSet.warnChanged", name);
if (message)
msg = template.linkifyHelp(msg + " " + message);
util.dactyl.warn(msg);

View File

@@ -974,6 +974,12 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
.map(function (node) "//" + node).join(" | ");
},
makeDTD: function makeDTD(obj) unescape(encodeURI(iter(obj)
.map(function ([k, v]) ["<!ENTITY ", k, ' "', String.replace(v == null ? "null" : v, /[&"<%]/g,
function (m) ({ '"': "&quot;", "&": "&amp;", "<": "&lt;", "%": "&#x25;" })[m]),
'">'].join(""))
.join("\n"))),
map: deprecated("iter.map", function map(obj, fn, self) iter(obj).map(fn, self).toArray()),
writeToClipboard: deprecated("dactyl.clipboardWrite", function writeToClipboard(str, verbose) util.dactyl.clipboardWrite(str, verbose)),
readFromClipboard: deprecated("dactyl.clipboardRead", function readFromClipboard() util.dactyl.clipboardRead(false)),