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

More cleanup and a fix or two

This commit is contained in:
Kris Maglione
2008-11-26 06:46:13 +00:00
parent 79acfcf412
commit 3176b654dd

View File

@@ -36,8 +36,7 @@ function Option(names, description, type, defaultValue, extraInfo) //{{{
if (!extraInfo) if (!extraInfo)
extraInfo = {}; extraInfo = {};
let cannonName = names[0]; this.name = names[0];
this.name = cannonName;
this.names = names; this.names = names;
this.type = type; this.type = type;
this.scope = (extraInfo.scope & options.OPTION_SCOPE_BOTH) || this.scope = (extraInfo.scope & options.OPTION_SCOPE_BOTH) ||
@@ -62,31 +61,49 @@ function Option(names, description, type, defaultValue, extraInfo) //{{{
if (this.type == "boolean") if (this.type == "boolean")
{ {
this.names = []; // reset since order is important this.names = []; // reset since order is important
for (let i = 0; i < names.length; i++) for (let [,name] in Iterator(names))
{ {
this.names.push(names[i]); this.names.push(name);
this.names.push("no" + names[i]); this.names.push("no" + name);
} }
} }
this.__defineGetter__("globalvalue", function () options.store.get(cannonName));
this.__defineSetter__("globalvalue", function (val) { options.store.set(cannonName, val); });
if (this.globalvalue == undefined) if (this.globalvalue == undefined)
this.globalvalue = this.defaultValue; this.globalvalue = this.defaultValue;
}
Option.prototype = {
get globalvalue() options.store.get(this.name),
set globalvalue(val) { options.store.set(this.name, val) },
this.__defineGetter__("values", function () this.getValues(this.scope)); parseValues: function (value)
this.getValues = function (scope)
{ {
let value = this.get(scope);
if (this.type == "stringlist") if (this.type == "stringlist")
return value.split(","); return value.split(",");
if (this.type == "charlist") if (this.type == "charlist")
return Array.slice(value); return Array.slice(value);
return value; return value;
}; },
this.get = function (scope) joinValues: function (values)
{
if (this.type == "stringlist")
return values.join(",");
if (this.type == "charlist")
return values.join("");
return values;
},
get values() this.parseValues(this.value),
set values(values) this.setValues(this.scope, values),
getValues: function (scope) this.parseValues(this.get(scope)),
setValues: function (values, scope)
{
this.set(this.joinValues(values), scope || this.scope);
},
get: function (scope)
{ {
if (scope) if (scope)
{ {
@@ -109,9 +126,9 @@ function Option(names, description, type, defaultValue, extraInfo) //{{{
this.getter.call(this, aValue); this.getter.call(this, aValue);
return aValue; return aValue;
}; },
this.set = function (newValue, scope) set: function (newValue, scope)
{ {
scope = scope || this.scope; scope = scope || this.scope;
if ((scope & this.scope) == 0) // option doesn't exist in this scope if ((scope & this.scope) == 0) // option doesn't exist in this scope
@@ -135,12 +152,12 @@ function Option(names, description, type, defaultValue, extraInfo) //{{{
this.globalvalue = newValue; this.globalvalue = newValue;
this.hasChanged = true; this.hasChanged = true;
}; },
this.__defineGetter__("value", this.get); get value() this.get(),
this.__defineSetter__("value", this.set); set value(val) this.set(val),
this.has = function () has: function ()
{ {
let self = this; let self = this;
let test = function (val) values.indexOf(val) >= 0; let test = function (val) values.indexOf(val) >= 0;
@@ -149,25 +166,22 @@ function Option(names, description, type, defaultValue, extraInfo) //{{{
let values = this.values; let values = this.values;
/* Return whether some argument matches */ /* Return whether some argument matches */
return Array.some(arguments, function (val) test(val)) return Array.some(arguments, function (val) test(val))
}; },
this.hasName = function (name) hasName: function (name) this.names.indexOf(name) >= 0,
{
return this.names.indexOf(name) >= 0;
};
this.isValidValue = function (value) isValidValue: function (value)
{ {
if (this.validator) if (this.validator)
return this.validator(value); return this.validator(value);
else else
return true; return true;
}; },
this.reset = function () reset: function ()
{ {
this.value = this.defaultValue; this.value = this.defaultValue;
}; },
}; //}}} }; //}}}
@@ -607,12 +621,6 @@ function Options() //{{{
break; break;
} }
// NOTE: empty elements are significant in stringlist options like 'cdpath'
if (option.type == "stringlist")
newValue = newValue.join(",");
else
newValue = newValue.filter(function (x) x != "").join("");
break; break;
case "string": case "string":
@@ -638,10 +646,9 @@ function Options() //{{{
liberator.echoerr("E685: Internal error: option type `" + option.type + "' not supported"); liberator.echoerr("E685: Internal error: option type `" + option.type + "' not supported");
} }
newValue = option.joinValues(newValue);
if (option.isValidValue(newValue)) if (option.isValidValue(newValue))
{
option.set(newValue, opt.scope); option.set(newValue, opt.scope);
}
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);
@@ -731,7 +738,7 @@ function Options() //{{{
if (completer) if (completer)
{ {
completions = completions.concat(completer(filter)); completions = completions.concat(completer(filter));
if (opt.optionValues) if (/list$/.test(option.type))
{ {
completions = completions.filter(function (val) opt.values.indexOf(val[0]) == -1); completions = completions.filter(function (val) opt.values.indexOf(val[0]) == -1);
switch (opt.operator) switch (opt.operator)
@@ -968,15 +975,7 @@ function Options() //{{{
ret.optionValue = ret.option.get(ret.scope); ret.optionValue = ret.option.get(ret.scope);
ret.optionValues = ret.option.getValues(ret.scope); ret.optionValues = ret.option.getValues(ret.scope);
switch (ret.option.type) ret.values = ret.option.parseValues(ret.value);
{
case "stringlist":
ret.values = ret.value.split(",");
break;
case "charlist":
ret.values = Array.slice(ret.value);
break;
}
return ret; return ret;
}, },