1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 17:42:27 +01:00

new :setlocal and :setglobal commands, please test thorougly and improve! Thanks konstantin

This commit is contained in:
Martin Stubenschrott
2008-08-07 20:23:09 +00:00
parent 615fddca4f
commit 902d7c4030
6 changed files with 167 additions and 18 deletions

View File

@@ -2,6 +2,7 @@
<b>Note:</b> If you don't wish to appear on this list when making a donation, please tell me. <b>Note:</b> If you don't wish to appear on this list when making a donation, please tell me.
2008: 2008:
* Victor Nemkov
* John Lusth * John Lusth
* Thomas Svensen * Thomas Svensen
* Ryan McBride * Ryan McBride

1
NEWS
View File

@@ -35,6 +35,7 @@
* keywords in :open <arg> have higher priority than local files now * keywords in :open <arg> have higher priority than local files now
* add :set online to control the "work offline" menu item * add :set online to control the "work offline" menu item
* add :jumps command to list current tab's history * add :jumps command to list current tab's history
* add :setlocal & :setglobal commands, so options can be local (per tab) & global
* many small bug fixes * many small bug fixes
2008-06-03: 2008-06-03:

1
TODO
View File

@@ -34,6 +34,7 @@ FEATURES:
google to another page and click 10 links there, [d would take me back to the google page google to another page and click 10 links there, [d would take me back to the google page
opera's fast forward does something like this opera's fast forward does something like this
7 make an option to disable session saving by default when you close Firefox 7 make an option to disable session saving by default when you close Firefox
6 check/correct spellings in insert mode with some mappings
6 add more autocommands (TabClose, TabOpen, TabChanged, any more?) 6 add more autocommands (TabClose, TabOpen, TabChanged, any more?)
6 jump to the next heading with ]h, next image ]i, previous textbox [t and so on 6 jump to the next heading with ]h, next image ]i, previous textbox [t and so on
6 :grep support (needs location list) 6 :grep support (needs location list)

View File

@@ -582,8 +582,6 @@ liberator.Buffer = function () //{{{
get URL() get URL()
{ {
// TODO: .URL is not defined for XUL documents
//return window.content.document.URL;
return window.content.document.location.href; return window.content.document.location.href;
}, },
@@ -615,6 +613,13 @@ liberator.Buffer = function () //{{{
return window.content.document.title; return window.content.document.title;
}, },
get options()
{
if (!window.content.document.liberatorOptions)
window.content.document.liberatorOptions = {};
return window.content.document.liberatorOptions;
},
// returns an XPathResult object // returns an XPathResult object
evaluateXPath: function (expression, doc, elem, asIterator) evaluateXPath: function (expression, doc, elem, asIterator)
{ {

View File

@@ -28,7 +28,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
// Do NOT create instances of this class yourself, use the helper method // Do NOT create instances of this class yourself, use the helper method
// liberator.options.add() instead // liberator.options.add() instead
liberator.Option = function (names, description, type, defaultValue, getter, setter, validator, completer) //{{{ liberator.Option = function (names, description, type, defaultValue, scope, getter, setter, validator, completer) //{{{
{ {
if (!names || !type) if (!names || !type)
return null; return null;
@@ -38,6 +38,7 @@ liberator.Option = function (names, description, type, defaultValue, getter, set
this.name = names[0]; this.name = names[0];
this.names = names; this.names = names;
this.type = type; this.type = type;
this.scope = (scope & liberator.options.OPTION_SCOPE_BOTH) || liberator.options.OPTION_SCOPE_GLOBAL; // XXX set to BOTH by default someday? - kstep
this.description = description || ""; this.description = description || "";
// "", 0 are valid default values // "", 0 are valid default values
@@ -67,18 +68,30 @@ liberator.Option = function (names, description, type, defaultValue, getter, set
this.__defineGetter__("value", this.__defineGetter__("value",
function () function ()
{ {
var aValue;
if (this.scope & liberator.options.OPTION_SCOPE_LOCAL)
aValue = liberator.buffer.options[this.name];
if ((this.scope & liberator.options.OPTION_SCOPE_GLOBAL) && (aValue == undefined))
aValue = value;
if (this.getter) if (this.getter)
this.getter.call(this); this.getter.call(this, aValue);
return value;
return aValue;
} }
); );
this.__defineSetter__("value", this.__defineSetter__("value",
function (newValue) function (newValue)
{ {
if (this.scope & liberator.options.OPTION_SCOPE_LOCAL)
liberator.buffer.options[this.name] = newValue;
if (this.scope & liberator.options.OPTION_SCOPE_GLOBAL)
value = newValue; value = newValue;
this.hasChanged = true; this.hasChanged = true;
if (this.setter) if (this.setter)
this.setter.call(this, value); this.setter.call(this, newValue);
} }
); );
@@ -298,8 +311,8 @@ liberator.Options = function () //{{{
if (special) // open firefox settings gui dialog if (special) // open firefox settings gui dialog
{ {
liberator.open("about:config", liberator.open("about:config",
(liberator.options["newtab"] && (liberator.options.newtab &&
(liberator.options["newtab"] == "all" || liberator.options["newtab"].split(",").indexOf("prefs") != -1)) ? (liberator.options.newtab == "all" || liberator.options.newtab.split(",").indexOf("prefs") != -1)) ?
liberator.NEW_TAB : liberator.CURRENT_TAB); liberator.NEW_TAB : liberator.CURRENT_TAB);
} }
else else
@@ -313,6 +326,38 @@ liberator.Options = function () //{{{
} }
}); });
liberator.commands.add(["setl[ocal]"],
"Set local option",
function (args, special, count)
{
liberator.commands.get("set").execute(args, special, count, { scope: liberator.options.OPTION_SCOPE_LOCAL });
},
{
completer: function (filter, special, count)
{
return liberator.commands.get("set").completer(filter, special, count, { scope: liberator.options.OPTION_SCOPE_LOCAL });
}
}
);
liberator.commands.add(["setg[lobal]"],
"Set global option",
function (args, special, count)
{
liberator.commands.get("set").execute(args, special, count, { scope: liberator.options.OPTION_SCOPE_GLOBAL });
},
{
completer: function (filter, special, count)
{
return liberator.commands.get("set").completer(filter, special, count, { scope: liberator.options.OPTION_SCOPE_GLOBAL });
}
}
);
// TODO: support setting multiple options at once // TODO: support setting multiple options at once
liberator.commands.add(["se[t]"], liberator.commands.add(["se[t]"],
"Set an option", "Set an option",
@@ -396,13 +441,23 @@ liberator.Options = function () //{{{
if (name == "all") if (name == "all")
all = true; all = true;
var option = liberator.options.get(name); var scope = liberator.options.OPTION_SCOPE_BOTH;
if (modifiers && modifiers.scope)
scope = modifiers.scope;
var option = liberator.options.get(name, scope);
if (!option && !all) if (!option && !all)
{ {
liberator.echoerr("E518: Unknown option: " + args); liberator.echoerr("E518: Unknown option: " + args);
return; return;
} }
var oldOptionScope = option.scope;
var newOptionScope = option.scope;
if (scope != liberator.options.OPTION_SCOPE_BOTH)
newOptionScope = scope;
var valueGiven = !!matches[4]; var valueGiven = !!matches[4];
var get = false; var get = false;
@@ -441,14 +496,16 @@ liberator.Options = function () //{{{
{ {
if (all) if (all)
{ {
liberator.options.list(onlyNonDefault); liberator.options.list(onlyNonDefault, scope);
} }
else else
{ {
option.scope = newOptionScope;
if (option.type == "boolean") if (option.type == "boolean")
liberator.echo((option.value ? " " : "no") + option.name); liberator.echo((option.value ? " " : "no") + option.name);
else else
liberator.echo(" " + option.name + "=" + option.value); liberator.echo(" " + option.name + "=" + option.value);
option.scope = oldOptionScope;
} }
} }
// write access // write access
@@ -457,7 +514,10 @@ liberator.Options = function () //{{{
// benefit // benefit
else else
{ {
option.scope = newOptionScope;
var currentValue = option.value; var currentValue = option.value;
option.scope = oldOptionScope;
var newValue; var newValue;
switch (option.type) switch (option.type)
@@ -470,7 +530,7 @@ liberator.Options = function () //{{{
} }
if (invertBoolean) if (invertBoolean)
newValue = !option.value; newValue = !currentValue;
else else
newValue = !unsetBoolean; newValue = !unsetBoolean;
@@ -552,14 +612,18 @@ liberator.Options = function () //{{{
} }
if (option.isValidValue(newValue)) if (option.isValidValue(newValue))
{
option.scope = newOptionScope;
option.value = newValue; option.value = newValue;
option.scope = oldOptionScope;
}
else else
// FIXME: need to be able to specify more specific errors // FIXME: need to be able to specify more specific errors
liberator.echoerr("E474: Invalid argument: " + args); liberator.echoerr("E474: Invalid argument: " + args);
} }
}, },
{ {
completer: function (filter, special) completer: function (filter, special, count, modifiers)
{ {
var optionCompletions = []; var optionCompletions = [];
var prefix = filter.match(/^no|inv/) || ""; var prefix = filter.match(/^no|inv/) || "";
@@ -594,11 +658,18 @@ liberator.Options = function () //{{{
return [0, liberator.completion.filter(optionCompletions, filter)]; return [0, liberator.completion.filter(optionCompletions, filter)];
} }
var scope = liberator.options.OPTION_SCOPE_BOTH;
if (modifiers && modifiers.scope)
scope = modifiers.scope;
if (!filter) if (!filter)
{ {
var options = []; var options = [];
for (var option in liberator.options) for (var option in liberator.options)
{ {
if (!(option.scope & scope))
continue;
if (prefix && option.type != "boolean") if (prefix && option.type != "boolean")
continue; continue;
options.push([prefix + option.name, option.description]); options.push([prefix + option.name, option.description]);
@@ -611,6 +682,8 @@ liberator.Options = function () //{{{
filter = filter.substr(0, filter.length - 1); filter = filter.substr(0, filter.length - 1);
for (var option in liberator.options) for (var option in liberator.options)
{ {
if (!(option.scope & scope))
continue;
if (option.hasName(filter)) if (option.hasName(filter))
{ {
if (option.completer) if (option.completer)
@@ -624,6 +697,8 @@ liberator.Options = function () //{{{
var filterLength = filter.length; var filterLength = filter.length;
for (var option in liberator.options) for (var option in liberator.options)
{ {
if (!(option.scope & scope))
continue;
if (prefix && option.type != "boolean") if (prefix && option.type != "boolean")
continue; continue;
@@ -674,6 +749,10 @@ liberator.Options = function () //{{{
return { return {
OPTION_SCOPE_GLOBAL: 1,
OPTION_SCOPE_LOCAL: 2,
OPTION_SCOPE_BOTH: 3,
__iterator__: function () __iterator__: function ()
{ {
for (var i = 0; i < options.length; i++) for (var i = 0; i < options.length; i++)
@@ -687,15 +766,29 @@ liberator.Options = function () //{{{
if (!extraInfo) if (!extraInfo)
extraInfo = {}; extraInfo = {};
var option = new liberator.Option(names, description, type, defaultValue, var option = new liberator.Option(names, description, type, defaultValue, extraInfo.scope,
extraInfo.getter, extraInfo.setter, extraInfo.validator, extraInfo.completer); extraInfo.getter, extraInfo.setter, extraInfo.validator, extraInfo.completer);
if (!option)
return false;
for (var i = 0; i < options.length; i++)
{
if (options[i].name == option.name)
{
// never replace for now
liberator.log("Warning: '" + names[0] + "' already exists, NOT replacing existing option.", 1);
return false;
}
}
// quickly access options with liberator.options["wildmode"]: // quickly access options with liberator.options["wildmode"]:
this.__defineGetter__(option.name, function () { return option.value; }); this.__defineGetter__(option.name, function () { return option.value; });
this.__defineSetter__(option.name, function (value) { option.value = value; }); this.__defineSetter__(option.name, function (value) { option.value = value; });
// TODO: sort option // TODO: sort option
options.push(option); options.push(option);
return true;
}, },
destroy: function () destroy: function ()
@@ -706,22 +799,29 @@ liberator.Options = function () //{{{
storePreference("dom.popup_allowed_events", popupAllowedEvents); storePreference("dom.popup_allowed_events", popupAllowedEvents);
}, },
get: function (name) get: function (name, scope)
{ {
if (!scope)
scope = liberator.options.OPTION_SCOPE_BOTH;
for (var i = 0; i < options.length; i++) for (var i = 0; i < options.length; i++)
{ {
if (options[i].hasName(name)) if (options[i].hasName(name) && (options[i].scope & scope))
return options[i]; return options[i];
} }
return null; return null;
}, },
list: function (onlyNonDefault) list: function (onlyNonDefault, scope)
{ {
var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" + var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" +
"<table><tr align=\"left\" class=\"hl-Title\"><th>--- Options ---</th></tr>"; "<table><tr align=\"left\" class=\"hl-Title\"><th>--- Options ---</th></tr>";
var name, value, def; var name, value, def;
if (!scope)
scope = liberator.options.OPTION_SCOPE_BOTH;
for (var i = 0; i < options.length; i++) for (var i = 0; i < options.length; i++)
{ {
name = options[i].name; name = options[i].name;
@@ -731,6 +831,9 @@ liberator.Options = function () //{{{
if (onlyNonDefault && value == def) if (onlyNonDefault && value == def)
continue; continue;
if (!(options[i].scope & scope))
continue;
if (options[i].type == "boolean") if (options[i].type == "boolean")
{ {
name = value ? " " + name : "no" + name; name = value ? " " + name : "no" + name;

View File

@@ -81,6 +81,44 @@ exactly as they appear in the option. Remove flags
one by one to avoid problems. one by one to avoid problems.
____ ____
|:setlocal| |:setl|
||:setl[ocal]|| +
||:setl[ocal] all|| +
||:setl[ocal] {option}?|| +
||:setl[ocal] {option}|| +
||:setl[ocal] no{option}|| +
||:setl[ocal] inv{option}|| +
||:setl[ocal] {option}&|| +
||:setl[ocal] all&|| +
||:setl[ocal] {option}={value}|| +
||:setl[ocal] {option}+={value}|| +
||:setl[ocal] {option}^={value}|| +
||:setl[ocal] {option}-={value}|| +
____
The same as [c]:set[c] command, but operates on local for current
tab options only. See [c]:set[c] for details.
____
|:setglobal| |:setg|
||:setg[lobal]|| +
||:setg[lobal] all|| +
||:setg[lobal] {option}?|| +
||:setg[lobal] {option}|| +
||:setg[lobal] no{option}|| +
||:setg[lobal] inv{option}|| +
||:setg[lobal] {option}&|| +
||:setg[lobal] all&|| +
||:setg[lobal] {option}={value}|| +
||:setg[lobal] {option}+={value}|| +
||:setg[lobal] {option}^={value}|| +
||:setg[lobal] {option}-={value}|| +
____
The same as [c]:set[c] command, but operates on global options only.
See [c]:set[c] for details.
____
section:Setting{nbsp}Firefox{nbsp}options[firefox-options] section:Setting{nbsp}Firefox{nbsp}options[firefox-options]
Most Firefox options are not touched/overridden by Vimperator. In order to set Most Firefox options are not touched/overridden by Vimperator. In order to set