mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 07:17:59 +01:00
added Option.{get/set}
This commit is contained in:
@@ -65,36 +65,52 @@ liberator.Option = function (names, description, type, defaultValue, scope, gett
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.__defineGetter__("value",
|
this.get = function(scope)
|
||||||
function ()
|
|
||||||
{
|
{
|
||||||
|
if (scope)
|
||||||
|
{
|
||||||
|
if ((scope & this.scope) == 0) // option doesn't exist in this scope
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
scope = this.scope;
|
||||||
|
|
||||||
var aValue;
|
var aValue;
|
||||||
|
|
||||||
if (this.scope & liberator.options.OPTION_SCOPE_LOCAL)
|
if (scope & liberator.options.OPTION_SCOPE_LOCAL)
|
||||||
aValue = liberator.tabs.options[this.name]; // TODO: does that work without has("tabs")?
|
aValue = liberator.tabs.options[this.name]; // TODO: does that work without has("tabs")?
|
||||||
if ((this.scope & liberator.options.OPTION_SCOPE_GLOBAL) && (aValue == undefined))
|
if ((scope & liberator.options.OPTION_SCOPE_GLOBAL) && (aValue == undefined))
|
||||||
aValue = value;
|
aValue = value;
|
||||||
|
|
||||||
if (this.getter)
|
if (this.getter)
|
||||||
this.getter.call(this, aValue);
|
this.getter.call(this, aValue);
|
||||||
|
|
||||||
return aValue;
|
return aValue;
|
||||||
}
|
};
|
||||||
);
|
|
||||||
|
|
||||||
this.__defineSetter__("value",
|
this.set = function(newValue, scope)
|
||||||
function (newValue)
|
|
||||||
{
|
{
|
||||||
if (this.scope & liberator.options.OPTION_SCOPE_LOCAL)
|
if (scope)
|
||||||
liberator.buffer.options[this.name] = newValue;
|
{
|
||||||
if (this.scope & liberator.options.OPTION_SCOPE_GLOBAL)
|
if ((scope & this.scope) == 0) // option doesn't exist in this scope
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
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;
|
value = newValue;
|
||||||
|
|
||||||
this.hasChanged = true;
|
this.hasChanged = true;
|
||||||
if (this.setter)
|
if (this.setter)
|
||||||
this.setter.call(this, newValue);
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user