From a9e8d9d691353586eb1cb16624f80e472a37df88 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 13 Nov 2009 21:50:06 -0500 Subject: [PATCH] Make Option.validateCompleter the default validator: look out for minor breakage. --- common/content/autocommands.js | 3 +-- common/content/bookmarks.js | 3 +-- common/content/browser.js | 3 +-- common/content/buffer.js | 6 ++---- common/content/commandline.js | 13 ++++--------- common/content/hints.js | 9 +++------ common/content/io.js | 3 +-- common/content/options.js | 13 ++++++------- common/content/sanitizer.js | 6 ++---- common/content/statusline.js | 3 +-- common/content/tabs.js | 9 +++------ 11 files changed, 25 insertions(+), 46 deletions(-) diff --git a/common/content/autocommands.js b/common/content/autocommands.js index 0bd4e849..82b7e0cd 100755 --- a/common/content/autocommands.js +++ b/common/content/autocommands.js @@ -264,8 +264,7 @@ const AutoCommands = Module("autocommands", { "List of autocommand event names which should be ignored", "stringlist", "", { - completer: function () config.autocommands.concat([["all", "All events"]]), - validator: Option.validateCompleter + completer: function () config.autocommands.concat([["all", "All events"]]) }); options.add(["focuscontent", "fc"], diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index 5f04fa5f..e8d4766b 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -594,8 +594,7 @@ const Bookmarks = Module("bookmarks", { completer: function completer(context) { completion.search(context, true); context.completions = [["", "Don't perform searches by default"]].concat(context.completions); - }, - validator: Option.validateCompleter + } }); }, completion: function () { diff --git a/common/content/browser.js b/common/content/browser.js index 99354acc..49caf1a8 100644 --- a/common/content/browser.js +++ b/common/content/browser.js @@ -49,8 +49,7 @@ const Browser = Module("browser", { } catch (e) { liberator.reportError(e); } }, - completer: function (context) completion.charset(context), - validator: Option.validateCompleter + completer: function (context) completion.charset(context) }); // only available in FF 3.5 diff --git a/common/content/buffer.js b/common/content/buffer.js index 9760a865..a32c60f9 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -1612,8 +1612,7 @@ const Buffer = Module("buffer", { "Desired info in the :pageinfo output", "charlist", "gfm", { - completer: function (context) [[k, v[1]] for ([k, v] in Iterator(this.pageInfo))], - validator: Option.validateCompleter + completer: function (context) [[k, v[1]] for ([k, v] in Iterator(this.pageInfo))] }); options.add(["scroll", "scr"], @@ -1629,8 +1628,7 @@ const Buffer = Module("buffer", { ["0", "Don't show link destination"], ["1", "Show the link in the status line"], ["2", "Show the link in the command line"] - ], - validator: Option.validateCompleter + ] }); options.add(["usermode", "um"], diff --git a/common/content/commandline.js b/common/content/commandline.js index 9d9a58cb..9dc07444 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -1528,16 +1528,14 @@ const CommandLine = Module("commandline", { .filter(function (engine) engine.supportsResponseType("application/x-suggestions+json")); return engines.map(function (engine) [engine.alias, engine.description]); - }, - validator: Option.validateCompleter + } }); options.add(["complete", "cpt"], "Items which are completed at the :open prompts", "charlist", typeof(config.defaults["complete"]) == "string" ? config.defaults["complete"] : "slf", { - completer: function (context) array(values(completion.urlCompleters)), - validator: Option.validateCompleter + completer: function (context) array(values(completion.urlCompleters)) }); options.add(["wildcase", "wic"], @@ -1548,8 +1546,7 @@ const CommandLine = Module("commandline", { ["smart", "Case is significant when capital letters are typed"], ["match", "Case is always significant"], ["ignore", "Case is never significant"] - ], - validator: Option.validateCompleter + ] }); options.add(["wildignore", "wig"], @@ -1581,7 +1578,6 @@ const CommandLine = Module("commandline", { ["list:full", "List all and complete first match"], ["list:longest", "List all and complete common string"] ], - validator: Option.validateCompleter, checkHas: function (value, val) { let [first, second] = value.split(":", 2); return first == val || second == val; @@ -1598,8 +1594,7 @@ const CommandLine = Module("commandline", { ["auto", "Automatically show this._completions while you are typing"], ["sort", "Always sort the completion list"] ]; - }, - validator: Option.validateCompleter + } }); }, styles: function () { diff --git a/common/content/hints.js b/common/content/hints.js index 4c928e90..309e446f 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -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 ."], ["1", "Follow the selected hint on ."], ["2", "Follow the selected hint on only it's been -selected."] - ], - validator: Option.validateCompleter + ] }); 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."], ["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)"], - ], - validator: Option.validateCompleter + ] }); options.add(["wordseparators", "wsp"], @@ -1130,8 +1128,7 @@ const Hints = Module("hints", { ["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"], ["name", "Match against the name of an input field, only if neither a name or value could be found."] - ], - validator: Option.validateCompleter + ] }); } }); diff --git a/common/content/io.js b/common/content/io.js index 60245a00..c6550ba4 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -1077,8 +1077,7 @@ lookup: options.add(["fileencoding", "fenc"], "Sets the character encoding of read and written files", "string", "UTF-8", { - completer: function (context) completion.charset(context), - validator: Option.validateCompleter + completer: function (context) completion.charset(context) }); options.add(["cdpath", "cd"], "List of directories searched when executing :cd", diff --git a/common/content/options.js b/common/content/options.js index 24dec17e..46c75594 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -198,12 +198,7 @@ const Option = Class("Option", { * Returns whether the specified values are valid for this option. * @see Option#validator */ - isValidValue: function (values) { - if (this.validator) - return this.validator(values); - else - return true; - }, + isValidValue: function (values) this.validator(values), /** * 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 * 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 * contains a specified value. diff --git a/common/content/sanitizer.js b/common/content/sanitizer.js index e7264301..12a04d18 100644 --- a/common/content/sanitizer.js +++ b/common/content/sanitizer.js @@ -241,8 +241,7 @@ const Sanitizer = Module("sanitizer", { ["passwords", "Saved passwords"], ["sessions", "Authenticated sessions"], ["sitesettings", "Site preferences"], - ], - validator: Option.validateCompleter + ] }); options.add(["sanitizetimespan", "sts"], @@ -260,8 +259,7 @@ const Sanitizer = Module("sanitizer", { ["2", "Last two hours"], ["3", "Last four hours"], ["4", "Today"] - ], - validator: Option.validateCompleter + ] }); } }); diff --git a/common/content/statusline.js b/common/content/statusline.js index 676a089e..f455f09b 100644 --- a/common/content/statusline.js +++ b/common/content/statusline.js @@ -236,8 +236,7 @@ const StatusLine = Module("statusline", { ["0", "Never display status line"], ["1", "Display status line only if there are multiple windows"], ["2", "Always display status line"] - ], - validator: Option.validateCompleter + ] }); } }); diff --git a/common/content/tabs.js b/common/content/tabs.js index d1d35bf6..c92f8471 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -1056,8 +1056,7 @@ const Tabs = Module("tabs", { ["0", "Never show tab bar"], ["1", "Show tab bar only if more than one tab is open"], ["2", "Always show tab bar"] - ], - validator: Option.validateCompleter + ] }); if (config.hasTabbrowser) { @@ -1085,8 +1084,7 @@ const Tabs = Module("tabs", { ["help", ":h[elp] command"], ["javascript", ":javascript! or :js! command"], ["prefs", ":pref[erences]! or :prefs! command"] - ], - validator: Option.validateCompleter + ] }); // TODO: Is this really applicable to Xulmus? @@ -1113,8 +1111,7 @@ const Tabs = Module("tabs", { ["tab", "Open popups in a new tab"], ["window", "Open popups in a new window"], ["resized", "Open resized popups in a new window"] - ], - validator: Option.validateCompleter + ] }); } }