mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-23 12:45:45 +01:00
Add lazy instantiation and completion to _.
This commit is contained in:
@@ -20,17 +20,25 @@ var Messages = Module("messages", {
|
|||||||
|
|
||||||
this.bundle = services.stringBundle.createBundle(JSMLoader.getTarget("dactyl://locale/messages.properties"));
|
this.bundle = services.stringBundle.createBundle(JSMLoader.getTarget("dactyl://locale/messages.properties"));
|
||||||
|
|
||||||
this._ = function _(message) {
|
this._ = Class("_", String, {
|
||||||
if (arguments.length > 1) {
|
init: function _(message) {
|
||||||
let args = Array.slice(arguments, 1);
|
this.args = arguments;
|
||||||
return this.format(message + "-" + args.length, args, null) || this.format(message, args);
|
},
|
||||||
}
|
value: Class.memoize(function () {
|
||||||
return this.get(message);
|
let message = this.args[0];
|
||||||
};
|
|
||||||
|
if (this.args.length > 1) {
|
||||||
|
let args = Array.slice(this.args, 1);
|
||||||
|
return self.format(message + "-" + args.length, args, null) || self.format(message, args);
|
||||||
|
}
|
||||||
|
return self.get(message);
|
||||||
|
}),
|
||||||
|
valueOf: function valueOf() this.value,
|
||||||
|
toString: function toString() this.value
|
||||||
|
});
|
||||||
|
|
||||||
let seen = {};
|
let seen = {};
|
||||||
for (let prop in iter(this.bundle.getSimpleEnumeration())) {
|
for (let { key } in this.iterate()) {
|
||||||
let key = prop.QueryInterface(Ci.nsIPropertyElement).key.split(".")[0];
|
|
||||||
if (!set.add(seen, key))
|
if (!set.add(seen, key))
|
||||||
this._[key] = this[key] = {
|
this._[key] = this[key] = {
|
||||||
__noSuchMethod__: function __(prop, args) self._.apply(self, [prop].concat(args))
|
__noSuchMethod__: function __(prop, args) self._.apply(self, [prop].concat(args))
|
||||||
@@ -38,6 +46,9 @@ var Messages = Module("messages", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
iterate: function () let (bundle = this.bundle)
|
||||||
|
iter(prop.QueryInterface(Ci.nsIPropertyElement) for (prop in iter(bundle.getSimpleEnumeration()))),
|
||||||
|
|
||||||
cleanup: function cleanup() {
|
cleanup: function cleanup() {
|
||||||
services.stringBundle.flushBundles();
|
services.stringBundle.flushBundles();
|
||||||
},
|
},
|
||||||
@@ -68,9 +79,17 @@ var Messages = Module("messages", {
|
|||||||
|
|
||||||
}, {
|
}, {
|
||||||
}, {
|
}, {
|
||||||
|
javascript: function initJavascript(dactyl, modules, window) {
|
||||||
|
modules.JavaScript.setCompleter([this._, this.get, this.format], [
|
||||||
|
function (context) {
|
||||||
|
context.keys = { text: "key", description: "value" };
|
||||||
|
return messages.iterate();
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var { _ } = messages.closure;
|
var { _ } = messages;
|
||||||
|
|
||||||
endModule();
|
endModule();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user