1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 04:07:59 +01:00

Make Option.validateCompleter the default validator: look out for minor breakage.

This commit is contained in:
Kris Maglione
2009-11-13 21:50:06 -05:00
parent a75ef9a540
commit a9e8d9d691
11 changed files with 25 additions and 46 deletions

View File

@@ -264,8 +264,7 @@ const AutoCommands = Module("autocommands", {
"List of autocommand event names which should be ignored", "List of autocommand event names which should be ignored",
"stringlist", "", "stringlist", "",
{ {
completer: function () config.autocommands.concat([["all", "All events"]]), completer: function () config.autocommands.concat([["all", "All events"]])
validator: Option.validateCompleter
}); });
options.add(["focuscontent", "fc"], options.add(["focuscontent", "fc"],

View File

@@ -594,8 +594,7 @@ const Bookmarks = Module("bookmarks", {
completer: function completer(context) { completer: function completer(context) {
completion.search(context, true); completion.search(context, true);
context.completions = [["", "Don't perform searches by default"]].concat(context.completions); context.completions = [["", "Don't perform searches by default"]].concat(context.completions);
}, }
validator: Option.validateCompleter
}); });
}, },
completion: function () { completion: function () {

View File

@@ -49,8 +49,7 @@ const Browser = Module("browser", {
} }
catch (e) { liberator.reportError(e); } catch (e) { liberator.reportError(e); }
}, },
completer: function (context) completion.charset(context), completer: function (context) completion.charset(context)
validator: Option.validateCompleter
}); });
// only available in FF 3.5 // only available in FF 3.5

View File

@@ -1612,8 +1612,7 @@ const Buffer = Module("buffer", {
"Desired info in the :pageinfo output", "Desired info in the :pageinfo output",
"charlist", "gfm", "charlist", "gfm",
{ {
completer: function (context) [[k, v[1]] for ([k, v] in Iterator(this.pageInfo))], completer: function (context) [[k, v[1]] for ([k, v] in Iterator(this.pageInfo))]
validator: Option.validateCompleter
}); });
options.add(["scroll", "scr"], options.add(["scroll", "scr"],
@@ -1629,8 +1628,7 @@ const Buffer = Module("buffer", {
["0", "Don't show link destination"], ["0", "Don't show link destination"],
["1", "Show the link in the status line"], ["1", "Show the link in the status line"],
["2", "Show the link in the command line"] ["2", "Show the link in the command line"]
], ]
validator: Option.validateCompleter
}); });
options.add(["usermode", "um"], options.add(["usermode", "um"],

View File

@@ -1528,16 +1528,14 @@ const CommandLine = Module("commandline", {
.filter(function (engine) engine.supportsResponseType("application/x-suggestions+json")); .filter(function (engine) engine.supportsResponseType("application/x-suggestions+json"));
return engines.map(function (engine) [engine.alias, engine.description]); return engines.map(function (engine) [engine.alias, engine.description]);
}, }
validator: Option.validateCompleter
}); });
options.add(["complete", "cpt"], options.add(["complete", "cpt"],
"Items which are completed at the :open prompts", "Items which are completed at the :open prompts",
"charlist", typeof(config.defaults["complete"]) == "string" ? config.defaults["complete"] : "slf", "charlist", typeof(config.defaults["complete"]) == "string" ? config.defaults["complete"] : "slf",
{ {
completer: function (context) array(values(completion.urlCompleters)), completer: function (context) array(values(completion.urlCompleters))
validator: Option.validateCompleter
}); });
options.add(["wildcase", "wic"], options.add(["wildcase", "wic"],
@@ -1548,8 +1546,7 @@ const CommandLine = Module("commandline", {
["smart", "Case is significant when capital letters are typed"], ["smart", "Case is significant when capital letters are typed"],
["match", "Case is always significant"], ["match", "Case is always significant"],
["ignore", "Case is never significant"] ["ignore", "Case is never significant"]
], ]
validator: Option.validateCompleter
}); });
options.add(["wildignore", "wig"], options.add(["wildignore", "wig"],
@@ -1581,7 +1578,6 @@ const CommandLine = Module("commandline", {
["list:full", "List all and complete first match"], ["list:full", "List all and complete first match"],
["list:longest", "List all and complete common string"] ["list:longest", "List all and complete common string"]
], ],
validator: Option.validateCompleter,
checkHas: function (value, val) { checkHas: function (value, val) {
let [first, second] = value.split(":", 2); let [first, second] = value.split(":", 2);
return first == val || second == val; return first == val || second == val;
@@ -1598,8 +1594,7 @@ const CommandLine = Module("commandline", {
["auto", "Automatically show this._completions while you are typing"], ["auto", "Automatically show this._completions while you are typing"],
["sort", "Always sort the completion list"] ["sort", "Always sort the completion list"]
]; ];
}, }
validator: Option.validateCompleter
}); });
}, },
styles: function () { styles: function () {

View File

@@ -1100,8 +1100,7 @@ const Hints = Module("hints", {
["0", "Follow the first hint as soon as typed text uniquely identifies it. Follow the selected hint on <Return>."], ["0", "Follow the first hint as soon as typed text uniquely identifies it. Follow the selected hint on <Return>."],
["1", "Follow the selected hint on <Return>."], ["1", "Follow the selected hint on <Return>."],
["2", "Follow the selected hint on <Return> only it's been <Tab>-selected."] ["2", "Follow the selected hint on <Return> only it's been <Tab>-selected."]
], ]
validator: Option.validateCompleter
}); });
options.add(["hintmatching", "hm"], options.add(["hintmatching", "hm"],
@@ -1114,8 +1113,7 @@ const Hints = Module("hints", {
["firstletters", "Behaves like wordstartswith, but all groups much match a sequence of words."], ["firstletters", "Behaves like wordstartswith, but all groups much match a sequence of words."],
["custom", "Delegate to a custom function: liberator.plugins.customHintMatcher(hintString)"], ["custom", "Delegate to a custom function: liberator.plugins.customHintMatcher(hintString)"],
["transliterated", "When true, special latin characters are translated to their ascii equivalent (e.g., \u00e9 -> e)"], ["transliterated", "When true, special latin characters are translated to their ascii equivalent (e.g., \u00e9 -> e)"],
], ]
validator: Option.validateCompleter
}); });
options.add(["wordseparators", "wsp"], options.add(["wordseparators", "wsp"],
@@ -1130,8 +1128,7 @@ const Hints = Module("hints", {
["value", "Match against the value contained by the input field"], ["value", "Match against the value contained by the input field"],
["label", "Match against the value of a label for the input field, if one can be found"], ["label", "Match against the value of a label for the input field, if one can be found"],
["name", "Match against the name of an input field, only if neither a name or value could be found."] ["name", "Match against the name of an input field, only if neither a name or value could be found."]
], ]
validator: Option.validateCompleter
}); });
} }
}); });

