1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 02:17:59 +01:00

Better option validation messages for the more confusing validators.

This commit is contained in:
Kris Maglione
2010-09-28 17:06:46 -04:00
parent 50c1c568a2
commit c2c33b77fb
3 changed files with 18 additions and 5 deletions

View File

@@ -1183,7 +1183,8 @@ const Dactyl = Module("dactyl", {
options.safeSetPref("layout.scrollbar.side", opts.indexOf("l") >= 0 ? 3 : 2, options.safeSetPref("layout.scrollbar.side", opts.indexOf("l") >= 0 ? 3 : 2,
"See 'guioptions' scrollbar flags."); "See 'guioptions' scrollbar flags.");
}, },
validator: function (opts) (opts.indexOf("l") < 0 || opts.indexOf("r") < 0) validator: function (opts) Option.validIf(!(opts.indexOf("l") >= 0 && opts.indexOf("r") >= 0),
UTF8("Only one of l or r allowed"))
}, },
tab: { tab: {
feature: "tabs", feature: "tabs",
@@ -1271,7 +1272,7 @@ const Dactyl = Module("dactyl", {
options.add(["verbose", "vbs"], options.add(["verbose", "vbs"],
"Define which info messages are displayed", "Define which info messages are displayed",
"number", 1, "number", 1,
{ validator: function (value) value >= 0 && value <= 15 }); { validator: function (value) Option.validIf(value >= 0 && value <= 15, "Value must be between 0 and 15") });
options.add(["visualbell", "vb"], options.add(["visualbell", "vb"],
"Use visual bell instead of beeping on errors", "Use visual bell instead of beeping on errors",

View File

@@ -1072,7 +1072,8 @@ const Hints = Module("hints", {
["asdfg;lkjh", "Home Row"]], ["asdfg;lkjh", "Home Row"]],
validator: function (value) { validator: function (value) {
let values = events.fromString(value).map(events.closure.toString); let values = events.fromString(value).map(events.closure.toString);
return array.uniq(values).length === values.length; return Option.validIf(array.uniq(values).length === values.length,
"Duplicate keys not allowed")
} }
}); });

View File

@@ -234,8 +234,13 @@ const Option = Class("Option", {
if (newValues == null) if (newValues == null)
return "Operator " + operator + " not supported for option type " + this.type; return "Operator " + operator + " not supported for option type " + this.type;
if (!this.isValidValue(newValues)) try {
return this.invalidArgument(str || this.joinValues(values), operator); if (!this.isValidValue(newValues))
return this.invalidArgument(str || this.joinValues(values), operator);
}
catch (e) {
return this.invalidArgument(str || this.joinValues(values), operator) + ": " + e.message;
}
this.setValues(newValues, scope); this.setValues(newValues, scope);
return null; return null;
@@ -551,6 +556,12 @@ const Option = Class("Option", {
} }
}, },
validIf: function (test, error) {
if (test)
return true;
throw Error(error);
},
// TODO: Run this by default? // TODO: Run this by default?
/** /**
* Validates the specified <b>values</b> against values generated by the * Validates the specified <b>values</b> against values generated by the