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

added Option.{get/set}

This commit is contained in:
Martin Stubenschrott
2008-08-13 23:07:51 +00:00
parent a5e2c7f912
commit ac59056ac8

View File

@@ -65,36 +65,52 @@ liberator.Option = function (names, description, type, defaultValue, scope, gett
} }
} }
this.__defineGetter__("value", this.get = function(scope)
function () {
if (scope)
{ {
var aValue; if ((scope & this.scope) == 0) // option doesn't exist in this scope
return null;
if (this.scope & liberator.options.OPTION_SCOPE_LOCAL)
aValue = liberator.tabs.options[this.name]; // TODO: does that work without has("tabs")?
if ((this.scope & liberator.options.OPTION_SCOPE_GLOBAL) && (aValue == undefined))
aValue = value;
if (this.getter)
this.getter.call(this, aValue);
return aValue;
} }
); else
scope = this.scope;
this.__defineSetter__("value", var aValue;
function (newValue)
if (scope & liberator.options.OPTION_SCOPE_LOCAL)
aValue = liberator.tabs.options[this.name]; // TODO: does that work without has("tabs")?
if ((scope & liberator.options.OPTION_SCOPE_GLOBAL) && (aValue == undefined))
aValue = value;
if (this.getter)
this.getter.call(this, aValue);
return aValue;
};
this.set = function(newValue, scope)
{
if (scope)
{ {
if (this.scope & liberator.options.OPTION_SCOPE_LOCAL) if ((scope & this.scope) == 0) // option doesn't exist in this scope
liberator.buffer.options[this.name] = newValue; return null;
if (this.scope & liberator.options.OPTION_SCOPE_GLOBAL)
value = newValue;
this.hasChanged = true;
if (this.setter)
this.setter.call(this, newValue);
} }
); else
scope = this.scope;
if (scope & liberator.options.OPTION_SCOPE_LOCAL)
liberator.tabs.options[this.name] = newValue;
if (scope & liberator.options.OPTION_SCOPE_GLOBAL)
value = newValue;
this.hasChanged = true;
if (this.setter)
this.setter.call(this, newValue);
};
this.__defineGetter__("value", this.get);
this.__defineSetter__("value", this.set);
this.hasName = function (name) this.hasName = function (name)
{ {
@@ -445,11 +461,6 @@ liberator.Options = function () //{{{
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;
@@ -492,12 +503,10 @@ liberator.Options = function () //{{{
} }
else else
{ {
option.scope = newOptionScope;
if (option.type == "boolean") if (option.type == "boolean")
liberator.echo((option.value ? " " : "no") + option.name); liberator.echo((option.get(scope) ? " " : "no") + option.name);
else else
liberator.echo(" " + option.name + "=" + option.value); liberator.echo(" " + option.name + "=" + option.get(scope));
option.scope = oldOptionScope;
} }
} }
// write access // write access
@@ -505,9 +514,7 @@ liberator.Options = function () //{{{
// improved. i.e. Vim's behavior is pretty sloppy to no real benefit // improved. i.e. Vim's behavior is pretty sloppy to no real benefit
else else
{ {
option.scope = newOptionScope; var currentValue = option.get(scope);
var currentValue = option.value;
option.scope = oldOptionScope;
var newValue; var newValue;
@@ -604,9 +611,7 @@ liberator.Options = function () //{{{
if (option.isValidValue(newValue)) if (option.isValidValue(newValue))
{ {
option.scope = newOptionScope; option.set(newValue, scope);
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