diff --git a/chrome/content/vimperator/bookmarks.js b/chrome/content/vimperator/bookmarks.js index a14dff7d..21d80383 100644 --- a/chrome/content/vimperator/bookmarks.js +++ b/chrome/content/vimperator/bookmarks.js @@ -86,7 +86,7 @@ function Bookmarks() var bookmarks = null; var keywords = null; - if(get_pref("preload")) + if(vimperator.options["preload"]) setTimeout(function() { load(); } , 100); function load() @@ -230,7 +230,7 @@ function Bookmarks() { var url = null; if(!engine_name || engine_name == "") - engine_name = get_pref("defsearch", "google"); + engine_name = vimperator.options["defsearch"]; // first checks the search engines for a match var engine = search_service.getEngineByAlias(engine_name); @@ -273,7 +273,7 @@ function History() var history = null; - if(get_pref("preload")) + if(vimperator.options["preload"]) setTimeout(function() { load(); } , 100); function load() diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js index 28d49fc0..7e298012 100644 --- a/chrome/content/vimperator/commands.js +++ b/chrome/content/vimperator/commands.js @@ -1390,7 +1390,7 @@ function copyToClipboard(str) function beep() { - if (get_pref("beep") == false) + if (!vimperator.options["beep"]) return; var gBeepService = Components.classes['@mozilla.org/sound;1'] @@ -1406,9 +1406,9 @@ function beep() function quit(save_session) { if (save_session) - set_firefox_pref("browser.startup.page", 3); // start with saved session + Options.setFirefoxPref("browser.startup.page", 3); // start with saved session else - set_firefox_pref("browser.startup.page", 1); // start with default homepage session + Options.setFirefoxPref("browser.startup.page", 1); // start with default homepage session goQuitApplication(); } @@ -1507,7 +1507,7 @@ function set(args, special) var no = true; if (matches[1] === undefined) no = false; var opt = matches[2]; - var option = get_option(opt); + var option = vimperator.options.get(opt); if (!option) { vimperator.echoerr("E518: Unknown option: " + opt); @@ -1515,7 +1515,7 @@ function set(args, special) } var get = false; if (matches[3] == "?" || - (option[TYPE] != 'boolean' && matches[4] === undefined)) get = true; + (option.type != 'boolean' && matches[4] === undefined)) get = true; var reset = false; if (matches[3] == "&") reset = true; var oper = matches[5]; var val = matches[6]; if (val === undefined) val = ""; @@ -1523,42 +1523,42 @@ function set(args, special) // reset a variable to its default value. if (reset) { - var def = option[DEFAULT]; - option[SETFUNC].call(this, def); + option.value = option.default_value; } // read access else if (get) { - var cur_val = option[GETFUNC].call(this); - vimperator.echo(" " + option[COMMANDS][0] + "=" + cur_val); + vimperator.echo(" " + option.name + "=" + option.value); + //vimperator.echo(" " + option.name + "=" + vimperator.options[option.name]); } // write access else { - var type = option[TYPE]; + var type = option.type; if (type == "boolean") { - option[SETFUNC].call(this, !no); + option.value = !no; } else if (type == "number") { var num = parseInt(val, 10); if (isNaN(num)) - vimperator.echoerr("Invalid argument type to option " + option[COMMANDS][0] + ": Expects number"); + vimperator.echoerr("Invalid argument type to option " + option.name + ": Expects number"); else { - var cur_val = option[GETFUNC].call(this); + var cur_val = option.value; if (oper == '+') num = cur_val + num; if (oper == '-') num = cur_val - num; - if (option[CHECKFUNC] != null && option[CHECKFUNC].call(this, num) == false) - vimperator.echoerr("Invalid argument to option " + option[COMMANDS][0] + ": Check help for more details"); + // FIXME + if (option.validator != null && option.validator.call(this, num) == false) + vimperator.echoerr("Invalid argument to option " + option.name + ": Check help for more details"); else // all checks passed, execute option handler - option[SETFUNC].call(this, num); + option.value = num; } } else if (type == "charlist" || type == "stringlist" || type == "string") { - var cur_val = option[GETFUNC].call(this); + var cur_val = option.value; if (type == "charlist" || type == "string") { if (oper == '+' && !cur_val.match(val)) @@ -1575,10 +1575,11 @@ function set(args, special) val = val.replace(/^,?/, ''); } } - if (option[CHECKFUNC] != null && option[CHECKFUNC].call(this, val) == false) - vimperator.echoerr("Invalid argument to option " + option[COMMANDS][0] + ": Check help for more details"); + // FIXME + if (option.validator != null && option.validator.call(this, val) == false) + vimperator.echoerr("Invalid argument to option " + option.name + ": Check help for more details"); else // all checks passed, execute option handler - option[SETFUNC].call(this, val); + option.value = val; } else vimperator.echoerr("Internal error, option format `" + type + "' not supported"); @@ -1689,105 +1690,105 @@ function evaluateXPath(expression, doc, ordered) -// list all installed themes and extensions -function outputAddonsList(aTarget) -{ - var RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"] - .getService(Components.interfaces.nsIRDFService); - var Container = Components.classes["@mozilla.org/rdf/container;1"] - .getService(Components.interfaces.nsIRDFContainer); - var stream = Components.classes['@mozilla.org/network/file-output-stream;1'] - .createInstance(Components.interfaces.nsIFileOutputStream); - var fp = Components.classes["@mozilla.org/filepicker;1"] - .createInstance(Components.interfaces.nsIFilePicker); +//// list all installed themes and extensions +//function outputAddonsList(aTarget) +//{ +// var RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"] +// .getService(Components.interfaces.nsIRDFService); +// var Container = Components.classes["@mozilla.org/rdf/container;1"] +// .getService(Components.interfaces.nsIRDFContainer); +// var stream = Components.classes['@mozilla.org/network/file-output-stream;1'] +// .createInstance(Components.interfaces.nsIFileOutputStream); +// var fp = Components.classes["@mozilla.org/filepicker;1"] +// .createInstance(Components.interfaces.nsIFilePicker); +// +// fp.init(window, aTarget+'s List', fp.modeSave); +// fp.defaultString=aTarget+"sList.txt"; +// fp.appendFilters(fp.filterText); +// fp.appendFilters(fp.filterAll); +// if (fp.show() == fp.returnCancel) +// return; +// +// var extensionDS= Components.classes["@mozilla.org/extensions/manager;1"] +// .getService(Components.interfaces.nsIExtensionManager).datasource; +// var root = RDFService +// .GetResource("urn:mozilla:"+aTarget.toLowerCase()+":root"); +// var nameArc = RDFService +// .GetResource("http://www.mozilla.org/2004/em-rdf#name"); +// var versionArc = RDFService +// .GetResource("http://www.mozilla.org/2004/em-rdf#version"); +// var disabledArc = RDFService +// .GetResource("http://www.mozilla.org/2004/em-rdf#disabled"); +// +// var list=""; +// var disabledlist=""; +// +// Container.Init(extensionDS,root); +// var elements=Container.GetElements(); +// +// while(elements.hasMoreElements()) +// { +// var element=elements.getNext(); +// var name=""; +// var version=""; +// var disabled=""; +// element.QueryInterface(Components.interfaces.nsIRDFResource); +// var target=extensionDS.GetTarget(element, nameArc ,true); +// if(target) +// name=target +// .QueryInterface(Components.interfaces.nsIRDFLiteral).Value; +// target=extensionDS.GetTarget(element, versionArc ,true); +// if(target) +// version=target +// .QueryInterface(Components.interfaces.nsIRDFLiteral).Value; +// target=extensionDS.GetTarget(element, disabledArc ,true); +// if(target) +// disabled=target +// .QueryInterface(Components.interfaces.nsIRDFLiteral).Value; +// if( disabled && disabled=="true") +// disabledlist += name + " " + version +"\n"; +// else if(name) +// list += name + " " + version +"\n" +// } +// +// if(disabledlist) +// list += "\n#Disabled Extensions\n" + disabledlist; +// +// stream.init(fp.file, 0x20|0x02|0x08, 0666, 0); +// stream.write(list, list.length); +// stream.close(); +//} - fp.init(window, aTarget+'s List', fp.modeSave); - fp.defaultString=aTarget+"sList.txt"; - fp.appendFilters(fp.filterText); - fp.appendFilters(fp.filterAll); - if (fp.show() == fp.returnCancel) - return; +///* selects the first input box */ +//function selectInput() +//{ +//// if (! (ev.charCode == 47 /* ord('/') */ && ev.ctrlKey)) +//// return; +// +// var texts = evaluateXPath("//input[@type='text']"); +// +// texts.snapshotItem(0).focus(); +//} - var extensionDS= Components.classes["@mozilla.org/extensions/manager;1"] - .getService(Components.interfaces.nsIExtensionManager).datasource; - var root = RDFService - .GetResource("urn:mozilla:"+aTarget.toLowerCase()+":root"); - var nameArc = RDFService - .GetResource("http://www.mozilla.org/2004/em-rdf#name"); - var versionArc = RDFService - .GetResource("http://www.mozilla.org/2004/em-rdf#version"); - var disabledArc = RDFService - .GetResource("http://www.mozilla.org/2004/em-rdf#disabled"); - - var list=""; - var disabledlist=""; - - Container.Init(extensionDS,root); - var elements=Container.GetElements(); - - while(elements.hasMoreElements()) - { - var element=elements.getNext(); - var name=""; - var version=""; - var disabled=""; - element.QueryInterface(Components.interfaces.nsIRDFResource); - var target=extensionDS.GetTarget(element, nameArc ,true); - if(target) - name=target - .QueryInterface(Components.interfaces.nsIRDFLiteral).Value; - target=extensionDS.GetTarget(element, versionArc ,true); - if(target) - version=target - .QueryInterface(Components.interfaces.nsIRDFLiteral).Value; - target=extensionDS.GetTarget(element, disabledArc ,true); - if(target) - disabled=target - .QueryInterface(Components.interfaces.nsIRDFLiteral).Value; - if( disabled && disabled=="true") - disabledlist += name + " " + version +"\n"; - else if(name) - list += name + " " + version +"\n" - } - - if(disabledlist) - list += "\n#Disabled Extensions\n" + disabledlist; - - stream.init(fp.file, 0x20|0x02|0x08, 0666, 0); - stream.write(list, list.length); - stream.close(); -} - -/* selects the first input box */ -function selectInput() -{ -// if (! (ev.charCode == 47 /* ord('/') */ && ev.ctrlKey)) -// return; - - var texts = evaluateXPath("//input[@type='text']"); - - texts.snapshotItem(0).focus(); -} - -function toggle_images() { - if (!gPrefService) { - message("EEP: no gPrefService"); - return 0; - } - - - var pref; - if (!gPrefService.prefHasUserValue("network.image.imageBehavior")) { - pref = 0; - } else { - pref = gPrefService.getIntPref("network.image.imageBehavior"); - } - - - set_pref("network.image.imageBehavior", pref ? 0 : 2); - pref = gPrefService.getIntPref("network.image.imageBehavior"); -// redraw(); - message ("imageBehavior set to " + pref); -} +//function toggle_images() { +// if (!gPrefService) { +// message("EEP: no gPrefService"); +// return 0; +// } +// +// +// var pref; +// if (!gPrefService.prefHasUserValue("network.image.imageBehavior")) { +// pref = 0; +// } else { +// pref = gPrefService.getIntPref("network.image.imageBehavior"); +// } +// +// +// set_pref("network.image.imageBehavior", pref ? 0 : 2); +// pref = gPrefService.getIntPref("network.image.imageBehavior"); +//// redraw(); +// message ("imageBehavior set to " + pref); +//} // vim: set fdm=marker sw=4 ts=4 et: diff --git a/chrome/content/vimperator/completion.js b/chrome/content/vimperator/completion.js index 1e0ac2be..768f05cb 100644 --- a/chrome/content/vimperator/completion.js +++ b/chrome/content/vimperator/completion.js @@ -109,7 +109,7 @@ function get_url_completions(filter, complete)/*{{{*/ var completions = new Array(); g_substrings = []; - var cpt = complete || get_pref("complete"); + var cpt = complete || vimperator.options["complete"]; // join all completion arrays together for (var i = 0; i < cpt.length; i++) { @@ -273,7 +273,7 @@ function get_help_completions(filter)/*{{{*/ ]; })); for (var map in vimperator.mappings) - help_array.push([map.commands, map.short_help]) + help_array.push([map.names, map.short_help]) if (!filter) return help_array.map(function($_) { return [$_[COMMANDS][0], $_[1]]; // unfiltered, use the first command @@ -309,34 +309,42 @@ function get_options_completions(filter, unfiltered)/*{{{*/ no_mode = true; filter = filter.substr(2); } - if (unfiltered) return g_options.filter(function($_) { - if (no_mode && $_[TYPE] != "boolean") return false; - else return true; - }).map(function($_) { - return [$_[COMMANDS], $_[SHORTHELP]]; - }); - if (!filter) return g_options.filter(function($_) { - if (no_mode && $_[TYPE] != "boolean") return false; - else return true; - }).map(function($_) { - var prefix = no_mode ? 'no' : ''; - return [prefix + $_[COMMANDS][0], $_[SHORTHELP]]; - }); + if (unfiltered) + { + var options = []; + for (var option in vimperator.options) + { + if (no_mode && option.type != "boolean") + continue; + options.push([option.names, option.short_help]) + } + return options; + } + + if (!filter) + { + var options = []; + for (var option in vimperator.options) + { + if (no_mode && option.type != "boolean") + continue; + var prefix = no_mode ? 'no' : ''; + options.push([prefix + option.name, option.short_help]) + } + return options; + } // check if filter ends with =, then complete current value else if(filter.length > 0 && filter.lastIndexOf("=") == filter.length -1) { filter = filter.substr(0, filter.length-1); - for(var i=0; i //usage = usage.replace(/<([^b][^r].*>)/g, "<$1"); @@ -71,19 +71,19 @@ function help(section, easter) ret += ''; // the actual help text with the first line in bold - if (commands[i][SHORTHELP]) + if (command.short_help) { ret += ''; - ret += commands[i][SHORTHELP]; // the help description + ret += command.short_help; // the help description ret += "
"; if(func) // for options we print default values here, e.g. { - ret += func.call(this, commands[i]); + ret += func.call(this, command); ret += "
"; } - if (commands[i][HELP]) + if (command.help) { - ret += commands[i][HELP]; // the help description + ret += command.help; // the help description ret += "
"; } } @@ -91,7 +91,7 @@ function help(section, easter) ret += "Sorry, no help available"; // the tags which are printed on the top right ret += ''; - var names = commands[i][COMMANDS]; + var names = command.names; for (var j=0; j < names.length; j++) { var cmd_name = names[j]; @@ -100,12 +100,12 @@ function help(section, easter) // cmd_name = cmd_name.replace(/"/g, """); // cmd_name = cmd_name.replace(/'/g, "'"); // cmd_name = cmd_name.replace(/&/g, "&"); - ret += '' +beg+ cmd_name +end+ '
'; + ret += '' + beg + cmd_name + end + '
'; } ret += ''; // add more space between entries - if (i < commands.length-1) + // FIXME: if (i < commands.length-1) ret += '
\n'; } return ret; @@ -113,20 +113,20 @@ function help(section, easter) function makeOptionsHelpString(command) { var ret = ""; - ret = command[TYPE] + ' (default: '; - if (command[TYPE] == "boolean") + ret = command.type + ' (default: '; + if (command.type == "boolean") { - if(command[DEFAULT] == true) + if(command.default_value == true) ret += "on"; else ret += "off"; } else { - if (typeof command[DEFAULT] == 'string' && command[DEFAULT].length == 0) + if (typeof command.default_value == 'string' && command.default_value.length == 0) ret += "''"; else - ret += command[DEFAULT]; + ret += command.default_value; } ret += ")
"; @@ -165,20 +165,14 @@ function help(section, easter) '

The denotion of modifier keys is like in Vim, so C- means the Control key, M- the Meta key, A- the Alt key and S- the Shift key.

'+ '' // FIXME: fix this when Command() is added and help patch is merged -- djk - var all_maps = []; - for (var map in vimperator.mappings) - all_maps.push([map.commands, [map.usage], map.short_help, map.help]) - mappings += makeHelpString(all_maps, "", "", null); + mappings += makeHelpString(vimperator.mappings, "", "", null); mappings += '
'; if (section && section == 'holy-grail') mappings += 'You found it, Arthur!\n'; var commands = 'commands

Commands

\n' + '\n'; - var all_commands = []; - for (var command in vimperator.commands) - all_commands.push([command.names, command.usage, command.short_help, command.help]); - commands += makeHelpString(all_commands, ":", "", null); + commands += makeHelpString(vimperator.commands, ":", "", null); commands += '
'; if (section && section == '42') commands += '

What is the meaning of life, the universe and everything?
' + @@ -188,7 +182,7 @@ function help(section, easter) var options = 'options

Options

\n' + '\n'; - options += makeHelpString(g_options, "'", "'", makeOptionsHelpString); + options += makeHelpString(vimperator.options, "'", "'", makeOptionsHelpString); options += '
'; var fulldoc = '\n' + diff --git a/chrome/content/vimperator/hints.js b/chrome/content/vimperator/hints.js index bcbc15ab..87c32e42 100644 --- a/chrome/content/vimperator/hints.js +++ b/chrome/content/vimperator/hints.js @@ -78,7 +78,7 @@ function hit_a_hint() wins.push(win); } // logMessage("winId:"+win.winId); - win.res = evaluateXPath(get_pref("hinttags"), doc); + win.res = evaluateXPath(vimperator.options["hinttags"], doc); win.coordLoaderId = window.setTimeout("hah.loadCoord(" + win.winId + ", 0);", 1); } @@ -135,12 +135,12 @@ function hit_a_hint() area[3] = area[1] + win.innerHeight; var doc = win.document; - var res = evaluateXPath(get_pref("hinttags"), doc); + var res = evaluateXPath(vimperator.options["hinttags"], doc); var elem, i; hintElemSpan = doc.createElement('SPAN'); - hintElemSpan.style.cssText = get_pref("hintstyle"); + hintElemSpan.style.cssText = vimperator.options["hintstyle"]; hintElemSpan.setAttribute('name', 'hah_hint'); var hintContainer = doc.getElementById('hah_hints'); @@ -153,7 +153,7 @@ function hit_a_hint() hintContainer.valid_hint_count = 0; // none of these hints should be visible initially var hints = hintContainer.childNodes; - var maxhints = get_pref("maxhints"); + var maxhints = vimperator.options["maxhints"]; for (i = 0; i < res.snapshotLength; i++) { // this saves from script timeouts on pages with some thousand links @@ -261,7 +261,7 @@ function hit_a_hint() for (i = 0; i < res.snapshotLength; i++) { elem = res.snapshotItem(i); - setHintStyle(elem, get_pref("hintstyle")); + setHintStyle(elem, vimperator.options["hintstyle"]); elem.style.display = 'none'; } @@ -328,7 +328,7 @@ function hit_a_hint() function formatHint(hintNum) { - var hintCharacters = get_pref("hintchars"); + var hintCharacters = vimperator.options["hintchars"]; var str = hintNum.toString(hintCharacters.length); // turn hintNum into a base(length) number // map the number onto the chars in the numbers string @@ -364,8 +364,8 @@ function hit_a_hint() function changeHintFocus(linkNumString, oldLinkNumString) { - var styleString = get_pref("hintstyle"); - var styleStringFocus = get_pref("focusedhintstyle"); + var styleString = vimperator.options["hintstyle"]; + var styleStringFocus = vimperator.options["focusedhintstyle"]; var hintElem; if (oldLinkNumString.length > 0) @@ -432,7 +432,7 @@ function hit_a_hint() //hintmode = HINT_MODE_QUICK; linkNumString = ''; hintedElems = []; -// if (!silent && get_pref("showmode")) +// if (!silent && vimperator.options["showmode"]) // vimperator.echo(''); removeHints(win); @@ -450,7 +450,7 @@ function hit_a_hint() if (!elem) return 0; // reset style attribute - setHintStyle(elem, get_pref("hintstyle")); + setHintStyle(elem, vimperator.options["hintstyle"]); } }; @@ -480,7 +480,7 @@ function hit_a_hint() if (!elem) return 0; - setHintStyle(elem, get_pref("hintstyle")); + setHintStyle(elem, vimperator.options["hintstyle"]); elem = elem.refElem; var elemTagName = elem.tagName; elem.focus(); @@ -601,7 +601,7 @@ function hit_a_hint() state = 0; var num = String.fromCharCode(event.charCode).toUpperCase(); - var hintCharacters = get_pref("hintchars"); + var hintCharacters = vimperator.options["hintchars"]; if (num != null && hintCharacters.toUpperCase().indexOf(num) > -1) { var oldLinkNumString = linkNumString; diff --git a/chrome/content/vimperator/mappings.js b/chrome/content/vimperator/mappings.js index 8ba2aa5a..b92d0674 100644 --- a/chrome/content/vimperator/mappings.js +++ b/chrome/content/vimperator/mappings.js @@ -5,7 +5,7 @@ function Map(mode, cmds, act, extra_info) //{{{ return null; this.mode = mode; - this.commands = cmds; + this.names = cmds; this.action = act; if (extra_info) @@ -19,9 +19,10 @@ function Map(mode, cmds, act, extra_info) //{{{ this.usage = ""; if (this.flags & Mappings.flags.COUNT) this.usage = "{count}"; - this.usage += this.commands[0]; // only the first command name + this.usage += this.names[0]; // only the first command name if (this.flags & Mappings.flags.ARGUMENT) this.usage += " {arg}"; + this.usage = [this.usage]; // FIXME: usage an array - needed for the help } this.help = extra_info.help || null; @@ -48,7 +49,7 @@ Map.prototype.toString = function() // FIXME: -- djk return "Map {" + "\n\tmode: " + this.mode + - "\n\tcommands: " + this.commands + + "\n\tnames: " + this.names + "\n\taction: " + this.action + "\n\tusage: " + this.usage + "\n\tshort_help: " + this.short_help + @@ -68,7 +69,6 @@ function Mappings()//{{{ { if (!main[map.mode]) main[map.mode] = []; - main[map.mode].push(map); } @@ -81,8 +81,8 @@ function Mappings()//{{{ var stack_length = substack.length; for (var i = 0; i < stack_length; i++) { - for (var j = 0; j < substack[i].commands.length; j++) - if (substack[i].commands[j] == cmd) + for (var j = 0; j < substack[i].names.length; j++) + if (substack[i].names[j] == cmd) return substack[i]; } } @@ -167,9 +167,9 @@ function Mappings()//{{{ for (var i = 0; i < main[mode].length; i++) // FIXME: just the main/default map space for now -- djk { var map = main[mode][i]; - for (var j = 0; j < map.commands.length; j++) + for (var j = 0; j < map.names.length; j++) { - if (map.commands[j].indexOf(cmd) == 0) + if (map.names[j].indexOf(cmd) == 0) matching.push(map) } } @@ -187,7 +187,7 @@ function Mappings()//{{{ function (mark) { vimperator.marks.jumpTo(mark) }, { short_help: "Jump to the mark in the current buffer", - usage: "'{a-zA-Z0-9}", + usage: ["'{a-zA-Z0-9}"], help: "Marks a-z are local to the buffer, whereas A-Z and 0-9 are valid between buffers.", flags: Mappings.flags.ARGUMENT } @@ -271,7 +271,7 @@ function Mappings()//{{{ function(mark) { vimperator.marks.add(mark) }, { short_help: "Set mark at the cursor position", - usage: "m{a-zA-Z0-9}", + usage: ["m{a-zA-Z0-9}"], help: "Marks a-z are local to the buffer, whereas A-Z and 0-9 are valid between buffers.", flags: Mappings.flags.ARGUMENT } diff --git a/chrome/content/vimperator/options.js b/chrome/content/vimperator/options.js index 76620e54..c2fb9f5a 100644 --- a/chrome/content/vimperator/options.js +++ b/chrome/content/vimperator/options.js @@ -1,534 +1,483 @@ -// options.js -// -// handles all persistent storage of information -// to and from the firefox registry - -const TYPE = 4; -const SETFUNC = 6; -const GETFUNC = 7; -const DEFAULT = 8; -const CHECKFUNC = 9; - - -// the global handle to the root of the firefox options -var g_firefox_prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); -var g_vimperator_prefs = null; - -// non persistent options -var opt_usermode = false; -var opt_fullscreen = false; - -/* all user-setable vimperator options - * format: - * [ - * 0: [all names of this option], - * 1: usage, - * 2: shorthelp - * 3: help text, - * 4: type, - * 5: completefunc - * 6: set_function, - * 7: get_function, - * 8: default, - * 9: checkfunc, - * ] - */ -var g_options = [/*{{{*/ - [ - ["activate"], - ["activate"], - "Define when tabs are automatically activated", - "Not implemented yet", - "stringlist", - null, - function(value) { set_pref("activate", value); }, - function() { return get_pref("activate"); }, - "quickmark,tabopen,paste", - null - ], - [ - ["beep", "nobeep"], - ["beep"], - "Emit a pc speaker beep on certain errors", - null, - "boolean", - null, - function(value) { set_pref("beep", value); }, - function() { return get_pref("beep"); }, - true, - null - ], - [ - ["complete", "cpt"], - ["complete", "cpt"], - "Items which are completed at the :[tab]open prompt", - "Available items:
" + - "The order is important, so :set complete=bs would list bookmarks first, and then any available quick searches.
"+ - "Add 'sort' to the 'wildoptions' option if you want all entries sorted.", - "charlist", - null, - function(value) { set_pref("complete", value); }, - function() { return get_pref("complete"); }, - "sfbh", - null - ], - [ - ["defsearch", "ds"], - ["defsearch", "ds"], - "Set the default search engine", - "The default search engine is used in the :[tab]open [arg] command "+ - "if [arg] neither looks like a URL or like a specified search engine/keyword.", - "string", - function() { return [["foo", "bar"], ["shit", "blub"]]; }, - function(value) { set_pref("defsearch", value); }, - function() { return get_pref("defsearch", "google"); }, - "google", - null - ], - [ - ["extendedhinttags", "eht"], - ["extendedhinttags", "eht"], - "XPath string of hintable elements activated by ';'", - null, - "string", - null, - function(value) { set_pref("extendedhinttags", value); }, - function() { return get_pref("extendedhinttags"); }, - "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | //input[@type!='hidden' or not(boolean(@type))] | //a | //area | //iframe | //textarea | //button | //select | "+ - "//xhtml:*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | //xhtml:input[@type!='hidden' or not(boolean(@type))] | //xhtml:a | //xhtml:area | //xhtml:iframe | //xhtml:textarea | //xhtml:button | //xhtml:select", - null - ], - [ - ["focusedhintstyle", "fhs"], - ["focusedhintstyle", "fhs"], - "CSS specification of focused hints appearance", - null, - "string", - null, - function(value) { set_pref("focusedhintstyle", value); }, - function() { return get_pref("focusedhintstyle"); }, - "z-index:5000; font-family:monospace; font-size:12px; color:ButtonText; background-color:ButtonShadow; border-color:ButtonShadow; border-width:1px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;", - null - ], - [ - ["fullscreen", "fs", "nofullscreen", "nofs"], - ["fullscreen", "fs"], - "Shows the current window fullscreen", - null, - "boolean", - null, - function(value) { opt_fullscreen = value; BrowserFullScreen(); }, - function() { return opt_fullscreen; }, - false, - null - ], - [ - ["guioptions", "go"], - ["guioptions", "go"], - "Shows or hides the menu, toolbar and scrollbars", - "Supported characters:
", - "charlist", - null, - function(value) { set_pref("guioptions", value); set_guioptions(value); }, - function() { return get_pref("guioptions"); }, - "", - null - ], - [ - ["hintchars", "hc"], - ["hintchars", "hc"], - "String of single characters which can be used to follow hints", - null, - "charlist", - null, - function(value) { set_pref("hintchars", value); }, - function() { return get_pref("hintchars"); }, - "hjklasdfgyuiopqwertnmzxcvb", - null - ], - [ - ["hintstyle", "hs"], - ["hintstyle", "hs"], - "CSS specification of unfocused hints appearance", - null, - "string", - null, - function(value) { set_pref("hintstyle", value); }, - function() { return get_pref("hintstyle"); }, - "z-index:5000; font-family:monospace; font-size:12px; color:black; background-color:yellow; border-color:ButtonShadow; border-width:0px; border-style:solid; padding:0px 1px 0px 1px; position:absolute; ", - null - ], - [ - ["hinttags"], - ["hinttags"], - "XPath string of hintable elements activated by 'f' and 'F'", - null, - "string", - null, - function(value) { set_pref("hinttags", value); }, - function() { return get_pref("hinttags"); }, - "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | //input[@type!='hidden'] | //a | //area | //iframe | //textarea | //button | //select | "+ - "//xhtml:*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | //xhtml:input[@type!='hidden'] | //xhtml:a | //xhtml:area | //xhtml:iframe | //xhtml:textarea | //xhtml:button | //xhtml:select", - null - ], - [ - ["maxhints", "mh"], - ["maxhints", "mh"], - "Maximum number of simultanously shown hints", - "If you want to speed up display of hints, choose a smaller value", - "number", - null, - function(value) { set_pref("maxhints", value); }, - function() { return get_pref("maxhints"); }, - 250, - function (value) { if (value>=1 && value <=1000) return true; else return false; } - ], - [ - ["preload", "nopreload"], - ["preload"], - "Speed up first time history/bookmark completion", - "History access can be quite slow for a large history. Vimperator maintains a cache to speed it up significantly on subsequent access.
"+ - "In order to also speed up first time access, it is cached at startup, if this option is set (recommended).", - "boolean", - null, - function(value) { set_pref("preload", value); }, - function() { return get_pref("preload"); }, - true, - null - ], - [ - ["previewheight", "pvh"], - ["previewheight", "pvh"], - "Default height for preview window", - "Value must be between 1 and 50. If the value is too high, completions may cover the command-line. "+ - "Close the preview window with :pclose.", - "number", - null, - function(value) { set_pref("previewheight", value); }, - function() { return get_pref("previewheight"); }, - 10, - function (value) { if (value>=1 && value <=50) return true; else return false; } - ], - [ - ["showmode", "smd", "noshowmode", "nosmd"], - ["showmode", "smd"], - "Show the current mode in the command line", - null, - "boolean", - null, - function(value) { set_pref("showmode", value); }, - function() { return get_pref("showmode"); }, - true, - null - ], - [ - ["showstatuslinks", "ssli"], - ["showstatuslinks", "ssli"], - "Show the destination of the link under the cursor in the status bar", - "Also links which are focused by keyboard commands like <Tab> are shown. "+ - "Possible values:
", - "number", - null, - function(value) { set_pref("showstatuslinks", value); }, - function() { return get_pref("showstatuslinks"); }, - 1, - null - ], - [ - ["showtabline", "stal"], - ["showtabline", "stal"], - "Control when to show the tab bar of opened web pages", - "Possible values:
"+ - "Not implemented yet.", - "number", - null, - function(value) { set_pref("showtabline", value); set_showtabline(value); }, - function() { return get_pref("showtabline"); }, - 2, - function (value) { if (value>=0 && value <=2) return true; else return false; } - ], - [ - ["titlestring"], - ["titlestring"], - "Change the title of the browser window", - "Vimperator changes the browser title from \"Title of webpage - Mozilla Firefox\" to "+ - "\"Title of webpage - Vimperator\".
If you don't like that, you can restore it with: "+ - ":set titlestring=Mozilla Firefox.", - "string", - null, - function(value) { set_pref("titlestring", value); set_titlestring(value); }, - function() { return get_pref("titlestring"); }, - "Vimperator", - null - ], - [ - ["usermode", "um", "nousermode", "noum"], - ["usermode", "um"], - "Show current website with a minimal style sheet to make it easily accessible", - "Note that this is a local option for now, later it may be split into a global and :setlocal part", - "boolean", - null, - function(value) { opt_usermode = value; setStyleDisabled(value); }, - function() { return opt_usermode; }, - false, - null - ], - [ - ["wildmode", "wim"], - ["wildmode", "wim"], - "Define how command line completion works", - "It is a comma-separated list of parts, where each part specifies " + - "what to do for each consecutive use of the completion key. The first part " + - "specifies the behavior for the first use of the completion key, the second part " + - "for the second use, etc.
" + - "These are the possible values for each part:
" + - ""+ - "" + - "" + - "" + - "" + - "" + - "" + - "
''Complete only the first match
'full'Complete the next full match. After the last, the original string is used.
'longest'Complete till the longest common string.
'list'When more than one match, list all matches.
'list:full'When more than one match, list all matches and complete first match.
'list:longest'When more than one match, list all matches and complete till the longest common string.
" + - "When there is only a single match, it is fully completed regardless of the case.", - "stringlist", - null, - function(value) { set_pref("wildmode", value); }, - function() { return get_pref("wildmode"); }, - "list:full", - null - ], - [ - ["wildoptions", "wop"], - ["wildoptions", "wop"], - "Change how command line completion is done", - "A list of words that change how command line completion is done.
"+ - "Currently only one word is allowed:
"+ - ""+ - "" + - "
sortAlways sorts completion list, overriding the 'complete' option.
", - "stringlist", - null, - function(value) { set_pref("wildoptions", value); }, - function() { return get_pref("wildoptions"); }, - "", - null - ] - - // TODO: make more performant and then enable - /*,[ - ["numbertabs", "nt"], - ["numbertabs", "nt"], - "Turns tab numbering on or off", - "If you want to see a number on each tab turn this on", - "boolean", - null, - function(value) { set_pref("numbertabs", value); set_tabnumbers(value); }, - function() { return get_pref("numbertabs"); }, - false, - null - ], - - function set_tabnumbers(value) - { - if(value==false) - vimperator.tabs.updateTitles(true); - vimperator.tabs.updateTitles(false); - } -*/ - -]/*}}}*/ - -// return null, if the cmd cannot be found in our g_options array, or -// otherwise a refernce to our command -function get_option(cmd)/*{{{*/ +function Option(names, type, extra_info)//{{{ { - for (var i=0; i < g_options.length; i++) + if (!names || !type) + return null; + + this.name = names[0]; + this.names = names; + this.type = type; + + // add noOPTION variant of boolean OPTION to this.names + if (this.type == "boolean") { - for (var j=0; j < g_options[i][COMMANDS].length; j++) + this.names = []; + for (var i = 0; i < names.length; i++) { - if (g_options[i][COMMANDS][j] == cmd) - { - return g_options[i]; - } + this.names.push(names[i]); + this.names.push("no" + names[i]); } } - return null; -}/*}}}*/ -///////////////////////////////////////////////// -// preference getter functions ///////////// {{{1 -///////////////////////////////////////////////// -Vimperator.prototype.getpr = function(name){ - //alert('in here'); - if (!g_vimperator_prefs) - g_vimperator_prefs = g_firefox_prefs.getBranch("extensions.vimperator."); - try{ - pref = g_vimperator_prefs.getCharPref(name); - } catch(e) { pref = "no idea"; } - return pref; -} -// does not work: -vimperator.getpref2 = function(name){ - pref = g_vimperator_prefs.getCharPref(name); - return pref; -} + this.setter = function(value) { Options.setPref(this.name, value); }; + this.getter = function() { return Options.getPref(this.name); }; -function get_pref(name, forced_default) -{ - var pref = null; - var default_value = ""; - - // sometimes this var is not yet inititialized, make sure, it is - if (!g_vimperator_prefs) - g_vimperator_prefs = g_firefox_prefs.getBranch("extensions.vimperator."); - - if (forced_default) // this argument sets defaults for non-user settable options (like comp_history) - default_value = forced_default; - else + if (extra_info) { - for (var i=0; i -1 ? false : true; + document.getElementById("toolbar-menubar").hidden = value.indexOf("m") > -1 ? false : true; + // and main toolbar + document.getElementById("nav-bar").collapsed = value.indexOf("T") > -1 ? false : true; + document.getElementById("nav-bar").hidden = value.indexOf("T") > -1 ? false : true; + // and bookmarks toolbar + document.getElementById("PersonalToolbar").collapsed = value.indexOf("b") > -1 ? false : true; + document.getElementById("PersonalToolbar").hidden = value.indexOf("b") > -1 ? false : true; + // and original status bar (default), but show it, e.g. when needed for extensions + document.getElementById("status-bar").collapsed = value.indexOf("s") > -1 ? false : true; + document.getElementById("status-bar").hidden = value.indexOf("s") > -1 ? false : true; + } + + function setShowTabline(value) + { + // hide tabbar + if (value == 0) + { + getBrowser().mStrip.collapsed = true; + getBrowser().mStrip.hidden = true; + } + else if (value == 1) + vimperator.echo("show tabline only with > 1 page open not impl. yet"); else - pref = default_value; - } catch (e) - { - pref = default_value; + { + getBrowser().mStrip.collapsed = false; + getBrowser().mStrip.hidden = false; + } } - return pref; -} -///////////////////////////////////////////////// -// preference setter functions ///////////// {{{1 -///////////////////////////////////////////////// -function set_pref(name, value) -{ - // sometimes this var is not yet inititialized, make sure, it is - if (!g_vimperator_prefs) - g_vimperator_prefs = g_firefox_prefs.getBranch("extensions.vimperator."); - - if (typeof value == "string") - g_vimperator_prefs.setCharPref(name, value); - else if (typeof value == "number") - g_vimperator_prefs.setIntPref(name, value); - else if (typeof value == "boolean") - g_vimperator_prefs.setBoolPref(name, value); - else - vimperator.echoerr("Unknown typeof pref: " + value); -} - -function set_firefox_pref(name, value) -{ - // NOTE: firefox prefs are always inititialized, no need to re-init - - if (typeof value == "string") - g_firefox_prefs.setCharPref(name, value); - else if (typeof value == "number") - g_firefox_prefs.setIntPref(name, value); - else if (typeof value == "boolean") - g_firefox_prefs.setBoolPref(name, value); - else - vimperator.echoerr("Unknown typeof pref: " + value); -} - - -///////////////////////////////////////////////// -// helper functions //////////////////////// {{{1 -///////////////////////////////////////////////// - -function set_guioptions(value) -{ - // hide menubar - document.getElementById("toolbar-menubar").collapsed = value.indexOf("m") > -1 ? false : true; - document.getElementById("toolbar-menubar").hidden = value.indexOf("m") > -1 ? false : true; - // and main toolbar - document.getElementById("nav-bar").collapsed = value.indexOf("T") > -1 ? false : true; - document.getElementById("nav-bar").hidden = value.indexOf("T") > -1 ? false : true; - // and bookmarks toolbar - document.getElementById("PersonalToolbar").collapsed = value.indexOf("b") > -1 ? false : true; - document.getElementById("PersonalToolbar").hidden = value.indexOf("b") > -1 ? false : true; - // and original status bar (default), but show it, e.g. when needed for extensions - document.getElementById("status-bar").collapsed = value.indexOf("s") > -1 ? false : true; - document.getElementById("status-bar").hidden = value.indexOf("s") > -1 ? false : true; -} - -function set_showtabline(value) -{ - // hide tabbar - if(value == 0) + function setTitleString(value) { - getBrowser().mStrip.collapsed = true; - getBrowser().mStrip.hidden = true; + document.getElementById("main-window").setAttribute("titlemodifier", value); + document.title = window.content.document.title + " - " + value; // not perfect fix, but good enough } - else if(value == 1) - vimperator.echo("show tabline only with > 1 page open not impl. yet"); - else + + /////////////////////////////////////////////////////////////////////////////}}} + ////////////////////// PUBLIC SECTION ////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////{{{ + + this.__iterator__ = function() { - getBrowser().mStrip.collapsed = false; - getBrowser().mStrip.hidden = false; + return optionsIterator(); } -} -function set_titlestring(value) -{ - if (!value || typeof value != "string") - value = get_pref("titlestring"); + this.get = function(name) + { + for (var i = 0; i < options.length; i++) + { + if (options[i].hasName(name)) + return options[i]; + } + return null; + } - document.getElementById("main-window").setAttribute("titlemodifier", value); - document.title = window.content.document.title + " - " + value; // not perfect fix, but good enough -} + this.toString = function() + { + str = ""; + for (var i = 0; i < options.length; i++) + str += "\n\t" + options[i].name + "=" + options[i].value; + return "Options {" + str + "\n}" + } + + // TODO: separate Preferences from Options? Would these utility functions + // be better placed in the 'core' vimperator namespace somewhere? + Options.setPref = function(name, value) + { + return storePreference(name, value, true); + } + + Options.getPref = function(name, forced_default) + { + return loadPreference(name, forced_default, true); + } + + Options.setFirefoxPref = function(name, value) + { + return storePreference(name, value); + } + + Options.getFirefoxPref = function(name, forced_default) + { + return loadPreference(name, forced_default); + } + + /////////////////////////////////////////////////////////////////////////////}}} + ////////////////////// DEFAULT OPTIONS ///////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////{{{ + + addOption(new Option(["activate"], "stringlist", + { + short_help: "Define when tabs are automatically activated", + help: "Not implemented yet", + default_value: "quickmark,tabopen,paste" + } + )); + addOption(new Option(["beep"], "boolean", + { + short_help: "Emit a pc speaker beep on certain errors", + default_value: true + } + )); + addOption(new Option(["complete", "cpt"], "charlist", + { + short_help: "Items which are completed at the :[tab]open prompt", + help: "Available items:
    " + + "
  • s: Search machines and keyword URLs
  • " + + "
  • f: Local files
  • " + + "
  • b: Bookmarks
  • " + + "
  • h: History
" + + "The order is important, so :set complete=bs would list bookmarks first, and then any available quick searches.
" + + "Add 'sort' to the 'wildoptions' option if you want all entries sorted.", + default_value: "sfbh" + } + )); + addOption(new Option(["defsearch", "ds"], "string", + { + short_help: "Set the default search engine", + help: "The default search engine is used in the :[tab]open [arg] command " + + "if [arg] neither looks like a URL or like a specified search engine/keyword.", + completer: function() { return [["foo", "bar"], ["shit", "blub"]]; }, + default_value: "google" + } + )); + addOption(new Option(["extendedhinttags", "eht"], "string", + { + short_help: "XPath string of hintable elements activated by ';'", + default_value: "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | " + + "//input[@type!='hidden' or not(boolean(@type))] | //a | //area | //iframe | //textarea | //button | //select | " + + "//xhtml:*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | " + + "//xhtml:input[@type!='hidden' or not(boolean(@type))] | //xhtml:a | //xhtml:area | //xhtml:iframe | " + + "//xhtml:textarea | //xhtml:button | //xhtml:select" + } + )); + addOption(new Option(["focusedhintstyle", "fhs"], "string", + { + short_help: "CSS specification of focused hints appearance", + default_value: "z-index:5000; font-family:monospace; font-size:12px; color:ButtonText; background-color:ButtonShadow; " + + "border-color:ButtonShadow; border-width:1px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;" + } + )); + addOption(new Option(["fullscreen", "fs"], "boolean", + { + short_help: "Shows the current window fullscreen", + setter: function(value) { window.fullScreen = value; }, + getter: function() { return window.fullScreen; }, + default_value: false + } + )); + addOption(new Option(["guioptions", "go"], "charlist", + { + short_help: "Shows or hide the menu, toolbar and scrollbars", + help: "Supported characters:
    " + + "
  • m: menubar
  • " + + "
  • T: toolbar
  • " + + "
  • b: bookmark bar
  • " + + "
  • s: original Firefox statusbar
", + setter: function(value) { Options.setPref("guioptions", value); setGuiOptions(value); }, + getter: function() { return Options.getPref("guioptions"); }, + default_value: "" + } + )); + addOption(new Option(["hintchars", "hc"], "charlist", + { + short_help: "String of single characters which can be used to follow hints", + default_value: "hjklasdfgyuiopqwertnmzxcvb" + } + )); + addOption(new Option(["hintstyle", "hs"], "string", + { + short_help: "CSS specification of unfocused hints appearance", + default_value: "z-index:5000; font-family:monospace; font-size:12px; color:black; background-color:yellow; " + + "border-color:ButtonShadow; border-width:0px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;" + } + )); + addOption(new Option(["hinttags"], "string", + { + short_help: "XPath string of hintable elements activated by 'f' and 'F'", + default_value: "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | " + + "//input[@type!='hidden'] | //a | //area | //iframe | //textarea | //button | //select | " + + "//xhtml:*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | " + + "//xhtml:input[@type!='hidden'] | //xhtml:a | //xhtml:area | //xhtml:iframe | //xhtml:textarea | //xhtml:button | //xhtml:select" + } + )); + addOption(new Option(["maxhints", "mh"], "number", + { + short_help: "Maximum number of simultanously shown hints", + help: "If you want to speed up display of hints, choose a smaller value", + default_value: 250, + validator: function (value) { if (value>=1 && value <=1000) return true; else return false; } + } + )); + addOption(new Option(["preload"], "boolean", + { + short_help: "Speed up first time history/bookmark completion", + help: "History access can be quite slow for a large history. Vimperator maintains a cache to speed it up significantly on subsequent access.
" + + "In order to also speed up first time access, it is cached at startup, if this option is set (recommended).", + default_value: true + } + )); + addOption(new Option(["previewheight", "pvh"], "number", + { + short_help: "Default height for preview window", + help: "Value must be between 1 and 50. If the value is too high, completions may cover the command-line. " + + "Close the preview window with :pclose.", + default_value: 10, + validator: function (value) { if (value>=1 && value <=50) return true; else return false; } + } + )); + addOption(new Option(["showmode", "smd"], "boolean", + { + short_help: "Show the current mode in the command line", + default_value: true + } + )); + addOption(new Option(["showstatuslinks", "ssli"], "number", + { + short_help: "Show the destination of the link under the cursor in the status bar", + help: "Also links which are focused by keyboard commands like <Tab> are shown. " + + "Possible values:
    " + + "
  • 0: Don't show link destination
  • " + + "
  • 1: Show the link in the status line
  • " + + "
  • 2: Show the link in the command line
", + default_value: 1 + } + )); + addOption(new Option(["showtabline", "stal"], "number", + { + short_help: "Control when to show the tab bar of opened web pages", + help: "Possible values:
    " + + "
  • 0: Never show tab bar
  • " + + "
  • 1: Show tab bar only if more than one tab is open
  • " + + "
  • 2: Always show tab bar
" + + "Not implemented yet.", + setter: function(value) { Options.setPref("showtabline", value); setShowTabline(value); }, + getter: function() { return Options.getPref("showtabline"); }, + default_value: 2, + validator: function (value) { if (value>=0 && value <=2) return true; else return false; } + } + )); + addOption(new Option(["titlestring"], "string", + { + short_help: "Change the title of the browser window", + help: "Vimperator changes the browser title from \"Title of webpage - Mozilla Firefox\" to " + + "\"Title of webpage - Vimperator\".
If you don't like that, you can restore it with: " + + ":set titlestring=Mozilla Firefox.", + setter: function(value) { Options.setPref("titlestring", value); setTitleString(value); }, + getter: function() { return Options.getPref("titlestring"); }, + default_value: "Vimperator" + } + )); + addOption(new Option(["usermode", "um"], "boolean", + { + short_help: "Show current website with a minimal style sheet to make it easily accessible", + help: "Note that this is a local option for now, later it may be split into a global and :setlocal part", + setter: function(value) { getMarkupDocumentViewer().authorStyleDisabled = value; }, + getter: function() { return getMarkupDocumentViewer().authorStyleDisabled; }, + default_value: false + } + )); + addOption(new Option(["wildmode", "wim"], "stringlist", + { + short_help: "Define how command line completion works", + help: "It is a comma-separated list of parts, where each part specifies " + + "what to do for each consecutive use of the completion key. The first part " + + "specifies the behavior for the first use of the completion key, the second part " + + "for the second use, etc.
" + + "These are the possible values for each part:
" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
''Complete only the first match
'full'Complete the next full match. After the last, the original string is used.
'longest'Complete till the longest common string.
'list'When more than one match, list all matches.
'list:full'When more than one match, list all matches and complete first match.
'list:longest'When more than one match, list all matches and complete till the longest common string.
" + + "When there is only a single match, it is fully completed regardless of the case.", + default_value: "list:full" + } + )); + addOption(new Option(["wildoptions", "wop"], "stringlist", + { + short_help: "Change how command line completion is done", + help: "A list of words that change how command line completion is done.
" + + "Currently only one word is allowed:
" + + "" + + "" + + "
sortAlways sorts completion list, overriding the 'complete' option.
", + default_value: "" + } + )); + //}}} + + setShowTabline(this.showtabline); + setGuiOptions(this.guioptions); + setTitleString(this.titlestring); + + logMessage("Options initialized"); +}//}}} // vim: set fdm=marker sw=4 ts=4 et: diff --git a/chrome/content/vimperator/ui.js b/chrome/content/vimperator/ui.js index 68ca82e0..de4d732a 100644 --- a/chrome/content/vimperator/ui.js +++ b/chrome/content/vimperator/ui.js @@ -90,7 +90,7 @@ function CommandLine () var echo_allowed = false; // load the commandline history - var hist = get_pref("commandline_history", ""); + var hist = Options.getPref("commandline_history", ""); history = hist.split("\n"); // TODO: these styles should be moved to the .css file @@ -381,7 +381,7 @@ function CommandLine () [completion_start_index, completions] = res; // Sort the completion list - if (get_pref('wildoptions').match(/\bsort\b/)) + if (vimperator.options["wildoptions"].match(/\bsort\b/)) { completions.sort(function(a, b) { if (a[0] < b[0]) @@ -403,7 +403,7 @@ function CommandLine () return; } - var wim = get_pref('wildmode').split(/,/); + var wim = vimperator.options["wildmode"].split(/,/); var has_list = false; var longest = false; var full = false; @@ -500,7 +500,7 @@ function CommandLine () // it would be better if we had a destructor in javascript ... this.destroy = function() { - set_pref("commandline_history", history.join("\n")); + Options.setPref("commandline_history", history.join("\n")); } logMessage("CommandLine initialized."); } @@ -606,7 +606,7 @@ function InformationList(id, options) */ this.show = function(compl) { - //max_items = get_pref("previewheight"); + //max_items = vimperator.options["previewheight"]; if (compl) { diff --git a/chrome/content/vimperator/vimperator.js b/chrome/content/vimperator/vimperator.js index ce6e88fd..cd6f732c 100644 --- a/chrome/content/vimperator/vimperator.js +++ b/chrome/content/vimperator/vimperator.js @@ -51,11 +51,12 @@ function init() // TODO: can these classes be moved into a namesspace to now clobber // the main namespace? + Vimperator.prototype.options = new Options; Vimperator.prototype.events = new Events; Vimperator.prototype.commands = new Commands; Vimperator.prototype.bookmarks = new Bookmarks; Vimperator.prototype.history = new History; -// Vimperator.prototype.commandline = new CommandLine; + Vimperator.prototype.commandline = new CommandLine; Vimperator.prototype.search = new Search; Vimperator.prototype.previewwindow = new InformationList("vimperator-previewwindow", { incremental_fill: false, max_items: 10 }); Vimperator.prototype.bufferwindow = new InformationList("vimperator-bufferwindow", { incremental_fill: false, max_items: 10 }); @@ -64,6 +65,10 @@ function init() Vimperator.prototype.mappings = new Mappings; Vimperator.prototype.marks = new Marks; + // DJK FIXME + Vimperator.prototype.echo = vimperator.commandline.echo; + Vimperator.prototype.echoerr = vimperator.commandline.echoErr; + // XXX: move into Vimperator() ? vimperator.input = { buffer: "", // partial command storage @@ -75,34 +80,34 @@ function init() vimperator.registerCallback("submit", vimperator.modes.EX, function(command) { /*vimperator.*/execute(command); } ); vimperator.registerCallback("complete", vimperator.modes.EX, function(str) { return exTabCompletion(str); } ); - set_showtabline(get_pref("showtabline")); - set_guioptions(get_pref("guioptions")); - set_titlestring(); + // this function adds all our required listeners to react on events + // also stuff like window.onScroll is handled there. + //addEventListeners(); + //vimperator.events(); // work around firefox popup blocker - popup_allowed_events = get_firefox_pref('dom.popup_allowed_events', 'change click dblclick mouseup reset submit'); + popup_allowed_events = Options.getFirefoxPref('dom.popup_allowed_events', 'change click dblclick mouseup reset submit'); if (!popup_allowed_events.match("keypress")) - set_firefox_pref('dom.popup_allowed_events', popup_allowed_events + " keypress"); + Options.setFirefoxPref('dom.popup_allowed_events', popup_allowed_events + " keypress"); // we have our own typeahead find implementation - set_firefox_pref('accessibility.typeaheadfind.autostart', false); - set_firefox_pref('accessibility.typeaheadfind', false); // actually the above setting should do it, but has no effect in firefox + Options.setFirefoxPref('accessibility.typeaheadfind.autostart', false); + Options.setFirefoxPref('accessibility.typeaheadfind', false); // actually the above setting should do it, but has no effect in firefox // first time intro message - if (get_pref("firsttime", true)) + if (Options.getPref("firsttime", true)) { setTimeout(function() { help(null, null, null, { inTab: true }); - set_pref("firsttime", false); + Options.setPref("firsttime", false); }, 1000); } - gURLBar.blur(); vimperator.focusContent(); // firefox preferences which we need to be changed to work well with vimperator - set_firefox_pref("browser.startup.page", 3); // start with saved session + Options.setFirefoxPref("browser.startup.page", 3); // start with saved session // Finally, read a ~/.vimperatorrc // Make sourcing asynchronous, otherwise commands that open new tabs won't work @@ -123,9 +128,9 @@ function unload() vimperator.events.destroy(); // reset some modified firefox prefs - if (get_firefox_pref('dom.popup_allowed_events', 'change click dblclick mouseup reset submit') + if (Options.getFirefoxPref('dom.popup_allowed_events', 'change click dblclick mouseup reset submit') == popup_allowed_events + " keypress") - set_firefox_pref('dom.popup_allowed_events', popup_allowed_events); + Options.setFirefoxPref('dom.popup_allowed_events', popup_allowed_events); } @@ -173,7 +178,7 @@ function Vimperator() //{{{1 function showMode() { - if (!get_pref("showmode")) + if (!vimperator.options["showmode"]) return; var str_mode = mode_messages[mode]; @@ -199,7 +204,8 @@ function Vimperator() //{{{1 ////////////////////// PUBLIC SECTION ////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// this.ver = "###VERSION### CVS (created: ###DATE###)"; - this.commandline = new CommandLine(); + // DJK FIXME + // this.commandline = new CommandLine(); // this.search = new Search(); /////////////// callbacks //////////////////////////// @@ -227,8 +233,8 @@ function Vimperator() //{{{1 } // just forward these echo commands - this.echo = this.commandline.echo; - this.echoerr = this.commandline.echoErr; + // DJK FIXME: this.echo = this.commandline.echo; + // DJK FIXME: this.echoerr = this.commandline.echoErr; this.getMode = function() @@ -680,7 +686,7 @@ function Events() //{{{1 }, setOverLink : function(link, b) { - var ssli = get_pref("showstatuslinks"); + var ssli = vimperator.options["showstatuslinks"]; if (link && ssli) { if (ssli == 1) @@ -883,7 +889,7 @@ function Tabs() //{{{1 return; } - var numbertabs = get_pref('numbertabs'); + var numbertabs = vimperator.options["numbertabs"]; if(numbertabs) { if(split_title)