View File

@@ -1077,8 +1077,7 @@ lookup:
options.add(["fileencoding", "fenc"], options.add(["fileencoding", "fenc"],
"Sets the character encoding of read and written files", "Sets the character encoding of read and written files",
"string", "UTF-8", { "string", "UTF-8", {
completer: function (context) completion.charset(context), completer: function (context) completion.charset(context)
validator: Option.validateCompleter
}); });
options.add(["cdpath", "cd"], options.add(["cdpath", "cd"],
"List of directories searched when executing :cd", "List of directories searched when executing :cd",

View File

@@ -198,12 +198,7 @@ const Option = Class("Option", {
* Returns whether the specified <b>values</b> are valid for this option. * Returns whether the specified <b>values</b> are valid for this option.
* @see Option#validator * @see Option#validator
*/ */
isValidValue: function (values) { isValidValue: function (values) this.validator(values),
if (this.validator)
return this.validator(values);
else
return true;
},
/** /**
* Resets the option to its default value. * Resets the option to its default value.
@@ -370,7 +365,11 @@ const Option = Class("Option", {
* @property {function} The function called to validate the option's value * @property {function} The function called to validate the option's value
* when set. * when set.
*/ */
validator: null, validator: function () {
if (this.completer)
return Option.validateCompleter.apply(this, arguments);
return true;
},
/** /**
* @property The function called to determine whether the option already * @property The function called to determine whether the option already
* contains a specified value. * contains a specified value.

View File

@@ -241,8 +241,7 @@ const Sanitizer = Module("sanitizer", {
["passwords", "Saved passwords"], ["passwords", "Saved passwords"],
["sessions", "Authenticated sessions"], ["sessions", "Authenticated sessions"],
["sitesettings", "Site preferences"], ["sitesettings", "Site preferences"],
], ]
validator: Option.validateCompleter
}); });
options.add(["sanitizetimespan", "sts"], options.add(["sanitizetimespan", "sts"],
@@ -260,8 +259,7 @@ const Sanitizer = Module("sanitizer", {
["2", "Last two hours"], ["2", "Last two hours"],
["3", "Last four hours"], ["3", "Last four hours"],
["4", "Today"] ["4", "Today"]
], ]
validator: Option.validateCompleter
}); });
} }
}); });

View File

@@ -236,8 +236,7 @@ const StatusLine = Module("statusline", {
["0", "Never display status line"], ["0", "Never display status line"],
["1", "Display status line only if there are multiple windows"], ["1", "Display status line only if there are multiple windows"],
["2", "Always display status line"] ["2", "Always display status line"]
], ]
validator: Option.validateCompleter
}); });
} }
}); });

View File

@@ -1056,8 +1056,7 @@ const Tabs = Module("tabs", {
["0", "Never show tab bar"], ["0", "Never show tab bar"],
["1", "Show tab bar only if more than one tab is open"], ["1", "Show tab bar only if more than one tab is open"],
["2", "Always show tab bar"] ["2", "Always show tab bar"]
], ]
validator: Option.validateCompleter
}); });
if (config.hasTabbrowser) { if (config.hasTabbrowser) {
@@ -1085,8 +1084,7 @@ const Tabs = Module("tabs", {
["help", ":h[elp] command"], ["help", ":h[elp] command"],
["javascript", ":javascript! or :js! command"], ["javascript", ":javascript! or :js! command"],
["prefs", ":pref[erences]! or :prefs! command"] ["prefs", ":pref[erences]! or :prefs! command"]
], ]
validator: Option.validateCompleter
}); });
// TODO: Is this really applicable to Xulmus? // TODO: Is this really applicable to Xulmus?
@@ -1113,8 +1111,7 @@ const Tabs = Module("tabs", {
["tab", "Open popups in a new tab"], ["tab", "Open popups in a new tab"],
["window", "Open popups in a new window"], ["window", "Open popups in a new window"],
["resized", "Open resized popups in a new window"] ["resized", "Open resized popups in a new window"]
], ]
validator: Option.validateCompleter
}); });
} }
} }