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:
@@ -1183,7 +1183,8 @@ const Dactyl = Module("dactyl", {
|
||||
options.safeSetPref("layout.scrollbar.side", opts.indexOf("l") >= 0 ? 3 : 2,
|
||||
"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: {
|
||||
feature: "tabs",
|
||||
@@ -1271,7 +1272,7 @@ const Dactyl = Module("dactyl", {
|
||||
options.add(["verbose", "vbs"],
|
||||
"Define which info messages are displayed",
|
||||
"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"],
|
||||
"Use visual bell instead of beeping on errors",
|
||||
|
||||
@@ -1072,7 +1072,8 @@ const Hints = Module("hints", {
|
||||
["asdfg;lkjh", "Home Row"]],
|
||||
validator: function (value) {
|
||||
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")
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -234,8 +234,13 @@ const Option = Class("Option", {
|
||||
if (newValues == null)
|
||||
return "Operator " + operator + " not supported for option type " + this.type;
|
||||
|
||||
try {
|
||||
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);
|
||||
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?
|
||||
/**
|
||||
* Validates the specified <b>values</b> against values generated by the
|
||||
|
||||
Reference in New Issue
Block a user