mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-04-10 18:23:34 +02:00
Add Option.has(). Improve JS completion.
This commit is contained in:
@@ -308,6 +308,7 @@ liberator.Completion = function () //{{{
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
liberator.dump("eval(" + liberator.util.escapeString(arg) + ")");
|
||||||
return window.eval(arg);
|
return window.eval(arg);
|
||||||
}
|
}
|
||||||
catch(e) {}
|
catch(e) {}
|
||||||
@@ -345,7 +346,7 @@ liberator.Completion = function () //{{{
|
|||||||
if (["string", "number", "boolean"].indexOf(type) > -1)
|
if (["string", "number", "boolean"].indexOf(type) > -1)
|
||||||
type += ": " + String(v).replace("\n", "\\n", "g");
|
type += ": " + String(v).replace("\n", "\\n", "g");
|
||||||
if (type == "function")
|
if (type == "function")
|
||||||
type += ": " + v.toSource.replace(/\{.*/, "{ ... }");
|
type += ": " + String(v).replace(/{(.|\n)*/, "{ ... }");
|
||||||
|
|
||||||
compl.push([k, type]);
|
compl.push([k, type]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ liberator.AutoCommands = function () //{{{
|
|||||||
{
|
{
|
||||||
let events = liberator.options["eventignore"].split(",");
|
let events = liberator.options["eventignore"].split(",");
|
||||||
|
|
||||||
if (events.some(function (e) e == "all" || e == event))
|
if (liberator.options.get("eventignore").has("all", event))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let autoCmds = store.filter(function (autoCmd) autoCmd.event == event);
|
let autoCmds = store.filter(function (autoCmd) autoCmd.event == event);
|
||||||
|
|||||||
@@ -155,9 +155,8 @@ const liberator = (function () //{{{
|
|||||||
function ()
|
function ()
|
||||||
{
|
{
|
||||||
liberator.open("chrome://mozapps/content/extensions/extensions.xul",
|
liberator.open("chrome://mozapps/content/extensions/extensions.xul",
|
||||||
(liberator.options["newtab"] &&
|
(liberator.options["newtab"] && liberator.options.get("newtab").has("all", "addons"))
|
||||||
(liberator.options["newtab"] == "all" || liberator.options["newtab"].split(",").indexOf("addons") != -1)) ?
|
? liberator.NEW_TAB: liberator.CURRENT_TAB);
|
||||||
liberator.NEW_TAB: liberator.CURRENT_TAB);
|
|
||||||
},
|
},
|
||||||
{ argCount: "0" });
|
{ argCount: "0" });
|
||||||
|
|
||||||
@@ -329,9 +328,8 @@ const liberator = (function () //{{{
|
|||||||
if (special) // open javascript console
|
if (special) // open javascript console
|
||||||
{
|
{
|
||||||
liberator.open("chrome://global/content/console.xul",
|
liberator.open("chrome://global/content/console.xul",
|
||||||
(liberator.options["newtab"] &&
|
(liberator.options["newtab"] && liberator.options.get("newtab").has("all", "javascript"))
|
||||||
(liberator.options["newtab"] == "all" || liberator.options["newtab"].split(",").indexOf("javascript") != -1)) ?
|
? liberator.NEW_TAB : liberator.CURRENT_TAB);
|
||||||
liberator.NEW_TAB : liberator.CURRENT_TAB);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -889,9 +887,8 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
help: function (topic)
|
help: function (topic)
|
||||||
{
|
{
|
||||||
var where = (liberator.options["newtab"] && (liberator.options["newtab"] == "all" ||
|
var where = (liberator.options["newtab"] && liberator.options.get("newtab").has("all", "help"))
|
||||||
liberator.options["newtab"].split(",").indexOf("help") != -1)) ?
|
? liberator.NEW_TAB : liberator.CURRENT_TAB;
|
||||||
liberator.NEW_TAB : liberator.CURRENT_TAB;
|
|
||||||
|
|
||||||
if (!topic)
|
if (!topic)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -100,15 +100,9 @@ liberator.Option = function (names, description, type, defaultValue, extraInfo)
|
|||||||
|
|
||||||
this.set = function (newValue, scope)
|
this.set = function (newValue, scope)
|
||||||
{
|
{
|
||||||
if (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
|
return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
scope = this.scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.setter)
|
if (this.setter)
|
||||||
{
|
{
|
||||||
@@ -130,8 +124,16 @@ liberator.Option = function (names, description, type, defaultValue, extraInfo)
|
|||||||
this.hasChanged = true;
|
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.__defineSetter__("value", this.set);
|
||||||
|
|
||||||
this.hasName = function (name)
|
this.hasName = function (name)
|
||||||
@@ -162,7 +164,7 @@ liberator.Options = function () //{{{
|
|||||||
|
|
||||||
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
||||||
.getService(Components.interfaces.nsIPrefBranch);
|
.getService(Components.interfaces.nsIPrefBranch);
|
||||||
var options = [];
|
var options = {};
|
||||||
|
|
||||||
function optionObserver(key, event, option)
|
function optionObserver(key, event, option)
|
||||||
{
|
{
|
||||||
@@ -368,9 +370,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.get("newtab").has("all", "prefs"))
|
||||||
(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
|
||||||
{
|
{
|
||||||
@@ -881,9 +882,9 @@ liberator.Options = function () //{{{
|
|||||||
|
|
||||||
__iterator__: function ()
|
__iterator__: function ()
|
||||||
{
|
{
|
||||||
let sorted = options.sort(function (opt1, opt2) opt1.name > opt2.name);
|
let sorted = [o for ([,o] in Iterator(options))]
|
||||||
for (let i = 0; i < sorted.length; i++)
|
.sort(function (a, b) String.localeCompare(a.name, b.name));
|
||||||
yield sorted[i];
|
return (v for ([k, v] in Iterator(sorted)));
|
||||||
},
|
},
|
||||||
|
|
||||||
add: function (names, description, type, defaultValue, extraInfo)
|
add: function (names, description, type, defaultValue, extraInfo)
|
||||||
@@ -896,22 +897,18 @@ liberator.Options = function () //{{{
|
|||||||
if (!option)
|
if (!option)
|
||||||
return false;
|
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);
|
||||||
// never replace for now
|
return false;
|
||||||
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 () option.value);
|
this.__defineGetter__(option.name, function () option.value);
|
||||||
this.__defineSetter__(option.name, function (value) { option.value = value; });
|
this.__defineSetter__(option.name, function (value) { option.value = value; });
|
||||||
|
|
||||||
// TODO: sort option
|
options[option.name] = option;
|
||||||
options.push(option);
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -920,10 +917,13 @@ liberator.Options = function () //{{{
|
|||||||
if (!scope)
|
if (!scope)
|
||||||
scope = liberator.options.OPTION_SCOPE_BOTH;
|
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))
|
if (opt.hasName(name) && (opt.scope & scope))
|
||||||
return options[i];
|
return opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ liberator.CommandLine = function () //{{{
|
|||||||
var promptCompleter = null;
|
var promptCompleter = null;
|
||||||
|
|
||||||
liberator.registerCallback("change", liberator.modes.EX, function (command) {
|
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);
|
autocompleteTimer.tell(command);
|
||||||
else
|
else
|
||||||
completionIndex = UNINITIALIZED;
|
completionIndex = UNINITIALIZED;
|
||||||
@@ -570,7 +570,7 @@ liberator.CommandLine = function () //{{{
|
|||||||
|
|
||||||
// open the completion list automatically if wanted
|
// open the completion list automatically if wanted
|
||||||
if (/\s/.test(cmd) &&
|
if (/\s/.test(cmd) &&
|
||||||
liberator.options["wildoptions"].indexOf("auto") >= 0 &&
|
liberator.options.get("wildoptions").has("auto") >= 0 &&
|
||||||
extendedMode == liberator.modes.EX)
|
extendedMode == liberator.modes.EX)
|
||||||
{
|
{
|
||||||
var [start, compl] = liberator.completion.ex(cmd);
|
var [start, compl] = liberator.completion.ex(cmd);
|
||||||
|
|||||||
@@ -261,8 +261,8 @@ liberator.config = { //{{{
|
|||||||
function ()
|
function ()
|
||||||
{
|
{
|
||||||
liberator.open("chrome://mozapps/content/downloads/downloads.xul",
|
liberator.open("chrome://mozapps/content/downloads/downloads.xul",
|
||||||
(liberator.options["newtab"] == "all" || liberator.options["newtab"].split(",").indexOf("downloads") != -1) ?
|
liberator.options.get("newtab").has("all", "downloads")
|
||||||
liberator.NEW_TAB : liberator.CURRENT_TAB);
|
? liberator.NEW_TAB : liberator.CURRENT_TAB);
|
||||||
},
|
},
|
||||||
{ argCount: "0" });
|
{ argCount: "0" });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user