1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-03 02:15:47 +01:00

Make .closure a Proxy and rename .bound

This commit is contained in:
Kris Maglione
2014-03-16 14:32:04 -07:00
parent 03596bd75d
commit af88d531d0
27 changed files with 113 additions and 119 deletions

View File

@@ -233,10 +233,10 @@ var Abbreviations = Module("abbreviations", {
get userHives() this.allHives.filter(h => h !== this.builtin),
get: deprecated("group.abbrevs.get", { get: function get() this.user.closure.get }),
set: deprecated("group.abbrevs.set", { get: function set() this.user.closure.set }),
remove: deprecated("group.abbrevs.remove", { get: function remove() this.user.closure.remove }),
removeAll: deprecated("group.abbrevs.clear", { get: function removeAll() this.user.closure.clear }),
get: deprecated("group.abbrevs.get", { get: function get() this.user.bound.get }),
set: deprecated("group.abbrevs.set", { get: function set() this.user.bound.set }),
remove: deprecated("group.abbrevs.remove", { get: function remove() this.user.bound.remove }),
removeAll: deprecated("group.abbrevs.clear", { get: function removeAll() this.user.bound.clear }),
/**
* Returns the abbreviation for the given *mode* if *text* matches the

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -77,9 +77,9 @@ var AutoCommands = Module("autocommands", {
get activeHives() contexts.allGroups.autocmd.filter(h => h._store.length),
add: deprecated("group.autocmd.add", { get: function add() autocommands.user.closure.add }),
get: deprecated("group.autocmd.get", { get: function get() autocommands.user.closure.get }),
remove: deprecated("group.autocmd.remove", { get: function remove() autocommands.user.closure.remove }),
add: deprecated("group.autocmd.add", { get: function add() autocommands.user.bound.add }),
get: deprecated("group.autocmd.get", { get: function get() autocommands.user.bound.get }),
remove: deprecated("group.autocmd.remove", { get: function remove() autocommands.user.bound.remove }),
/**
* Lists all autocommands with a matching *event*, *regexp* and optionally

View File

@@ -172,7 +172,7 @@ var Bookmarks = Module("bookmarks", {
}
},
isBookmarked: deprecated("bookmarkcache.isBookmarked", { get: function isBookmarked() bookmarkcache.closure.isBookmarked }),
isBookmarked: deprecated("bookmarkcache.isBookmarked", { get: function isBookmarked() bookmarkcache.bound.isBookmarked }),
/**
* Remove a bookmark or bookmarks. If *ids* is an array, removes the
@@ -189,7 +189,7 @@ var Bookmarks = Module("bookmarks", {
let uri = util.newURI(ids);
ids = services.bookmarks
.getBookmarkIdsForURI(uri, {})
.filter(bookmarkcache.closure.isRegularBookmark);
.filter(bookmarkcache.bound.isRegularBookmark);
}
ids.forEach(function (id) {
let bmark = bookmarkcache.bookmarks[id];

View File

@@ -341,7 +341,7 @@ var CommandMode = Class("CommandMode", {
false);
this.messageCount = commandline.messageCount;
modes.push(this.mode, this.extendedMode, this.closure);
modes.push(this.mode, this.extendedMode, this.bound);
this.widgets.active.commandline.collapsed = false;
this.widgets.prompt = this.prompt;
@@ -791,7 +791,7 @@ var CommandLine = Module("commandline", {
let action = this._echoLine;
if ((flags & this.FORCE_MULTILINE) || (/\n/.test(data) || !isinstance(data, [_, "String"])) && !(flags & this.FORCE_SINGLELINE))
action = mow.closure.echo;
action = mow.bound.echo;
let checkSingleLine = () => action == this._echoLine;
@@ -803,7 +803,7 @@ var CommandLine = Module("commandline", {
// So complicated...
if (checkSingleLine() && !this.widgets.mowContainer.collapsed) {
highlightGroup += " Message";
action = mow.closure.echo;
action = mow.bound.echo;
}
else if (!checkSingleLine() && this.widgets.mowContainer.collapsed) {
if (this._lastEcho && this.widgets.message && this.widgets.message[1] == this._lastEcho.msg) {
@@ -1113,7 +1113,7 @@ var CommandLine = Module("commandline", {
this.itemList = commandline.completionList;
this.itemList.open(this.context);
dactyl.registerObserver("events.doneFeeding", this.closure.onDoneFeeding, true);
dactyl.registerObserver("events.doneFeeding", this.bound.onDoneFeeding, true);
this.autocompleteTimer = Timer(200, 500, function autocompleteTell(tabPressed) {
if (events.feedingKeys && !tabPressed)
@@ -1246,7 +1246,7 @@ var CommandLine = Module("commandline", {
* called.
*/
cleanup: function cleanup() {
dactyl.unregisterObserver("events.doneFeeding", this.closure.onDoneFeeding);
dactyl.unregisterObserver("events.doneFeeding", this.bound.onDoneFeeding);
this.previewClear();
this.tabTimer.reset();
@@ -1945,7 +1945,7 @@ var ItemList = Class("ItemList", {
this.resize(flags);
}, this);
DOM(this.win).resize(this._onResize.closure.tell);
DOM(this.win).resize(this._onResize.bound.tell);
},
get rootXML()
@@ -2397,8 +2397,8 @@ var ItemList = Class("ItemList", {
first = row;
let container = DOM(this.nodes.items);
let before = first ? DOM(first).closure.before
: DOM(this.nodes.items).closure.append;
let before = first ? DOM(first).bound.before
: DOM(this.nodes.items).bound.append;
for (let [i, row] in this.context.getRows(range.start, range.end,
this.doc)) {

View File

@@ -206,7 +206,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
registerObservers: function registerObservers(obj, prop) {
for (let [signal, func] in Iterator(obj[prop || "signals"]))
this.registerObserver(signal, obj.closure(func), false);
this.registerObserver(signal, func.bind(obj), false);
},
unregisterObserver: function unregisterObserver(type, callback) {
@@ -241,7 +241,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
let filters = args.map(arg => let (re = util.regexp.escape(arg))
util.regexp("\\b" + re + "\\b|(?:^|[()\\s])" + re + "(?:$|[()\\s])", "i"));
if (filters.length)
results = results.filter(item => filters.every(re => keys(item).some(re.closure.test)));
results = results.filter(item => filters.every(re => keys(item).some(re.bound.test)));
commandline.commandOutput(
template.usage(results, params.format));
@@ -377,9 +377,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
},
dump: deprecated("util.dump",
{ get: function dump() util.closure.dump }),
{ get: function dump() util.bound.dump }),
dumpStack: deprecated("util.dumpStack",
{ get: function dumpStack() util.closure.dumpStack }),
{ get: function dumpStack() util.bound.dumpStack }),
/**
* Outputs a plain message to the command line.
@@ -627,8 +627,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
}
},
help: deprecated("help.help", { get: function help() modules.help.closure.help }),
findHelp: deprecated("help.findHelp", { get: function findHelp() help.closure.findHelp }),
help: deprecated("help.help", { get: function help() modules.help.bound.help }),
findHelp: deprecated("help.findHelp", { get: function findHelp() help.bound.findHelp }),
/**
* @private
@@ -724,7 +724,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
}
if (obj.completer && false)
add(completion._runCompleter(obj.closure.completer, "", null, args).items
add(completion._runCompleter(obj.bound.completer, "", null, args).items
.map(i => [i.text, i.description]));
if (obj.options && obj.options.some(o => o.description) && false)

View File

@@ -765,7 +765,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
completion: function initCompletion() {
completion.register = function complete_register(context) {
context = context.fork("registers");
context.keys = { text: util.identity, description: editor.closure.getRegister };
context.keys = { text: util.identity, description: editor.bound.getRegister };
context.match = function (r) !this.filter || this.filter.contains(r);

View File

@@ -90,7 +90,7 @@ var EventHive = Class("EventHive", Contexts.Hive, {
});
},
get wrapListener() events.closure.wrapListener
get wrapListener() events.bound.wrapListener
});
/**
@@ -107,9 +107,9 @@ var Events = Module("events", {
["window", { id: document.documentElement.id, xmlns: "xul" },
// http://developer.mozilla.org/en/docs/XUL_Tutorial:Updating_Commands
["commandset", { id: "dactyl-onfocus", commandupdater: "true", events: "focus",
commandupdate: this.closure.onFocusChange }],
commandupdate: this.bound.onFocusChange }],
["commandset", { id: "dactyl-onselect", commandupdater: "true", events: "select",
commandupdate: this.closure.onSelectionChange }]]]
commandupdate: this.bound.onSelectionChange }]]]
});
this._fullscreen = window.fullScreen;
@@ -211,7 +211,7 @@ var Events = Module("events", {
}
},
get listen() this.builtin.closure.listen,
get listen() this.builtin.bound.listen,
addSessionListener: deprecated("events.listen", { get: function addSessionListener() this.listen }),
/**
@@ -424,11 +424,11 @@ var Events = Module("events", {
return true;
},
canonicalKeys: deprecated("DOM.Event.canonicalKeys", { get: function canonicalKeys() DOM.Event.closure.canonicalKeys }),
canonicalKeys: deprecated("DOM.Event.canonicalKeys", { get: function canonicalKeys() DOM.Event.bound.canonicalKeys }),
create: deprecated("DOM.Event", function create() DOM.Event.apply(null, arguments)),
dispatch: deprecated("DOM.Event.dispatch", function dispatch() DOM.Event.dispatch.apply(DOM.Event, arguments)),
fromString: deprecated("DOM.Event.parse", { get: function fromString() DOM.Event.closure.parse }),
iterKeys: deprecated("DOM.Event.iterKeys", { get: function iterKeys() DOM.Event.closure.iterKeys }),
fromString: deprecated("DOM.Event.parse", { get: function fromString() DOM.Event.bound.parse }),
iterKeys: deprecated("DOM.Event.iterKeys", { get: function iterKeys() DOM.Event.bound.iterKeys }),
toString: function toString() {
if (!arguments.length)
@@ -1153,9 +1153,9 @@ var Events = Module("events", {
let value = parse.superapply(this, arguments);
value.forEach(function (filter) {
let vals = Option.splitList(filter.result);
filter.keys = DOM.Event.parse(vals[0]).map(DOM.Event.closure.stringify);
filter.keys = DOM.Event.parse(vals[0]).map(DOM.Event.bound.stringify);
filter.commandKeys = vals.slice(1).map(DOM.Event.closure.canonicalKeys);
filter.commandKeys = vals.slice(1).map(DOM.Event.bound.canonicalKeys);
filter.inputKeys = filter.commandKeys.filter(bind("test", /^<[ACM]-/));
});
return value;

View File

@@ -24,7 +24,7 @@ var HintSession = Class("HintSession", CommandMode, {
this.activeTimeout = null; // needed for hinttimeout > 0
this.continue = Boolean(opts.continue);
this.docs = [];
this.hintKeys = DOM.Event.parse(options["hintkeys"]).map(DOM.Event.closure.stringify);
this.hintKeys = DOM.Event.parse(options["hintkeys"]).map(DOM.Event.bound.stringify);
this.hintNumber = 0;
this.hintString = opts.filter || "";
this.pageHints = [];
@@ -36,8 +36,8 @@ var HintSession = Class("HintSession", CommandMode, {
this.open();
this.top = opts.window || content;
this.top.addEventListener("resize", this.closure._onResize, true);
this.top.addEventListener("dactyl-commandupdate", this.closure._onResize, false, true);
this.top.addEventListener("resize", this.bound._onResize, true);
this.top.addEventListener("dactyl-commandupdate", this.bound._onResize, false, true);
this.generate();
@@ -101,8 +101,8 @@ var HintSession = Class("HintSession", CommandMode, {
if (hints.hintSession == this)
hints.hintSession = null;
if (this.top) {
this.top.removeEventListener("resize", this.closure._onResize, true);
this.top.removeEventListener("dactyl-commandupdate", this.closure._onResize, true);
this.top.removeEventListener("resize", this.bound._onResize, true);
this.top.removeEventListener("dactyl-commandupdate", this.bound._onResize, true);
}
this.removeHints(0);
@@ -750,19 +750,19 @@ var Hints = Module("hints", {
let appContent = document.getElementById("appcontent");
if (appContent)
events.listen(appContent, "scroll", this.resizeTimer.closure.tell, false);
events.listen(appContent, "scroll", this.resizeTimer.bound.tell, false);
const Mode = Hints.Mode;
Mode.prototype.__defineGetter__("matcher", function ()
options.get("extendedhinttags").getKey(this.name, options.get("hinttags").matcher));
this.modes = {};
this.addMode(";", "Focus hint", buffer.closure.focusElement);
this.addMode(";", "Focus hint", buffer.bound.focusElement);
this.addMode("?", "Show information for hint", elem => buffer.showElementInfo(elem));
// TODO: allow for ! override to overwrite existing paths -- where? --djk
this.addMode("s", "Save hint", elem => buffer.saveLink(elem, false));
this.addMode("f", "Focus frame", elem => dactyl.focus(elem.ownerDocument.defaultView));
this.addMode("F", "Focus frame or pseudo-frame", buffer.closure.focusElement, isScrollable);
this.addMode("F", "Focus frame or pseudo-frame", buffer.bound.focusElement, isScrollable);
this.addMode("o", "Follow hint", elem => buffer.followLink(elem, dactyl.CURRENT_TAB));
this.addMode("t", "Follow hint in a new tab", elem => buffer.followLink(elem, dactyl.NEW_TAB));
this.addMode("b", "Follow hint in a background tab", elem => buffer.followLink(elem, dactyl.NEW_BACKGROUND_TAB));
@@ -1044,7 +1044,7 @@ var Hints = Module("hints", {
let indexOf = String.indexOf;
if (options.get("hintmatching").has("transliterated"))
indexOf = Hints.closure.indexOf;
indexOf = Hints.bound.indexOf;
switch (options["hintmatching"][0]) {
case "contains" : return containsMatcher(hintString);
@@ -1066,7 +1066,7 @@ var Hints = Module("hints", {
context.compare = () => 0;
context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))];
},
onCancel: mappings.closure.popCommand,
onCancel: mappings.bound.popCommand,
onSubmit: function (arg) {
if (arg)
hints.show(arg, opts);
@@ -1342,7 +1342,7 @@ var Hints = Module("hints", {
"asdfg;lkjh": "Home Row"
},
validator: function (value) {
let values = DOM.Event.parse(value).map(DOM.Event.closure.stringify);
let values = DOM.Event.parse(value).map(DOM.Event.bound.stringify);
return Option.validIf(array.uniq(values).length === values.length && values.length > 1,
_("option.hintkeys.duplicate"));
}

View File

@@ -142,9 +142,9 @@ var ProcessorStack = Class("ProcessorStack", {
let list = this.events.filter(e => e.defaultPrevented && !e.dactylDefaultPrevented);
if (result === Events.PASS)
events.dbg("PASS THROUGH: " + list.slice(0, length).filter(e => e.type === "keypress").map(DOM.Event.closure.stringify));
events.dbg("PASS THROUGH: " + list.slice(0, length).filter(e => e.type === "keypress").map(DOM.Event.bound.stringify));
if (list.length > length)
events.dbg("REFEED: " + list.slice(length).filter(e => e.type === "keypress").map(DOM.Event.closure.stringify));
events.dbg("REFEED: " + list.slice(length).filter(e => e.type === "keypress").map(DOM.Event.bound.stringify));
if (result === Events.PASS)
events.feedevents(null, list.slice(0, length), { skipmap: true, isMacro: true, isReplay: true });

View File

@@ -107,7 +107,7 @@ var Map = Class("Map", {
*/
hasName: function (name) this.keys.indexOf(name) >= 0,
get keys() array.flatten(this.names.map(mappings.closure.expand)),
get keys() array.flatten(this.names.map(mappings.bound.expand)),
/**
* Execute the action for this mapping.
@@ -171,7 +171,7 @@ var MapHive = Class("MapHive", Contexts.Hive, {
* @param {[Modes.Mode]} modes The modes for which to return mappings.
*/
iterate: function (modes) {
let stacks = Array.concat(modes).map(this.closure.getStack);
let stacks = Array.concat(modes).map(this.bound.getStack);
return values(stacks.shift().sort((m1, m2) => String.localeCompare(m1.name, m2.name))
.filter((map) => map.rhs &&
stacks.every(stack => stack.some(m => m.rhs && m.rhs === map.rhs && m.name === map.name))));

View File

@@ -311,7 +311,7 @@ var Marks = Module("marks", {
events: function () {
let appContent = document.getElementById("appcontent");
if (appContent)
events.listen(appContent, "load", marks.closure._onPageLoad, true);
events.listen(appContent, "load", marks.bound._onPageLoad, true);
},
mappings: function () {
var myModes = config.browserModes;

View File

@@ -90,14 +90,14 @@ var MOW = Module("mow", {
if (modes.main != modes.OUTPUT_MULTILINE) {
modes.push(modes.OUTPUT_MULTILINE, null, {
onKeyPress: this.closure.onKeyPress,
onKeyPress: this.bound.onKeyPress,
leave: this.closure(function leave(stack) {
leave: stack => {
if (stack.pop)
for (let message in values(this.messages))
if (message.leave)
message.leave(stack);
}),
},
window: this.window
});

View File

@@ -426,11 +426,11 @@ var Tabs = Module("tabs", {
if (focusLeftTab)
tabs.slice(Math.max(0, index + 1 - count),
index + 1)
.forEach(config.closure.removeTab);
.forEach(config.bound.removeTab);
else
tabs.slice(index,
index + count)
.forEach(config.closure.removeTab);
.forEach(config.bound.removeTab);
return res;
},
@@ -1113,7 +1113,7 @@ var Tabs = Module("tabs", {
}
for (let event in values(["TabMove", "TabOpen", "TabClose"]))
events.listen(tabContainer, event, callback, false);
events.listen(tabContainer, "TabSelect", tabs.closure._onTabSelect, false);
events.listen(tabContainer, "TabSelect", tabs.bound._onTabSelect, false);
},
mappings: function initMappings() {