From f1965c81ffa3bd71efb2769ac655fc62b310d14a Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 15 Mar 2011 23:12:28 -0400 Subject: [PATCH] Automagically generate option types and default value entities for options.xml. --- common/content/statusline.js | 3 +- common/locale/en-US/messages.properties | 1 + common/locale/en-US/options.xml | 267 ++++++++++++------------ common/modules/config.jsm | 17 +- common/modules/messages.jsm | 4 +- common/modules/options.jsm | 12 ++ common/modules/prefs.jsm | 2 +- common/modules/util.jsm | 6 + 8 files changed, 167 insertions(+), 145 deletions(-) diff --git a/common/content/statusline.js b/common/content/statusline.js index a839fb67..062c6c65 100644 --- a/common/content/statusline.js +++ b/common/content/statusline.js @@ -264,7 +264,8 @@ var StatusLine = Module("statusline", { get bookmarked() this._bookmarked, set bookmarked(val) { this._bookmarked = val; - this.status = this.status; + if (this.status) + this.status = this.status; }, updateStatus: function updateStatus() { diff --git a/common/locale/en-US/messages.properties b/common/locale/en-US/messages.properties index adafe648..ac04b91e 100644 --- a/common/locale/en-US/messages.properties +++ b/common/locale/en-US/messages.properties @@ -211,6 +211,7 @@ plugin.searchingForIn-2 = Searching for %S in %S plugin.notReplacingContext-1 = Not replacing plugin context for %S pref.prompt.resetAll-1 = Warning: Resetting all preferences may make %S unusable. Would you like to continue (yes/[no]): +pref.safeSet.warnChanged-1 = Warning: Setting preference %S, but it's changed from its default value. print.toFile-1 = Printing to file: %S print.sending = Sending to printer... diff --git a/common/locale/en-US/options.xml b/common/locale/en-US/options.xml index 9f911abf..84fbe2be 100644 --- a/common/locale/en-US/options.xml +++ b/common/locale/en-US/options.xml @@ -1,7 +1,7 @@ - + 'act' 'activate' 'activate' 'act' - stringlist + &option.activate.type; addons,bookmarks,diverted,downloads,extoptions, help,homepage,quickmark,tabopen,paste @@ -358,8 +358,8 @@ 'awim' 'altwildmode' 'altwildmode' 'awim' - stringlist - list:full + &option.altwildmode.type; + &option.altwildmode.default;

Like wildmode, but when the key @@ -371,8 +371,8 @@ 'au' 'autocomplete' 'autocomplete' 'au' - regexplist - .* + &option.autocomplete.type; + &option.autocomplete.default;

Enables automatic completion for completion contexts (see @@ -413,8 +413,8 @@ 'bh' 'banghist' 'banghist' 'bh' - boolean - on + &option.banghist.type; + &option.banghist.default;

Replace occurrences of ! with the previous command when @@ -427,7 +427,7 @@ $CDPATH 'cd' 'cdpath' 'cdpath' 'cd' - stringlist + &option.cdpath.type; equivalent to . or .,$CDPATH

@@ -445,8 +445,8 @@ 'ca' 'cookieaccept' 'cookieaccept' 'ca' - string - all + &option.cookieaccept.type; + &option.cookieaccept.default;

When to accept cookies.

@@ -461,8 +461,8 @@ 'cl' 'cookielifetime' 'cookielifetime' - string - default + &option.cookielifetime.type; + &option.cookielifetime.default;

The lifetime for which to accept cookies. The available @@ -482,7 +482,8 @@ 'ck' 'cookies' 'cookies' 'ck' - stringlist session + &option.cookies.type; + &option.cookies.default;

The default action for the :cookies command.

@@ -491,8 +492,8 @@ 'cpt' 'complete' 'complete' 'cpt' - charlist - slf + &option.complete.type; + &option.complete.default;

Items which are completed at the :open prompts. Available items:

@@ -521,8 +522,8 @@ 'ds' 'defsearch' 'defsearch' 'ds' - string - google + &option.defsearch.type; + &option.defsearch.default;

Sets the default search engine. The default search engine is @@ -543,8 +544,8 @@ 'editor' 'editor' - string - ]]> + &option.editor.type; + &option.editor.default;

Set the external text editor. @@ -576,8 +577,8 @@ 'enc' 'encoding' 'encoding' 'enc' - string - UTF-8 + &option.encoding.type; + &option.encoding.default;

Changes the character encoding of the current buffer. Valid only @@ -590,8 +591,8 @@ 'noeb' 'noerrorbells' 'eb' 'errorbells' 'errorbells' 'eb' - boolean - off + &option.errorbells.type; + &option.errorbells.default;

Ring the bell when an error message is displayed. See also @@ -603,8 +604,8 @@ 'ei' 'eventignore' 'eventignore' 'ei' - stringlist - + &option.eventignore.type; + &option.eventignore.default;

A list of autocommand event names which should be ignored. If the @@ -618,8 +619,8 @@ 'noex' 'noexrc' 'ex' 'exrc' 'exrc' 'ex' - boolean - off + &option.exrc.type; + &option.exrc.default;

Allow reading of an RC file in the current directory. This file is @@ -633,7 +634,7 @@ 'eht' 'extendedhinttags' 'extendedhinttags' 'eht' - regexpmap + &option.extendedhinttags.type; [asOTivVWy]:a[href],area[href],img[src],iframe[src], [f]:body, [F]:body,code,div,html,p,pre,span, @@ -652,8 +653,8 @@ 'fenc' 'fileencoding' 'fileencoding' 'fenc' - string - UTF-8 + &option.fileencoding.type; + &option.fileencoding.default;

Changes the character encoding that &dactyl.appName; uses to read @@ -665,8 +666,8 @@ 'fc' 'findcase' 'findcase' 'fc' - string - smart + &option.findcase.type; + &option.findcase.default;

Find case matching mode.

@@ -681,8 +682,8 @@ 'fh' 'followhints' 'followhints' 'fh' - number - 0 + &option.followhints.type; + &option.followhints.default;

Changes how soon matching hints are followed in Hints mode.

@@ -700,8 +701,8 @@ 'nofs' 'nofullscreen' 'fs' 'fullscreen' 'fullscreen' 'fs' - boolean - off + &option.fullscreen.type; + &option.fullscreen.default;

Show the current window full-screen. Also hide certain GUI elements, such as @@ -713,8 +714,8 @@ 'go' 'guioptions' 'guioptions' 'go' - charlist - bCrs + &option.guioptions.type; + &option.guioptions.default;

Show or hide certain GUI elements.

@@ -745,8 +746,8 @@ 'hf' 'helpfile' 'helpfile' 'hf' - string - intro + &option.helpfile.type; + &option.helpfile.default;

Name of the main help file. This is that page shown if the @@ -758,8 +759,8 @@ 'hin' 'hintinputs' 'hintinputs' 'hin' - stringlist - label,value + &option.hintinputs.type; + &option.hintinputs.default;

When generating hints for input elements that do not have an @@ -779,8 +780,8 @@ 'hk' 'hintkeys' 'hintkeys' 'hk' - string - 0123456789 + &option.hintkeys.type; + &option.hintkeys.default;

The keys used to label and select hints. With its default value, @@ -795,8 +796,8 @@ 'hm' 'hintmatching' 'hintmatching' 'hm' - stringlist - contains + &option.hintmatching.type; + &option.hintmatching.default;

Change the hint matching algorithm used in Hints mode.

@@ -848,7 +849,7 @@ 'ht' 'hinttags' 'hinttags' 'ht' - stringlist + &option.hinttags.type; a,area,button,iframe,input:not([type=hidden]),select,textarea, [onclick],[onmouseover],[onmousedown],[onmouseup],[oncommand], [tabindex],[role=link],[role=button] @@ -867,8 +868,8 @@ 'hto' 'hinttimeout' 'hinttimeout' 'hto' - number - 0 + &option.hinttimeout.type; + &option.hinttimeout.default;

Timeout in milliseconds before automatically following a non-unique @@ -883,8 +884,8 @@ 'hi' 'history' 'history' 'hi' - number - 500 + &option.history.type; + &option.history.default;

Maximum number of Ex commands and find patterns to store in the @@ -897,8 +898,8 @@ 'nohlf' 'nohlfind' 'hlf' 'hlfind' 'hlfind' 'hlf' - boolean - off + &option.hlfind.type; + &option.hlfind.default;

Highlight previous find pattern matches.

@@ -908,8 +909,8 @@ 'noif' 'noincfind' 'if' 'incfind' 'incfind' 'if' - boolean - on + &option.incfind.type; + &option.incfind.default;

Show the first match for a find pattern as it is typed.

@@ -919,8 +920,8 @@ 'noim' 'noinsertmode' 'im' 'insertmode' 'insertmode' 'im' - boolean - on + &option.insertmode.type; + &option.insertmode.default;

Use Insert mode as the default for text areas. This is useful if you @@ -939,8 +940,8 @@ 'nojsd' 'nojsdebugger' 'jsd' 'jsdebugger' 'jsdebugger' 'jsd' - boolean - off + &option.jsdebugger.type; + &option.jsdebugger.default;

Use the JavaScript debugger service for JavaScript completion. @@ -952,8 +953,8 @@ 'nolpl' 'noloadplugins' 'lpl' 'loadplugins' 'loadplugins' 'lpl' - regexplist - '\.(js|&dactyl.fileExt;)$' + &option.loadplugins.type; + &option.loadplugins.default;

A regular expression list that defines which plugins are loaded at @@ -990,8 +991,8 @@ 'ml' 'mapleader' 'mapleader' 'ml' - string - \ + &option.mapleader.type; + &option.mapleader.default;

Defines the replacement keys for the pseudo-key.

@@ -1000,8 +1001,8 @@ 'maxitems' 'maxitems' - number - 20 + &option.maxitems.type; + &option.maxitems.default;

Maximum number of items to display at once in a listing.

@@ -1010,8 +1011,8 @@ 'msgs' 'messages' 'messages' 'msgs' - number - 100 + &option.messages.type; + &option.messages.default;

Maximum number of messages to store in the message history.

@@ -1020,8 +1021,8 @@ 'nomore' 'more' 'more' - boolean - on + &option.more.type; + &option.more.default;

Pause the message list window when more than one screen of @@ -1033,8 +1034,8 @@ 'newtab' 'newtab' - stringlist - + &option.newtab.type; + &option.newtab.default;

Defines which Ex commands open pages in new tabs rather than the @@ -1062,8 +1063,8 @@ 'nextpattern' 'nextpattern' - stringlist - '\bnext',^>$,'^(>>|»)$','^(>|»)','(>|»)$','\bmore\b' + &option.nextpattern.type; + &option.nextpattern.default;

Patterns to use when guessing the next page in a document @@ -1078,8 +1079,8 @@ 'noonline' 'online' 'online' - boolean - on + &option.online.type; + &option.online.default;

Enables or disables ‘offline’ mode, where network access is @@ -1091,8 +1092,8 @@ 'pa' 'pageinfo' 'pageinfo' 'pa' - charlist - gfm + &option.pageinfo.type; + &option.pageinfo.default;

Info shown in the :pageinfo output.

@@ -1114,8 +1115,8 @@ 'pk' 'passkeys' 'passkeys' 'pk' - sitemap - + &option.passkeys.type; + &option.passkeys.default;

Pass certain keys through directly for the given URLs. @@ -1144,8 +1145,8 @@ 'pps' 'popups' 'popups' 'pps' - stringlist - tab + &option.popups.type; + &option.popups.default;

Defines where to show requested pop-up windows. Applies only to @@ -1179,8 +1180,8 @@ 'previouspattern' 'previouspattern' - stringlist - + &option.previouspattern.type; + &option.previouspattern.default;

Patterns to use when guessing the previous page in a document @@ -1195,8 +1196,8 @@ 'noprivate' 'private' 'private' - boolean - off + &option.private.type; + &option.private.default;

Set the private browsing option. In private browsing mode @@ -1213,7 +1214,7 @@ $&dactyl.idName;_RUNTIME 'rtp' 'runtimepath' 'runtimepath' 'rtp' - stringlist + &option.runtimepath.type; $&dactyl.idName;_RUNTIME or Unix, Mac: ~/.&dactyl.name; Windows: ~/&dactyl.name; @@ -1247,8 +1248,8 @@ 'si' 'sanitizeitems' 'sanitizeitems' 'si' - stringlist - all + &option.sanitizeitems.type; + &option.sanitizeitems.default;

The default list of private items to sanitize. See @@ -1260,8 +1261,8 @@ 'ss' 'sanitizeshutdown' 'sanitizeshutdown' 'ss' - stringlist - + &option.sanitizeshutdown.type; + &option.sanitizeshutdown.default;

The items to sanitize automatically at shutdown.

@@ -1271,8 +1272,8 @@ 'sts' 'sanitizetimespan' 'sanitizetimespan' 'sts' - number - all + &option.sanitizetimespan.type; + &option.sanitizetimespan.default;

The default sanitizer time span. Only items created within this timespan are @@ -1293,8 +1294,8 @@ 'scr' 'scroll' 'scroll' 'scr' - number - 0 + &option.scroll.type; + &option.scroll.default;

Number of lines to scroll with and @@ -1309,7 +1310,7 @@ 'sh' 'shell' 'shell' 'sh' - string + &option.shell.type; $SHELL or sh, Windows: cmd.exe

Shell to use for executing :! and :run commands.

@@ -1320,7 +1321,7 @@ 'shcf' 'shellcmdflag' 'shellcmdflag' 'shcf' - string + &option.shellcmdflag.type; -c, Windows: /c

Flag passed to shell when executing :! and :run commands.

@@ -1331,8 +1332,8 @@ 'nosmd' 'noshowmode' 'smd' 'showmode' 'showmode' 'smd' - regexplist - !^normal$ + &option.showmode.type; + &option.showmode.default;

Show the current mode in the command line if it matches this expression.

@@ -1342,8 +1343,8 @@ 'ssli' 'showstatuslinks' 'showstatuslinks' 'ssli' - string - status + &option.showstatuslinks.type; + &option.showstatuslinks.default;

When the mouse hovers over a link, or a link is otherwise focused, @@ -1363,8 +1364,8 @@ 'stal' 'showtabline' 'showtabline' 'stal' - string - always + &option.showtabline.type; + &option.showtabline.default;

Define when the tab bar is visible.

@@ -1380,8 +1381,8 @@ 'nosf' 'nostrictfocus' 'sf' 'strictfocus' 'strictfocus' 'sf' - boolean - on + &option.strictfocus.type; + &option.strictfocus.default;

Prevent scripts from focusing input elements without user intervention. @@ -1392,8 +1393,8 @@ 'suggestengines' 'suggestengines' - stringlist - google + &option.suggestengines.type; + &option.suggestengines.default;

Set the search engines which can be used for completion @@ -1406,8 +1407,8 @@ 'notmo' 'notimeout' 'tmo' 'timeout' 'timeout' 'tmo' - boolean - true + &option.timeout.type; + &option.timeout.default;

When this option is set and a key sequence interpretable both as a @@ -1420,8 +1421,8 @@ 'tmol' 'timeoutlen' 'timeoutlen' 'tmol' - number - 1000 + &option.timeoutlen.type; + &option.timeoutlen.default;

Maximum number of milliseconds to wait for a longer key command @@ -1434,8 +1435,8 @@ 'titlestring' 'titlestring' - string - &dactyl.appName; + &option.titlestring.type; + &option.titlestring.default;

Set the application name shown after the current page title in @@ -1448,8 +1449,8 @@ 'us' 'urlsep' 'urlseparator' 'urlseparator' 'urlsep' 'us' - string - \| + &option.urlseparator.type; + &option.urlseparator.default;

The regular expression used to split URL lists in commands @@ -1465,8 +1466,8 @@ 'noum' 'nousermode' 'um' 'usermode' 'usermode' 'um' - boolean - off + &option.usermode.type; + &option.usermode.default;

Show current website with minimal styling.

@@ -1475,8 +1476,8 @@ 'vbs' 'verbose' 'verbose' 'vbs' - number - 1 + &option.verbose.type; + &option.verbose.default;

Define which info messages are displayed. As the value increases, @@ -1493,8 +1494,8 @@ 'novb' 'novisualbell' 'vb' 'visualbell' 'visualbell' 'vb' - boolean - off + &option.visualbell.type; + &option.visualbell.default;

Use visual bell instead of beeping on errors. The visual bell @@ -1508,8 +1509,8 @@ 'wia' 'wildanchor' 'wildanchor' 'wia' - regexplist - !'/ex/(back|buffer|ext|forward|help|undo)' + &option.wildanchor.type; + &option.wildanchor.default;

Regular expression list defining which completion groups show only @@ -1526,8 +1527,8 @@ 'wic' 'wildcase' 'wildcase' 'wic' - regexpmap - .?:smart + &option.wildcase.type; + &option.wildcase.default;

Defines how completions are matched with regard to character case. @@ -1547,8 +1548,8 @@ 'wig' 'wildignore' 'wildignore' 'wig' - regexplist - + &option.wildignore.type; + &option.wildignore.default;

List of file patterns to ignore when completing files. For example, @@ -1564,8 +1565,8 @@ 'wim' 'wildmode' 'wildmode' 'wim' - stringlist - list:full + &option.wildmode.type; + &option.wildmode.default;

Defines how command-line completion works. It is a comma-separated @@ -1602,8 +1603,8 @@ 'wis' 'wildsort' 'wildsort' 'wis' - regexplist - .* + &option.wildsort.type; + &option.wildsort.default;

A list of regular expressions defining which completion contexts @@ -1620,8 +1621,8 @@ 'wsp' 'wordseparators' 'wordseparators' 'wsp' - string - #*+|=~ _-]]]> + &option.wordseparators.type; + &option.wordseparators.default;

A regular expression which defines how words are split for diff --git a/common/modules/config.jsm b/common/modules/config.jsm index 014cb989..496ab38d 100644 --- a/common/modules/config.jsm +++ b/common/modules/config.jsm @@ -27,12 +27,7 @@ var ConfigBase = Class("ConfigBase", { set.add(this.features, "Gecko2"); this.timeout(function () { - services["dactyl:"].pages.dtd = function () [null, - iter(config.dtdExtra, - (["dactyl." + k, v] for ([k, v] in iter(config.dtd))), - (["dactyl." + s, config[s]] for each (s in config.dtdStrings))) - .map(function ([k, v]) [""].join("")) - .join("\n")] + services["dactyl:"].pages.dtd = function () [null, util.makeDTD(config.dtd)]; }); }, @@ -168,9 +163,15 @@ var ConfigBase = Class("ConfigBase", { return version; }), - get fileExt() this.name.slice(0, -5), + get fileExt() this.name.slice(0, -6), - dtd: memoize({ + dtd: Class.memoize(function () + iter(this.dtdExtra, + (["dactyl." + k, v] for ([k, v] in iter(config.dtdDactyl))), + (["dactyl." + s, config[s]] for each (s in config.dtdStrings))) + .toObject()), + + dtdDactyl: memoize({ get name() config.name, get home() "http://dactyl.sourceforge.net/", get apphome() this.home + this.name, diff --git a/common/modules/messages.jsm b/common/modules/messages.jsm index c8b20c8b..a25cce72 100644 --- a/common/modules/messages.jsm +++ b/common/modules/messages.jsm @@ -67,7 +67,7 @@ var Messages = Module("messages", { catch (e) {} // Report error so tests fail, but don't throw - if (arguments.length < 2) + if (arguments.length < 2) // Do *not* localize these strings util.reportError(Error("Invalid locale string: " + value)); return arguments.length > 1 ? default_ : value; }, @@ -80,7 +80,7 @@ var Messages = Module("messages", { catch (e) {} // Report error so tests fail, but don't throw - if (arguments.length < 3) + if (arguments.length < 3) // Do *not* localize these strings util.reportError(Error("Invalid locale string: " + value)); return arguments.length > 2 ? default_ : value; } diff --git a/common/modules/options.jsm b/common/modules/options.jsm index cc9303b7..2a45f8e6 100644 --- a/common/modules/options.jsm +++ b/common/modules/options.jsm @@ -748,6 +748,18 @@ var Options = Module("options", { if (event == "change" && opt) opt.set(opt.globalValue, Option.SCOPE_GLOBAL, true); }, window); + + services["dactyl:"].pages["options.dtd"] = function () [null, + util.makeDTD( + iter(([["option", o.name, "default"].join("."), + o.type === "string" ? o.value.replace(/'/g, "''") : + o.value === true ? "on" : + o.value === false ? "off" : o.stringDefaultValue] + for (o in self)), + + ([["option", o.name, "type"].join("."), o.type] for (o in self)), + + config.dtd))]; }, dactyl: dactyl, diff --git a/common/modules/prefs.jsm b/common/modules/prefs.jsm index 981a6beb..c1221bbd 100644 --- a/common/modules/prefs.jsm +++ b/common/modules/prefs.jsm @@ -171,7 +171,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) let saved = this.get(this.SAVED + name); if (saved == null && curval != defval || saved != null && curval != saved) { - let msg = "Warning: setting preference " + name + ", but it's changed from its default value."; + let msg = _("pref.safeSet.warnChanged", name); if (message) msg = template.linkifyHelp(msg + " " + message); util.dactyl.warn(msg); diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 35476bf5..a61eddaa 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -974,6 +974,12 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), .map(function (node) "//" + node).join(" | "); }, + makeDTD: function makeDTD(obj) unescape(encodeURI(iter(obj) + .map(function ([k, v]) ["'].join("")) + .join("\n"))), + map: deprecated("iter.map", function map(obj, fn, self) iter(obj).map(fn, self).toArray()), writeToClipboard: deprecated("dactyl.clipboardWrite", function writeToClipboard(str, verbose) util.dactyl.clipboardWrite(str, verbose)), readFromClipboard: deprecated("dactyl.clipboardRead", function readFromClipboard() util.dactyl.clipboardRead(false)),