1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-14 19:25:45 +01:00

Merge some recent fixes into 1.0b5 branch.

This commit is contained in:
Kris Maglione
2011-01-17 13:28:14 -05:00
parent b52e78b92e
commit 2c74786f1c
13 changed files with 212 additions and 138 deletions

View File

@@ -174,15 +174,14 @@ var Buffer = Module("buffer", {
else
ext = "";
let re = ext ? RegExp("(\\." + currExt + ")?$") : /$/;
util.dump(ext.quote(),
isinstance(node, [Document, HTMLImageElement]),
node.contentType);
var names = [];
if (node.title)
names.push([node.title, "Page Name"]);
if (node.alt)
names.push([node.alt, "Alternate Text"]);
if (!isinstance(node, Document) && node.textContent)
names.push([node.textContent, "Link Text"]);
@@ -786,6 +785,10 @@ var Buffer = Module("buffer", {
var persist = services.Persist();
persist.persistFlags = persist.PERSIST_FLAGS_FROM_CACHE
| persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
persist.progressListener = new window.DownloadListener(window,
services.Transfer(uri, services.io.newFileURI(file), "",
null, null, null, persist));
persist.saveURI(uri, null, null, null, null, file);
}, {
autocomplete: true,

View File

@@ -21,6 +21,9 @@ var CommandWidgets = Class("CommandWidgets", {
<menuitem id="dactyl-context-copylink"
label="Copy Link Location" dactyl:group="link"
oncommand="goDoCommand('cmd_copyLink');"/>
<menuitem id="dactyl-context-copypath"
label="Copy File Path" dactyl:group="link path"
oncommand="dactyl.clipboardWrite(document.popupNode.getAttribute('path'));"/>
<menuitem id="dactyl-context-copy"
label="Copy" dactyl:group="selection"
command="cmd_copy"/>
@@ -265,10 +268,12 @@ var CommandWidgets = Class("CommandWidgets", {
while (elem.contentDocument.documentURI != elem.getAttribute("src") ||
["viewable", "complete"].indexOf(elem.contentDocument.readyState) < 0)
util.threadYield();
return elem;
res = res || (processor || util.identity).call(self, elem);
return res;
}
});
return Class.replaceProperty(this, name, (processor || util.identity).call(this, this[name]))
let res, self = this;
return Class.replaceProperty(this, name, this[name])
},
get completionList() this._whenReady("completionList", "dactyl-completions"),
@@ -748,8 +753,15 @@ var CommandLine = Module("commandline", {
XML.ignoreWhitespace = false;
XML.prettyPrinting = false;
let style = typeof str === "string" ? "pre" : "nowrap";
this._lastMowOutput = <div class="ex-command-output" style={"white-space: " + style} highlight={highlightGroup}>{str}</div>;
let output = util.xmlToDom(this._lastMowOutput, doc);
if (callable(str)) {
this._lastMowOutput = null;
var output = util.xmlToDom(<div class="ex-command-output" style="white-space: nowrap" highlight={highlightGroup}/>, doc);
output.appendChild(str(doc));
}
else {
this._lastMowOutput = <div class="ex-command-output" style={"white-space: " + style} highlight={highlightGroup}>{str}</div>;
var output = util.xmlToDom(this._lastMowOutput, doc);
}
// FIXME: need to make sure an open MOW is closed when commands
// that don't generate output are executed
@@ -824,7 +836,7 @@ var CommandLine = Module("commandline", {
let single = flags & (this.FORCE_SINGLELINE | this.DISALLOW_MULTILINE);
let action = this._echoLine;
if ((flags & this.FORCE_MULTILINE) || (/\n/.test(str) || typeof str == "xml") && !(flags & this.FORCE_SINGLELINE))
if ((flags & this.FORCE_MULTILINE) || (/\n/.test(str) || !isString(str)) && !(flags & this.FORCE_SINGLELINE))
action = this._echoMultiline;
if (single)
@@ -928,14 +940,21 @@ var CommandLine = Module("commandline", {
},
onContext: function onContext(event) {
let enabled = {
link: window.document.popupNode instanceof HTMLAnchorElement,
selection: !window.document.commandDispatcher.focusedWindow.getSelection().isCollapsed
};
try {
let enabled = {
link: window.document.popupNode instanceof HTMLAnchorElement,
path: window.document.popupNode.hasAttribute("path"),
selection: !window.document.commandDispatcher.focusedWindow.getSelection().isCollapsed
};
for (let [, node] in iter(event.target.childNodes)) {
let group = node.getAttributeNS(NS, "group");
node.hidden = group && !group.split(/\s+/).some(function (g) enabled[g]);
for (let node in array.iterValues(event.target.children)) {
let group = node.getAttributeNS(NS, "group");
util.dump(node, group, group && !group.split(/\s+/).every(function (g) enabled[g]));
node.hidden = group && !group.split(/\s+/).every(function (g) enabled[g]);
}
}
catch (e) {
util.reportError(e);
}
return true;
},
@@ -1073,63 +1092,72 @@ var CommandLine = Module("commandline", {
// FIXME: if 'more' is set and the MOW is not scrollable we should still
// allow a down motion after an up rather than closing
onMultilineOutputEvent: function onMultilineOutputEvent(event) {
const KILL = false, PASS = true;
try {
const KILL = false, PASS = true;
let win = this.widgets.multilineOutput.contentWindow;
let elem = win.document.documentElement;
let win = this.widgets.multilineOutput.contentWindow;
let elem = win.document.documentElement;
let key = events.toString(event);
let key = events.toString(event);
function openLink(where) {
event.preventDefault();
dactyl.open(event.target.href, where);
}
// TODO: Wouldn't multiple handlers be cleaner? --djk
if (event.type == "click" && event.target instanceof HTMLAnchorElement) {
let command = event.originalTarget.getAttributeNS(NS.uri, "command");
if (command && dactyl.commands[command]) {
const openLink = function openLink(where) {
event.preventDefault();
return dactyl.withSavedValues(["forceNewTab"], function () {
dactyl.forceNewTab = event.ctrlKey || event.shiftKey || event.button == 1;
return dactyl.commands[command](event);
});
dactyl.open(event.target.href, where);
}
switch (key) {
case "<LeftMouse>":
event.preventDefault();
openLink(dactyl.CURRENT_TAB);
return KILL;
case "<MiddleMouse>":
case "<C-LeftMouse>":
case "<C-M-LeftMouse>":
openLink({ where: dactyl.NEW_TAB, background: true });
return KILL;
case "<S-MiddleMouse>":
case "<C-S-LeftMouse>":
case "<C-M-S-LeftMouse>":
openLink({ where: dactyl.NEW_TAB, background: false });
return KILL;
case "<S-LeftMouse>":
openLink(dactyl.NEW_WINDOW);
return KILL;
// TODO: Wouldn't multiple handlers be cleaner? --djk
if (event.type == "click" && (event.target instanceof HTMLAnchorElement ||
event.originalTarget.hasAttributeNS(NS, "command"))) {
let command = event.originalTarget.getAttributeNS(NS, "command");
if (command && event.button == 2)
return PASS;
if (command && dactyl.commands[command]) {
event.preventDefault();
return dactyl.withSavedValues(["forceNewTab"], function () {
dactyl.forceNewTab = event.ctrlKey || event.shiftKey || event.button == 1;
return dactyl.commands[command](event);
});
}
switch (key) {
case "<LeftMouse>":
event.preventDefault();
openLink(dactyl.CURRENT_TAB);
return KILL;
case "<MiddleMouse>":
case "<C-LeftMouse>":
case "<C-M-LeftMouse>":
openLink({ where: dactyl.NEW_TAB, background: true });
return KILL;
case "<S-MiddleMouse>":
case "<C-S-LeftMouse>":
case "<C-M-S-LeftMouse>":
openLink({ where: dactyl.NEW_TAB, background: false });
return KILL;
case "<S-LeftMouse>":
openLink(dactyl.NEW_WINDOW);
return KILL;
}
return PASS;
}
return PASS;
if (event instanceof MouseEvent)
return KILL;
const atEnd = function atEnd(dir) !Buffer.isScrollable(elem, dir || 1);
if (!options["more"] || atEnd(1)) {
modes.pop();
events.feedkeys(key);
}
else
commandline.updateMorePrompt(false, true);
}
if (event instanceof MouseEvent)
return KILL;
function atEnd(dir) !Buffer.isScrollable(elem, dir || 1);
if (!options["more"] || atEnd(1)) {
modes.pop();
events.feedkeys(key);
catch (e) {
util.reportError(e);
}
else
commandline.updateMorePrompt(false, true);
return PASS;
},

View File

@@ -53,16 +53,18 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
},
observers: {
"dactyl-cleanup": function () {
"dactyl-cleanup": function dactyl_cleanup() {
let modules = dactyl.modules;
for (let name in values(Object.getOwnPropertyNames(modules).reverse())) {
let mod = Object.getOwnPropertyDescriptor(modules, name).value;
if (mod instanceof Class) {
if ("cleanup" in mod)
mod.cleanup();
this.trapErrors(mod.cleanup, mod);
if ("destroy" in mod)
mod.destroy();
this.trapErrors(mod.destroy, mod);
if ("INIT" in mod && "cleanup" in mod.INIT)
this.trapErrors(mod.cleanup, mod, dactyl, modules, window);
}
}
@@ -360,6 +362,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
},
userEval: function (str, context, fileName, lineNumber) {
if (jsmodules.__proto__ != window)
str = "with (window) { with (modules) { (this.eval || eval)(" + str.quote() + ") } }";
if (fileName == null)
if (io.sourcing && io.sourcing.file[0] !== "[")
({ file: fileName, line: lineNumber }) = io.sourcing;
@@ -389,9 +394,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
if (!context)
context = _userContext;
if (window.isPrototypeOf(modules))
return Cu.evalInSandbox(str, context, "1.8", fileName, lineNumber);
return Cu.evalInSandbox("with (window) { with (modules) { this.eval(" + str.quote() + ") } }", context, "1.8", fileName, lineNumber);
return Cu.evalInSandbox(str, context, "1.8", fileName, lineNumber);
},
/**
@@ -505,7 +508,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
* @param {string} feature The feature name.
* @returns {boolean}
*/
has: function (feature) config.features.indexOf(feature) >= 0,
has: function (feature) set.has(config.features, feature),
/**
* Returns the URL of the specified help *topic* if it exists.
@@ -2178,7 +2181,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
let init = services.environment.get(config.idName + "_INIT");
let rcFile = io.getRCFile("~");
if (dactyl.userEval('typeof document') === "undefined")
if (dactyl.userEval("typeof document", null, "test.js") === "undefined")
jsmodules.__proto__ = XPCSafeJSObjectWrapper(window);
try {

View File

@@ -175,6 +175,9 @@ var Modes = Module("modes", {
}
});
},
cleanup: function () {
modes.reset();
},
_getModeMessage: function () {
// when recording a macro