mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 11:18:00 +01:00
Backed out changeset ccb7eca3e069
This commit is contained in:
@@ -1887,16 +1887,14 @@ var Buffer = Module("buffer", {
|
|||||||
mappings.add([modes.NORMAL], ["]]", "<next-page>"],
|
mappings.add([modes.NORMAL], ["]]", "<next-page>"],
|
||||||
"Follow the link labeled 'next' or '>' if it exists",
|
"Follow the link labeled 'next' or '>' if it exists",
|
||||||
function (args) {
|
function (args) {
|
||||||
buffer.findLink("next", options.get("nextpattern").get(buffer.focusedFrame),
|
buffer.findLink("next", options["nextpattern"], (args.count || 1) - 1, true);
|
||||||
(args.count || 1) - 1, true);
|
|
||||||
},
|
},
|
||||||
{ count: true });
|
{ count: true });
|
||||||
|
|
||||||
mappings.add([modes.NORMAL], ["[[", "<previous-page>"],
|
mappings.add([modes.NORMAL], ["[[", "<previous-page>"],
|
||||||
"Follow the link labeled 'prev', 'previous' or '<' if it exists",
|
"Follow the link labeled 'prev', 'previous' or '<' if it exists",
|
||||||
function (args) {
|
function (args) {
|
||||||
buffer.findLink("previous", options.get("previouspattern").get(buffer.focusedFrame),
|
buffer.findLink("previous", options["previouspattern"], (args.count || 1) - 1, true);
|
||||||
(args.count || 1) - 1, true);
|
|
||||||
},
|
},
|
||||||
{ count: true });
|
{ count: true });
|
||||||
|
|
||||||
@@ -2054,23 +2052,19 @@ var Buffer = Module("buffer", {
|
|||||||
"The current buffer's character encoding",
|
"The current buffer's character encoding",
|
||||||
"string", "UTF-8",
|
"string", "UTF-8",
|
||||||
{
|
{
|
||||||
scope: Option.SCOPE_BUFFER,
|
scope: Option.SCOPE_LOCAL,
|
||||||
getter: function (val, context) util.docShell(context.content).QueryInterface(Ci.nsIDocCharset).charset,
|
getter: function () config.browser.docShell.QueryInterface(Ci.nsIDocCharset).charset,
|
||||||
setter: function (val, context) {
|
setter: function (val) {
|
||||||
if (options["encoding"] == val)
|
if (options["encoding"] == val)
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
// Stolen from browser.jar/content/browser/browser.js, more or less.
|
// Stolen from browser.jar/content/browser/browser.js, more or less.
|
||||||
try {
|
try {
|
||||||
let docShell = util.docShell(context.content).QueryInterface(Ci.nsIDocCharset);
|
config.browser.docShell.QueryInterface(Ci.nsIDocCharset).charset = val;
|
||||||
|
PlacesUtils.history.setCharsetForURI(getWebNavigation().currentURI, val);
|
||||||
docShell.charset = val;
|
window.getWebNavigation().reload(Ci.nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
|
||||||
PlacesUtils.history.setCharsetForURI(docShell.currentURI, val);
|
|
||||||
docShell.reload(docShell.LOAD_FLAGS_CHARSET_CHANGE);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
dactyl.reportError(e);
|
|
||||||
}
|
}
|
||||||
|
catch (e) { dactyl.reportError(e); }
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
completer: function (context) completion.charset(context)
|
completer: function (context) completion.charset(context)
|
||||||
@@ -2139,12 +2133,8 @@ var Buffer = Module("buffer", {
|
|||||||
"Show current website without styling defined by the author",
|
"Show current website without styling defined by the author",
|
||||||
"boolean", false,
|
"boolean", false,
|
||||||
{
|
{
|
||||||
scope: Option.SCOPE_TAB,
|
setter: function (value) config.browser.markupDocumentViewer.authorStyleDisabled = value,
|
||||||
setter: function (value, context) {
|
getter: function () config.browser.markupDocumentViewer.authorStyleDisabled
|
||||||
if (context.browser)
|
|
||||||
context.browser.markupDocumentViewer.authorStyleDisabled = value
|
|
||||||
},
|
|
||||||
getter: function (value, context) context.browser && context.browser.markupDocumentViewer.authorStyleDisabled
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1500,8 +1500,6 @@ update(iter, {
|
|||||||
nth: function nth(iter, pred, n, self) {
|
nth: function nth(iter, pred, n, self) {
|
||||||
if (typeof pred === "number")
|
if (typeof pred === "number")
|
||||||
[pred, n] = [function () true, pred]; // Hack.
|
[pred, n] = [function () true, pred]; // Hack.
|
||||||
if (n === undefined)
|
|
||||||
n = 0;
|
|
||||||
|
|
||||||
for (let elem in iter)
|
for (let elem in iter)
|
||||||
if (pred.call(self, elem) && n-- === 0)
|
if (pred.call(self, elem) && n-- === 0)
|
||||||
@@ -1643,8 +1641,6 @@ var array = Class("array", Array, {
|
|||||||
* given predicate.
|
* given predicate.
|
||||||
*/
|
*/
|
||||||
nth: function nth(ary, pred, n, self) {
|
nth: function nth(ary, pred, n, self) {
|
||||||
if (n === undefined)
|
|
||||||
n = 0;
|
|
||||||
for (let elem in values(ary))
|
for (let elem in values(ary))
|
||||||
if (pred.call(self, elem) && n-- === 0)
|
if (pred.call(self, elem) && n-- === 0)
|
||||||
return elem;
|
return elem;
|
||||||
|
|||||||
@@ -97,15 +97,13 @@ var Contexts = Module("contexts", {
|
|||||||
this.builtin.modifiable = false;
|
this.builtin.modifiable = false;
|
||||||
|
|
||||||
this.GroupFlag = Class("GroupFlag", CommandOption, {
|
this.GroupFlag = Class("GroupFlag", CommandOption, {
|
||||||
init: function (name, defaultValue) {
|
init: function (name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
this.type = ArgType("group", function (group) {
|
this.type = ArgType("group", function (group) {
|
||||||
return isString(group) ? contexts.getGroup(group, name)
|
return isString(group) ? contexts.getGroup(group, name)
|
||||||
: group[name];
|
: group[name];
|
||||||
});
|
});
|
||||||
|
|
||||||
this.defaultValue = defaultValue;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get toStringParams() [this.name],
|
get toStringParams() [this.name],
|
||||||
@@ -114,9 +112,7 @@ var Contexts = Module("contexts", {
|
|||||||
|
|
||||||
description: "Group to which to add",
|
description: "Group to which to add",
|
||||||
|
|
||||||
get default() let (group = contexts.context && contexts.context.group)
|
get default() (contexts.context && contexts.context.group || contexts.user)[this.name],
|
||||||
!group && this.defaultValue !== undefined ? this.defaultValue
|
|
||||||
: (group || contexts.user)[this.name],
|
|
||||||
|
|
||||||
completer: function (context) modules.completion.group(context)
|
completer: function (context) modules.completion.group(context)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -673,7 +673,8 @@ var RangeFind = Class("RangeFind", {
|
|||||||
this.range = range;
|
this.range = range;
|
||||||
this.document = range.startContainer.ownerDocument;
|
this.document = range.startContainer.ownerDocument;
|
||||||
this.window = this.document.defaultView;
|
this.window = this.document.defaultView;
|
||||||
this.docShell = util.docShell(this.window);
|
this.docShell = this.window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
|
||||||
|
.QueryInterface(Ci.nsIDocShell);
|
||||||
|
|
||||||
if (this.selection == null)
|
if (this.selection == null)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -102,11 +102,9 @@ var Option = Class("Option", {
|
|||||||
options.cleanupPrefs.set(this.name, value);
|
options.cleanupPrefs.set(this.name, value);
|
||||||
},
|
},
|
||||||
|
|
||||||
/** @property {Window|OptionHive|null} The default context for this option. */
|
/** @property {value} The option's global value. @see #scope */
|
||||||
context: null,
|
get globalValue() { try { return options.store.get(this.name, {}).value; } catch (e) { util.reportError(e); throw e; } },
|
||||||
|
set globalValue(val) { options.store.set(this.name, { value: val, time: Date.now() }); },
|
||||||
/** @property {[OptionHive]|null} The default hives for this option. */
|
|
||||||
hives: null,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns *value* as an array of parsed values if the option type is
|
* Returns *value* as an array of parsed values if the option type is
|
||||||
@@ -125,141 +123,65 @@ var Option = Class("Option", {
|
|||||||
*/
|
*/
|
||||||
stringify: function stringify(vals) Commands.quote(vals),
|
stringify: function stringify(vals) Commands.quote(vals),
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a context object for the given window.
|
|
||||||
*
|
|
||||||
* @param {Window} context The context for which to get this option value.
|
|
||||||
* @optional
|
|
||||||
* @returns {object}
|
|
||||||
* window: The global window for which to get the value.
|
|
||||||
* tab: The tab for which to get the value.
|
|
||||||
* content: The content window for which to get the value.
|
|
||||||
* hive: The option hive containing the value.
|
|
||||||
*/
|
|
||||||
getContext: function getContext(context) {
|
|
||||||
if (context instanceof OptionHive)
|
|
||||||
context = undefined;
|
|
||||||
|
|
||||||
if (context === undefined)
|
|
||||||
context = this.modules.content;
|
|
||||||
|
|
||||||
if (!context && this.scope & Option.SCOPE_BUFFER)
|
|
||||||
context = this.modules.buffer.focusedFrame;
|
|
||||||
|
|
||||||
let res = {};
|
|
||||||
if (context) {
|
|
||||||
if (this.scope & Option.SCOPE_WINDOW)
|
|
||||||
res.window = util.topWindow(context);
|
|
||||||
if (this.scope & Option.SCOPE_BUFFER)
|
|
||||||
res.content = context;
|
|
||||||
if (this.scope & Option.SCOPE_TAB) {
|
|
||||||
res.tab = array.nth(this.modules.tabs.allTabs,
|
|
||||||
function (tab) tab.linkedBrowser.contentWindow
|
|
||||||
== this,
|
|
||||||
0, context.top);
|
|
||||||
res.browser = res.tab && res.tab.linkedBrowser;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the option's value as an array of parsed values if the option
|
* Returns the option's value as an array of parsed values if the option
|
||||||
* type is "charlist" or "stringlist" or else the simple value.
|
* type is "charlist" or "stringlist" or else the simple value.
|
||||||
*
|
*
|
||||||
* @param {Window|OptionHive} context The context for which to get this option value.
|
* @param {number} scope The scope to return these values from (see
|
||||||
* @optional
|
* {@link Option#scope}).
|
||||||
* @param {boolean} skipGetter If true, return the saved value, not
|
* @returns {value|[string]}
|
||||||
* the return value from the getter.
|
|
||||||
* @see #getContext
|
|
||||||
*/
|
*/
|
||||||
get: function get(context, skipGetter) {
|
get: function get(scope) {
|
||||||
if (context === undefined)
|
if (scope) {
|
||||||
context = this.context;
|
if ((scope & this.scope) == 0) // option doesn't exist in this scope
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
scope = this.scope;
|
||||||
|
|
||||||
let hive = this._valueHive(context);
|
let values;
|
||||||
let value = hive ? hive.values[this.name] : this.globalValue;
|
|
||||||
if (this.getter && !skipGetter)
|
|
||||||
return util.trapErrors(this.getter, this, value,
|
|
||||||
this.getContext(context));
|
|
||||||
|
|
||||||
return value;
|
/*
|
||||||
},
|
if (config.has("tabs") && (scope & Option.SCOPE_LOCAL))
|
||||||
|
values = tabs.options[this.name];
|
||||||
|
*/
|
||||||
|
if ((scope & Option.SCOPE_GLOBAL) && (values == undefined))
|
||||||
|
values = this.globalValue;
|
||||||
|
|
||||||
_valueHive: function _valueHive(context) {
|
if (this.getter)
|
||||||
let { contexts, options } = this.modules;
|
return util.trapErrors(this.getter, this, values);
|
||||||
let hives = this.hives || options.hives;
|
|
||||||
|
|
||||||
context = context || this.context;
|
return values;
|
||||||
if (context instanceof Ci.nsIDOMWindow)
|
|
||||||
hives = array(contexts.matchingGroups(null, context.document).options);
|
|
||||||
else if (context instanceof OptionHive)
|
|
||||||
hives = array([context]);
|
|
||||||
|
|
||||||
return hives.nth(function (h) h.has(this), 0, this.name);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the option's value from an array of values if the option type is
|
* Sets the option's value from an array of values if the option type is
|
||||||
* "charlist" or "stringlist" or else the simple value.
|
* "charlist" or "stringlist" or else the simple value.
|
||||||
*
|
*
|
||||||
* @param {OptionHive} hive The hive for which to set this value.
|
* @param {number} scope The scope to apply these values to (see
|
||||||
* @optional
|
* {@link Option#scope}).
|
||||||
* @see #getContext
|
|
||||||
*/
|
*/
|
||||||
set: function set(newValue, hive) {
|
set: function set(newValues, scope, skipGlobal) {
|
||||||
|
scope = scope || this.scope;
|
||||||
|
if ((scope & this.scope) == 0) // option doesn't exist in this scope
|
||||||
|
return;
|
||||||
|
|
||||||
hive = hive || this.hives && this.hives[0];
|
if (this.setter)
|
||||||
if (hive) {
|
newValues = this.setter(newValues);
|
||||||
hive.values[this.name] = newValue;
|
if (newValues === undefined)
|
||||||
hive.setFrom[this.name] = null;
|
return;
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.globalValue = newValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*
|
||||||
this.runSetters(hive);
|
if (config.has("tabs") && (scope & Option.SCOPE_LOCAL))
|
||||||
|
tabs.options[this.name] = newValues;
|
||||||
|
*/
|
||||||
|
if ((scope & Option.SCOPE_GLOBAL) && !skipGlobal)
|
||||||
|
this.globalValue = newValues;
|
||||||
|
|
||||||
this.hasChanged = true;
|
this.hasChanged = true;
|
||||||
},
|
this.setFrom = null;
|
||||||
|
|
||||||
_runSetter: function _setter(window) {
|
// dactyl.triggerObserver("options." + this.name, newValues);
|
||||||
let opt = util.topWindow(window).dactyl.modules.options.get(this.name);
|
|
||||||
if (opt) {
|
|
||||||
let context = opt.getContext(window);
|
|
||||||
let value = opt.get(window, true)
|
|
||||||
if (!opt.getter || value != opt.getter(value, context))
|
|
||||||
opt.setter(value, context);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
runSetters: function runSetters(hive) {
|
|
||||||
if (this.setter) {
|
|
||||||
if (this.scope & Option.SCOPE_GLOBAL)
|
|
||||||
this.setter(this.get(null, true), this.getContext(null));
|
|
||||||
|
|
||||||
if (this.scope & Option.SCOPE_WINDOW)
|
|
||||||
for (let window in values(overlay.windows))
|
|
||||||
this._runSetter(window);
|
|
||||||
|
|
||||||
if (this.scope & Option.SCOPE_TAB)
|
|
||||||
for (let window in values(overlay.windows))
|
|
||||||
for (let tab in values(window.dactyl.modules.tabs.allTabs))
|
|
||||||
this._runSetter(tab.linkedBrowser.contentWindow);
|
|
||||||
|
|
||||||
if (this.scope & Option.SCOPE_BUFFER)
|
|
||||||
if (hive)
|
|
||||||
for (let doc in util.iterDocuments(["content"])) {
|
|
||||||
let win = doc.defaultView;
|
|
||||||
if ("dactyl" in util.topWindow(win) &&
|
|
||||||
hive.filter(doc.documentURIObject || util.newURI(doc.documentURI),
|
|
||||||
doc))
|
|
||||||
this._runSetter(win);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
this._runSetter(this.modules.buffer.focusedFrame);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getValues: deprecated("Option#get", "get"),
|
getValues: deprecated("Option#get", "get"),
|
||||||
@@ -364,9 +286,13 @@ var Option = Class("Option", {
|
|||||||
type: null,
|
type: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} The scope of the option.
|
* @property {number} The scope of the option. This can be local, global,
|
||||||
|
* or both.
|
||||||
|
* @see Option#SCOPE_LOCAL
|
||||||
|
* @see Option#SCOPE_GLOBAL
|
||||||
|
* @see Option#SCOPE_BOTH
|
||||||
*/
|
*/
|
||||||
scope: Class.Memoize(function () Option.SCOPE_WINDOW),
|
scope: 1, // Option.SCOPE_GLOBAL // XXX set to BOTH by default someday? - kstep
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {function(CompletionContext, Args)} This option's completer.
|
* @property {function(CompletionContext, Args)} This option's completer.
|
||||||
@@ -453,37 +379,37 @@ var Option = Class("Option", {
|
|||||||
*/
|
*/
|
||||||
hasChanged: false,
|
hasChanged: false,
|
||||||
|
|
||||||
_set: function _set(obj) {
|
|
||||||
update(options.store.get(this.name, {}), obj);
|
|
||||||
},
|
|
||||||
|
|
||||||
/** @property {value} The option's global value. */
|
|
||||||
get globalValue() { try { return options.store.get(this.name, {}).value; } catch (e) { util.reportError(e); throw e; } },
|
|
||||||
set globalValue(val) { this._set({ value: val, time: Date.now() }); },
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the timestamp when the option's value was last changed.
|
* Returns the timestamp when the option's value was last changed.
|
||||||
*/
|
*/
|
||||||
get lastSet() options.store.get(this.name).time,
|
get lastSet() options.store.get(this.name).time,
|
||||||
set lastSet(val) { this._set({ time: Date.now() }); },
|
set lastSet(val) { options.store.set(this.name, { value: this.globalValue, time: Date.now() }); },
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {nsIFile} The script in which this option was last set. null
|
* @property {nsIFile} The script in which this option was last set. null
|
||||||
* implies an interactive command.
|
* implies an interactive command.
|
||||||
*/
|
*/
|
||||||
get setFrom() let (hive = this._valueHive())
|
setFrom: null
|
||||||
hive ? hive.setFrom[this.name]
|
|
||||||
: options.store.get(this.name, {}).setFrom,
|
|
||||||
|
|
||||||
set setFrom(val) let (hive = this._valueHive())
|
|
||||||
hive ? (hive.setFrom[this.name] = val)
|
|
||||||
: this._set({ setFrom: val })
|
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
|
/**
|
||||||
|
* @property {number} Global option scope.
|
||||||
|
* @final
|
||||||
|
*/
|
||||||
SCOPE_GLOBAL: 1,
|
SCOPE_GLOBAL: 1,
|
||||||
SCOPE_WINDOW: 2,
|
|
||||||
SCOPE_TAB: 3,
|
/**
|
||||||
SCOPE_BUFFER: 4,
|
* @property {number} Local option scope. Options in this scope only
|
||||||
|
* apply to the current tab/buffer.
|
||||||
|
* @final
|
||||||
|
*/
|
||||||
|
SCOPE_LOCAL: 2,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number} Both local and global option scope.
|
||||||
|
* @final
|
||||||
|
*/
|
||||||
|
SCOPE_BOTH: 3,
|
||||||
|
|
||||||
has: {
|
has: {
|
||||||
toggleAll: function toggleAll() toggleAll.supercall(this, "all") ^ !!toggleAll.superapply(this, arguments),
|
toggleAll: function toggleAll() toggleAll.supercall(this, "all") ^ !!toggleAll.superapply(this, arguments),
|
||||||
@@ -834,7 +760,6 @@ var OptionHive = Class("OptionHive", Contexts.Hive, {
|
|||||||
init: function init(group) {
|
init: function init(group) {
|
||||||
init.supercall(this, group);
|
init.supercall(this, group);
|
||||||
this.values = {};
|
this.values = {};
|
||||||
this.setFrom = {};
|
|
||||||
this.has = Set.has(this.values);
|
this.has = Set.has(this.values);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -861,6 +786,12 @@ var Options = Module("options", {
|
|||||||
this._optionMap = {};
|
this._optionMap = {};
|
||||||
|
|
||||||
storage.newMap("options", { store: false });
|
storage.newMap("options", { store: false });
|
||||||
|
storage.addObserver("options", function optionObserver(key, event, option) {
|
||||||
|
// Trigger any setters.
|
||||||
|
let opt = self.get(option);
|
||||||
|
if (event == "change" && opt)
|
||||||
|
opt.set(opt.globalValue, Option.SCOPE_GLOBAL, true);
|
||||||
|
}, window);
|
||||||
|
|
||||||
services["dactyl:"].pages["options.dtd"] = function () [null,
|
services["dactyl:"].pages["options.dtd"] = function () [null,
|
||||||
util.makeDTD(
|
util.makeDTD(
|
||||||
@@ -882,8 +813,13 @@ var Options = Module("options", {
|
|||||||
* *onlyNonDefault* is specified.
|
* *onlyNonDefault* is specified.
|
||||||
*
|
*
|
||||||
* @param {function(Option)} filter Limit the list
|
* @param {function(Option)} filter Limit the list
|
||||||
|
* @param {number} scope Only list options in this scope (see
|
||||||
|
* {@link Option#scope}).
|
||||||
*/
|
*/
|
||||||
list: function list(filter) {
|
list: function list(filter, scope) {
|
||||||
|
if (!scope)
|
||||||
|
scope = Option.SCOPE_BOTH;
|
||||||
|
|
||||||
function opts(opt) {
|
function opts(opt) {
|
||||||
for (let opt in Iterator(this)) {
|
for (let opt in Iterator(this)) {
|
||||||
let option = {
|
let option = {
|
||||||
@@ -896,6 +832,8 @@ var Options = Module("options", {
|
|||||||
|
|
||||||
if (filter && !filter(opt))
|
if (filter && !filter(opt))
|
||||||
continue;
|
continue;
|
||||||
|
if (!(opt.scope & scope))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (opt.type == "boolean") {
|
if (opt.type == "boolean") {
|
||||||
if (!opt.value)
|
if (!opt.value)
|
||||||
@@ -997,26 +935,20 @@ var Options = Module("options", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the option with *name* in the specified *context*.
|
* Returns the option with *name* in the specified *scope*.
|
||||||
*
|
*
|
||||||
* @param {string} name The option's name.
|
* @param {string} name The option's name.
|
||||||
* @param {Window|OptionHive} context The context for which to get
|
* @param {number} scope The option's scope (see {@link Option#scope}).
|
||||||
* this option.
|
* @optional
|
||||||
* @returns {Option} The matching option.
|
* @returns {Option} The matching option.
|
||||||
*/
|
*/
|
||||||
get: function get(name, context) {
|
get: function get(name, scope) {
|
||||||
let opt = null;
|
if (!scope)
|
||||||
if (Set.has(this._optionMap, name)) {
|
scope = Option.SCOPE_BOTH;
|
||||||
opt = this._optionMap[name];
|
|
||||||
|
|
||||||
if (context) {
|
if (this._optionMap[name] && (this._optionMap[name].scope & scope))
|
||||||
opt = Object.create(opt);
|
return this._optionMap[name];
|
||||||
if (context instanceof OptionHive)
|
return null;
|
||||||
opt.hives = array([context]);
|
|
||||||
opt.context = context;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return opt;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1029,28 +961,25 @@ var Options = Module("options", {
|
|||||||
* @returns {Object} The parsed command object.
|
* @returns {Object} The parsed command object.
|
||||||
*/
|
*/
|
||||||
parseOpt: function parseOpt(args, modifiers) {
|
parseOpt: function parseOpt(args, modifiers) {
|
||||||
modifiers = modifiers || {};
|
|
||||||
|
|
||||||
let res = {};
|
let res = {};
|
||||||
let matches, prefix, postfix;
|
let matches, prefix, postfix;
|
||||||
|
|
||||||
[matches, prefix, res.name, postfix, res.valueGiven, res.operator, res.stringValue] =
|
[matches, prefix, res.name, postfix, res.valueGiven, res.operator, res.value] =
|
||||||
args.match(/^\s*(no|inv)?([^=]+?)([?&!])?\s*(([-+^]?)=(.*))?\s*$/) || [];
|
args.match(/^\s*(no|inv)?([^=]+?)([?&!])?\s*(([-+^]?)=(.*))?\s*$/) || [];
|
||||||
|
|
||||||
res.args = args;
|
res.args = args;
|
||||||
res.onlyNonDefault = false; // used for :set to print non-default options
|
res.onlyNonDefault = false; // used for :set to print non-default options
|
||||||
res.context = modifiers.context;
|
|
||||||
if (!args) {
|
if (!args) {
|
||||||
res.name = "all";
|
res.name = "all";
|
||||||
res.onlyNonDefault = true;
|
res.onlyNonDefault = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matches) {
|
if (matches) {
|
||||||
if (res.option = this.get(res.name, res.context)) {
|
if (res.option = this.get(res.name, res.scope)) {
|
||||||
if (prefix === "no" && res.option.type !== "boolean")
|
if (prefix === "no" && res.option.type !== "boolean")
|
||||||
res.option = null;
|
res.option = null;
|
||||||
}
|
}
|
||||||
else if (res.option = this.get(prefix + res.name, res.context)) {
|
else if (res.option = this.get(prefix + res.name, res.scope)) {
|
||||||
res.name = prefix + res.name;
|
res.name = prefix + res.name;
|
||||||
prefix = "";
|
prefix = "";
|
||||||
}
|
}
|
||||||
@@ -1065,16 +994,18 @@ var Options = Module("options", {
|
|||||||
res.reset = (postfix == "&");
|
res.reset = (postfix == "&");
|
||||||
res.unsetBoolean = (prefix == "no");
|
res.unsetBoolean = (prefix == "no");
|
||||||
|
|
||||||
|
res.scope = modifiers && modifiers.scope;
|
||||||
|
|
||||||
if (!res.option)
|
if (!res.option)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
if (res.stringValue === undefined)
|
if (res.value === undefined)
|
||||||
res.stringValue = "";
|
res.value = "";
|
||||||
|
|
||||||
res.optionValue = res.option.get(res.context);
|
res.optionValue = res.option.get(res.scope);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
res.value = res.option.parse(res.stringValue);
|
res.values = res.option.parse(res.value);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
res.error = e;
|
res.error = e;
|
||||||
@@ -1137,55 +1068,7 @@ var Options = Module("options", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
commands.add(["se[t]"],
|
|
||||||
"Set an option",
|
|
||||||
function (args) {
|
|
||||||
setAction(args);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
bang: true,
|
|
||||||
|
|
||||||
completer: setCompleter,
|
|
||||||
|
|
||||||
domains: function domains(args) array.flatten(args.map(function (spec) {
|
|
||||||
try {
|
|
||||||
let opt = modules.options.parseOpt(spec);
|
|
||||||
if (opt.option && opt.option.domains)
|
|
||||||
return opt.option.domains(opt.value);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
util.reportError(e);
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
})),
|
|
||||||
|
|
||||||
keepQuotes: true,
|
|
||||||
|
|
||||||
options: [
|
|
||||||
contexts.GroupFlag("options", null),
|
|
||||||
],
|
|
||||||
|
|
||||||
privateData: function privateData(args) args.some(function (spec) {
|
|
||||||
let opt = modules.options.parseOpt(spec);
|
|
||||||
return opt.option && opt.option.privateData &&
|
|
||||||
(!callable(opt.option.privateData) ||
|
|
||||||
opt.option.privateData(opt.value));
|
|
||||||
}),
|
|
||||||
|
|
||||||
serialize: function () [
|
|
||||||
{
|
|
||||||
command: this.name,
|
|
||||||
literalArg: [opt.type == "boolean" ? (opt.value ? "" : "no") + opt.name
|
|
||||||
: opt.name + "=" + opt.stringValue]
|
|
||||||
}
|
|
||||||
for (opt in modules.options)
|
|
||||||
if (!opt.getter)
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
function setAction(args, modifiers) {
|
function setAction(args, modifiers) {
|
||||||
modifiers = modifiers || {};
|
|
||||||
|
|
||||||
let bang = args.bang;
|
let bang = args.bang;
|
||||||
if (!args.length)
|
if (!args.length)
|
||||||
args[0] = "";
|
args[0] = "";
|
||||||
@@ -1253,7 +1136,6 @@ var Options = Module("options", {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifiers.context = args["-group"];
|
|
||||||
let opt = modules.options.parseOpt(arg, modifiers);
|
let opt = modules.options.parseOpt(arg, modifiers);
|
||||||
util.assert(opt, _("command.set.errorParsing", arg));
|
util.assert(opt, _("command.set.errorParsing", arg));
|
||||||
util.assert(!opt.error, _("command.set.errorParsing", opt.error));
|
util.assert(!opt.error, _("command.set.errorParsing", opt.error));
|
||||||
@@ -1280,13 +1162,13 @@ var Options = Module("options", {
|
|||||||
flushList();
|
flushList();
|
||||||
if (opt.option.type === "boolean") {
|
if (opt.option.type === "boolean") {
|
||||||
util.assert(!opt.valueGiven, _("error.invalidArgument", arg));
|
util.assert(!opt.valueGiven, _("error.invalidArgument", arg));
|
||||||
opt.value = !opt.unsetBoolean;
|
opt.values = !opt.unsetBoolean;
|
||||||
}
|
}
|
||||||
else if (/^(string|number)$/.test(opt.option.type) && opt.invert)
|
else if (/^(string|number)$/.test(opt.option.type) && opt.invert)
|
||||||
opt.value = Option.splitList(opt.stringValue);
|
opt.values = Option.splitList(opt.value);
|
||||||
try {
|
try {
|
||||||
var res = opt.option.op(opt.operator || "=", opt.value, opt.scope, opt.invert,
|
var res = opt.option.op(opt.operator || "=", opt.values, opt.scope, opt.invert,
|
||||||
opt.stringValue);
|
opt.value);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
res = e;
|
res = e;
|
||||||
@@ -1301,7 +1183,6 @@ var Options = Module("options", {
|
|||||||
|
|
||||||
function setCompleter(context, args, modifiers) {
|
function setCompleter(context, args, modifiers) {
|
||||||
const { completion } = modules;
|
const { completion } = modules;
|
||||||
modifiers = modifiers || {}
|
|
||||||
|
|
||||||
let filter = context.filter;
|
let filter = context.filter;
|
||||||
|
|
||||||
@@ -1312,8 +1193,8 @@ var Options = Module("options", {
|
|||||||
|
|
||||||
context.pushProcessor(0, function (item, text, next) next(item, text.substr(0, 100)));
|
context.pushProcessor(0, function (item, text, next) next(item, text.substr(0, 100)));
|
||||||
context.completions = [
|
context.completions = [
|
||||||
[prefs.get(filter), _("option.currentValue")],
|
[prefs.get(filter), _("option.currentValue")],
|
||||||
[prefs.defaults.get(filter), _("option.defaultValue")]
|
[prefs.defaults.get(filter), _("option.defaultValue")]
|
||||||
].filter(function (k) k[0] != null);
|
].filter(function (k) k[0] != null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -1351,13 +1232,13 @@ var Options = Module("options", {
|
|||||||
if (opt.get || opt.reset || !option || prefix)
|
if (opt.get || opt.reset || !option || prefix)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (!opt.stringValue && !opt.operator && !opt.invert) {
|
if (!opt.value && !opt.operator && !opt.invert) {
|
||||||
context.fork("default", 0, this, function (context) {
|
context.fork("default", 0, this, function (context) {
|
||||||
context.title = ["Extra Completions"];
|
context.title = ["Extra Completions"];
|
||||||
context.pushProcessor(0, function (item, text, next) next(item, text.substr(0, 100)));
|
context.pushProcessor(0, function (item, text, next) next(item, text.substr(0, 100)));
|
||||||
context.completions = [
|
context.completions = [
|
||||||
[option.stringValue, _("option.currentValue")],
|
[option.stringValue, _("option.currentValue")],
|
||||||
[option.stringDefaultValue, _("option.defaultValue")]
|
[option.stringDefaultValue, _("option.defaultValue")]
|
||||||
].filter(function (f) f[0] !== "");
|
].filter(function (f) f[0] !== "");
|
||||||
context.quote = ["", util.identity, ""];
|
context.quote = ["", util.identity, ""];
|
||||||
});
|
});
|
||||||
@@ -1367,7 +1248,7 @@ var Options = Module("options", {
|
|||||||
modules.completion.optionValue(optcontext, opt.name, opt.operator);
|
modules.completion.optionValue(optcontext, opt.name, opt.operator);
|
||||||
|
|
||||||
// Fill in the current values if we're removing
|
// Fill in the current values if we're removing
|
||||||
if (opt.operator == "-" && isArray(opt.value)) {
|
if (opt.operator == "-" && isArray(opt.values)) {
|
||||||
let have = Set([i.text for (i in values(context.allItems.items))]);
|
let have = Set([i.text for (i in values(context.allItems.items))]);
|
||||||
context = context.fork("current-values", 0);
|
context = context.fork("current-values", 0);
|
||||||
context.anchored = optcontext.anchored;
|
context.anchored = optcontext.anchored;
|
||||||
@@ -1454,6 +1335,64 @@ var Options = Module("options", {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
names: ["setl[ocal]"],
|
||||||
|
description: "Set local option",
|
||||||
|
modifiers: { scope: Option.SCOPE_LOCAL }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
names: ["setg[lobal]"],
|
||||||
|
description: "Set global option",
|
||||||
|
modifiers: { scope: Option.SCOPE_GLOBAL }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
names: ["se[t]"],
|
||||||
|
description: "Set an option",
|
||||||
|
modifiers: {},
|
||||||
|
extra: {
|
||||||
|
serialize: function () [
|
||||||
|
{
|
||||||
|
command: this.name,
|
||||||
|
literalArg: [opt.type == "boolean" ? (opt.value ? "" : "no") + opt.name
|
||||||
|
: opt.name + "=" + opt.stringValue]
|
||||||
|
}
|
||||||
|
for (opt in modules.options)
|
||||||
|
if (!opt.getter && !opt.isDefault && (opt.scope & Option.SCOPE_GLOBAL))
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
].forEach(function (params) {
|
||||||
|
commands.add(params.names, params.description,
|
||||||
|
function (args, modifiers) {
|
||||||
|
setAction(args, update(modifiers, params.modifiers));
|
||||||
|
},
|
||||||
|
update({
|
||||||
|
bang: true,
|
||||||
|
completer: setCompleter,
|
||||||
|
domains: function domains(args) array.flatten(args.map(function (spec) {
|
||||||
|
try {
|
||||||
|
let opt = modules.options.parseOpt(spec);
|
||||||
|
if (opt.option && opt.option.domains)
|
||||||
|
return opt.option.domains(opt.values);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
util.reportError(e);
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
})),
|
||||||
|
keepQuotes: true,
|
||||||
|
privateData: function privateData(args) args.some(function (spec) {
|
||||||
|
let opt = modules.options.parseOpt(spec);
|
||||||
|
return opt.option && opt.option.privateData &&
|
||||||
|
(!callable(opt.option.privateData) ||
|
||||||
|
opt.option.privateData(opt.values));
|
||||||
|
})
|
||||||
|
}, params.extra || {}));
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: deprecated. This needs to support "g:"-prefixed globals at a
|
||||||
|
// minimum for now.
|
||||||
commands.add(["unl[et]"],
|
commands.add(["unl[et]"],
|
||||||
"Delete a variable",
|
"Delete a variable",
|
||||||
function (args) {
|
function (args) {
|
||||||
|
|||||||
@@ -299,10 +299,10 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
|
|||||||
overlay.windows = array.uniq(overlay.windows.concat(window), true);
|
overlay.windows = array.uniq(overlay.windows.concat(window), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.dactylWindowVisible)
|
if (overlay.onWindowVisible)
|
||||||
finish();
|
|
||||||
else
|
|
||||||
overlay.onWindowVisible.push(finish);
|
overlay.onWindowVisible.push(finish);
|
||||||
|
else
|
||||||
|
finish();
|
||||||
|
|
||||||
modules.events.listen(window, "unload", function onUnload() {
|
modules.events.listen(window, "unload", function onUnload() {
|
||||||
window.removeEventListener("unload", onUnload.wrapped, false);
|
window.removeEventListener("unload", onUnload.wrapped, false);
|
||||||
@@ -350,7 +350,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
|
|||||||
"xul-window-visible": function () {
|
"xul-window-visible": function () {
|
||||||
if (this.onWindowVisible) {
|
if (this.onWindowVisible) {
|
||||||
this.onWindowVisible.forEach(function (f) f.call(this), this);
|
this.onWindowVisible.forEach(function (f) f.call(this), this);
|
||||||
this.onWindowVisible = [];
|
this.onWindowVisible = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -367,7 +367,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
|
|||||||
|
|
||||||
for (let doc in util.iterDocuments())
|
for (let doc in util.iterDocuments())
|
||||||
if (~["interactive", "complete"].indexOf(doc.readyState)) {
|
if (~["interactive", "complete"].indexOf(doc.readyState)) {
|
||||||
doc.defaultView.dactylWindowVisible = true;
|
this.onWindowVisible = null;
|
||||||
this._loadOverlays(doc.defaultView);
|
this._loadOverlays(doc.defaultView);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -478,16 +478,6 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
dequote: function dequote(pattern, chars)
|
dequote: function dequote(pattern, chars)
|
||||||
pattern.replace(/\\(.)/, function (m0, m1) chars.indexOf(m1) >= 0 ? m1 : m0),
|
pattern.replace(/\\(.)/, function (m0, m1) chars.indexOf(m1) >= 0 ? m1 : m0),
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the nsIDocShell for a given window.
|
|
||||||
*
|
|
||||||
* @param {Window} win The window.
|
|
||||||
* @returns {nsIDocShell}
|
|
||||||
*/
|
|
||||||
docShell: function docShell(win)
|
|
||||||
win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
|
|
||||||
.QueryInterface(Ci.nsIDocShell),
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints a message to the console. If *msg* is an object it is pretty
|
* Prints a message to the console. If *msg* is an object it is pretty
|
||||||
* printed.
|
* printed.
|
||||||
@@ -758,14 +748,11 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
* Iterates over all currently open documents, including all
|
* Iterates over all currently open documents, including all
|
||||||
* top-level window and sub-frames thereof.
|
* top-level window and sub-frames thereof.
|
||||||
*/
|
*/
|
||||||
iterDocuments: function iterDocuments(types) {
|
iterDocuments: function iterDocuments() {
|
||||||
types = types || ["chrome", "content"];
|
|
||||||
types = types.map(function (t) "type" + util.capitalize(t));
|
|
||||||
|
|
||||||
let windows = services.windowMediator.getXULWindowEnumerator(null);
|
let windows = services.windowMediator.getXULWindowEnumerator(null);
|
||||||
while (windows.hasMoreElements()) {
|
while (windows.hasMoreElements()) {
|
||||||
let window = windows.getNext().QueryInterface(Ci.nsIXULWindow);
|
let window = windows.getNext().QueryInterface(Ci.nsIXULWindow);
|
||||||
for each (let type in types) {
|
for each (let type in ["typeChrome", "typeContent"]) {
|
||||||
let docShells = window.docShell.getDocShellEnumerator(Ci.nsIDocShellTreeItem[type],
|
let docShells = window.docShell.getDocShellEnumerator(Ci.nsIDocShellTreeItem[type],
|
||||||
Ci.nsIDocShell.ENUMERATE_FORWARDS);
|
Ci.nsIDocShell.ENUMERATE_FORWARDS);
|
||||||
while (docShells.hasMoreElements())
|
while (docShells.hasMoreElements())
|
||||||
|
|||||||
Reference in New Issue
Block a user