1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-09 19:05:46 +01:00

Add Option.has(). Improve JS completion.

This commit is contained in:
Kris Maglione
2008-10-07 03:19:40 +00:00
parent 0f438cb499
commit 3169a93825
6 changed files with 42 additions and 44 deletions

View File

@@ -308,6 +308,7 @@ liberator.Completion = function () //{{{
{
try
{
liberator.dump("eval(" + liberator.util.escapeString(arg) + ")");
return window.eval(arg);
}
catch(e) {}
@@ -345,7 +346,7 @@ liberator.Completion = function () //{{{
if (["string", "number", "boolean"].indexOf(type) > -1)
type += ": " + String(v).replace("\n", "\\n", "g");
if (type == "function")
type += ": " + v.toSource.replace(/\{.*/, "{ ... }");
type += ": " + String(v).replace(/{(.|\n)*/, "{ ... }");
compl.push([k, type]);
}

View File

@@ -253,7 +253,7 @@ liberator.AutoCommands = function () //{{{
{
let events = liberator.options["eventignore"].split(",");
if (events.some(function (e) e == "all" || e == event))
if (liberator.options.get("eventignore").has("all", event))
return;
let autoCmds = store.filter(function (autoCmd) autoCmd.event == event);

View File

@@ -155,9 +155,8 @@ const liberator = (function () //{{{
function ()
{
liberator.open("chrome://mozapps/content/extensions/extensions.xul",
(liberator.options["newtab"] &&
(liberator.options["newtab"] == "all" || liberator.options["newtab"].split(",").indexOf("addons") != -1)) ?
liberator.NEW_TAB: liberator.CURRENT_TAB);
(liberator.options["newtab"] && liberator.options.get("newtab").has("all", "addons"))
? liberator.NEW_TAB: liberator.CURRENT_TAB);
},
{ argCount: "0" });
@@ -329,9 +328,8 @@ const liberator = (function () //{{{
if (special) // open javascript console
{
liberator.open("chrome://global/content/console.xul",
(liberator.options["newtab"] &&
(liberator.options["newtab"] == "all" || liberator.options["newtab"].split(",").indexOf("javascript") != -1)) ?
liberator.NEW_TAB : liberator.CURRENT_TAB);
(liberator.options["newtab"] && liberator.options.get("newtab").has("all", "javascript"))
? liberator.NEW_TAB : liberator.CURRENT_TAB);
}
else
{
@@ -889,9 +887,8 @@ const liberator = (function () //{{{
help: function (topic)
{
var where = (liberator.options["newtab"] && (liberator.options["newtab"] == "all" ||
liberator.options["newtab"].split(",").indexOf("help") != -1)) ?
liberator.NEW_TAB : liberator.CURRENT_TAB;
var where = (liberator.options["newtab"] && liberator.options.get("newtab").has("all", "help"))
? liberator.NEW_TAB : liberator.CURRENT_TAB;
if (!topic)
{

View File

@@ -100,15 +100,9 @@ liberator.Option = function (names, description, type, defaultValue, extraInfo)
this.set = function (newValue, scope)
{
if (scope)
{
if ((scope & this.scope) == 0) // option doesn't exist in this scope
return null;
}
else
{
scope = this.scope;
}
scope = scope || this.scope;
if ((scope & this.scope) == 0) // option doesn't exist in this scope
return null;
if (this.setter)
{
@@ -130,8 +124,16 @@ liberator.Option = function (names, description, type, defaultValue, extraInfo)
this.hasChanged = true;
};
this.__defineGetter__("value", this.get);
this.has = function ()
{
let value = this.value;
if (this.type == "stringlist")
value = this.value.split(",");
/* Return the number of matching arguments. */
return Array.reduce(arguments, function (n, val) value.indexOf(val) >= 0, 0);
};
this.__defineGetter__("value", this.get);
this.__defineSetter__("value", this.set);
this.hasName = function (name)
@@ -162,7 +164,7 @@ liberator.Options = function () //{{{
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var options = [];
var options = {};
function optionObserver(key, event, option)
{
@@ -368,9 +370,8 @@ liberator.Options = function () //{{{
if (special) // open Firefox settings GUI dialog
{
liberator.open("about:config",
(liberator.options.newtab &&
(liberator.options.newtab == "all" || liberator.options.newtab.split(",").indexOf("prefs") != -1)) ?
liberator.NEW_TAB : liberator.CURRENT_TAB);
(liberator.options["newtab"] && liberator.options.get("newtab").has("all", "prefs"))
? liberator.NEW_TAB : liberator.CURRENT_TAB);
}
else
{
@@ -881,9 +882,9 @@ liberator.Options = function () //{{{
__iterator__: function ()
{
let sorted = options.sort(function (opt1, opt2) opt1.name > opt2.name);
for (let i = 0; i < sorted.length; i++)
yield sorted[i];
let sorted = [o for ([,o] in Iterator(options))]
.sort(function (a, b) String.localeCompare(a.name, b.name));
return (v for ([k, v] in Iterator(sorted)));
},
add: function (names, description, type, defaultValue, extraInfo)
@@ -896,22 +897,18 @@ liberator.Options = function () //{{{
if (!option)
return false;
for (let opt in Iterator(this))
if (option.name in options)
{
if (opt.name == option.name)
{
// never replace for now
liberator.log("Warning: '" + names[0] + "' already exists, NOT replacing existing option.", 1);
return false;
}
// 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"]:
this.__defineGetter__(option.name, function () option.value);
this.__defineSetter__(option.name, function (value) { option.value = value; });
// TODO: sort option
options.push(option);
options[option.name] = option;
return true;
},
@@ -920,10 +917,13 @@ liberator.Options = function () //{{{
if (!scope)
scope = liberator.options.OPTION_SCOPE_BOTH;
for (let i = 0; i < options.length; i++)
if (name in options && (options[name].scope & scope))
return options[name];
for (let [,opt] in Iterator(options))
{
if (options[i].hasName(name) && (options[i].scope & scope))
return options[i];
if (opt.hasName(name) && (opt.scope & scope))
return opt;
}
return null;

View File

@@ -144,7 +144,7 @@ liberator.CommandLine = function () //{{{
var promptCompleter = null;
liberator.registerCallback("change", liberator.modes.EX, function (command) {
if (liberator.options["wildoptions"].indexOf("auto") >= 0)
if (liberator.options.get("wildoptions").has("auto"))
autocompleteTimer.tell(command);
else
completionIndex = UNINITIALIZED;
@@ -570,7 +570,7 @@ liberator.CommandLine = function () //{{{
// open the completion list automatically if wanted
if (/\s/.test(cmd) &&
liberator.options["wildoptions"].indexOf("auto") >= 0 &&
liberator.options.get("wildoptions").has("auto") >= 0 &&
extendedMode == liberator.modes.EX)
{
var [start, compl] = liberator.completion.ex(cmd);

View File

@@ -261,8 +261,8 @@ liberator.config = { //{{{
function ()
{
liberator.open("chrome://mozapps/content/downloads/downloads.xul",
(liberator.options["newtab"] == "all" || liberator.options["newtab"].split(",").indexOf("downloads") != -1) ?
liberator.NEW_TAB : liberator.CURRENT_TAB);
liberator.options.get("newtab").has("all", "downloads")
? liberator.NEW_TAB : liberator.CURRENT_TAB);
},
{ argCount: "0" });