1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 20:27:58 +01:00

Deal with fallout from 609832.

This commit is contained in:
Kris Maglione
2011-01-09 16:15:52 -05:00
parent 415386a183
commit 04f55e9324
10 changed files with 148 additions and 151 deletions

View File

@@ -9,8 +9,6 @@ function reportError(e) {
Cu.reportError(e);
}
try {
var global = this;
var NAME = "command-line-handler";
var Cc = Components.classes;
@@ -61,6 +59,4 @@ else
var NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]);
var EXPORTED_SYMBOLS = ["NSGetFactory", "global"];
} catch (e) { reportError(e) }
// vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -9,8 +9,6 @@ function reportError(e) {
Cu.reportError(e);
}
try {
/* Adds support for data: URIs with chrome privileges
* and fragment identifiers.
*
@@ -334,6 +332,4 @@ else
var NSGetModule = XPCOMUtils.generateNSGetModule([ChromeData, Dactyl, Shim]);
var EXPORTED_SYMBOLS = ["NSGetFactory", "global"];
} catch (e) { reportError(e) }
// vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -1064,13 +1064,14 @@ var CommandLine = Module("commandline", {
let key = events.toString(event);
// TODO: Wouldn't multiple handlers be cleaner? --djk
if (event.type == "click" && event.target instanceof HTMLAnchorElement) {
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]) {
event.preventDefault();
@@ -1494,7 +1495,7 @@ var CommandLine = Module("commandline", {
try {
this.waiting = true;
for (let [, context] in Iterator(list)) {
function done() !(idx >= n + context.items.length || idx == -2 && !context.items.length);
let done = function done() !(idx >= n + context.items.length || idx == -2 && !context.items.length);
while (context.incomplete && !done())
util.threadYield(false, true);

View File

@@ -320,11 +320,11 @@ var Command = Class("Command", {
let process = util.identity;
if (callable(params))
function makeParams(self, args)
var makeParams = function makeParams(self, args)
iter.toObject([k, process(v)]
for ([k, v] in iter(params.apply(self, args))))
else if (params)
function makeParams(self, args)
makeParams = function makeParams(self, args)
iter.toObject([name, process(args[i])]
for ([i, name] in Iterator(params)));
@@ -749,7 +749,6 @@ var Commands = Module("commands", {
* @returns {Args}
*/
parseArgs: function (str, params) {
try {
function getNextArg(str, _keepQuotes) {
if (arguments.length < 2)
_keepQuotes = keepQuotes;
@@ -769,6 +768,8 @@ var Commands = Module("commands", {
return [count, arg, quote];
}
try {
var { allowUnknownOptions, argCount, complete, extra, hereDoc, literal, options, keepQuotes } = params || {};
if (!options)
@@ -793,12 +794,12 @@ var Commands = Module("commands", {
var completeOpts;
// XXX
function matchOpts(arg) {
let matchOpts = function matchOpts(arg) {
// Push possible option matches into completions
if (complete && !onlyArgumentsRemaining)
completeOpts = options.filter(function (opt) opt.multiple || !set.has(args, opt.names[0]));
}
function resetCompletions() {
let resetCompletions = function resetCompletions() {
completeOpts = null;
args.completeArg = null;
args.completeOpt = null;
@@ -812,7 +813,7 @@ var Commands = Module("commands", {
args.completeArg = 0;
}
function fail(error) {
let fail = function fail(error) {
if (complete)
complete.message = error;
else
@@ -1328,7 +1329,7 @@ var Commands = Module("commands", {
dactyl.echoerr("E174: Command already exists: add ! to replace it");
}
else {
function completerToString(completer) {
let completerToString = function completerToString(completer) {
if (completer)
return [k for ([k, v] in Iterator(completerMap)) if (completer == completion.closure[v])][0] || "custom";
return "";

View File

@@ -534,19 +534,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
* Initialize the help system.
*/
initHelp: function (force) {
if (!force && !this.helpInitialized) {
if ("noscriptOverlay" in window) {
noscriptOverlay.safeAllow("chrome-data:", true, false);
noscriptOverlay.safeAllow("dactyl:", true, false);
}
let namespaces = ["locale-local", "locale"];
services["dactyl:"].init({});
let tagMap = services["dactyl:"].HELP_TAGS;
let fileMap = services["dactyl:"].FILE_MAP;
let overlayMap = services["dactyl:"].OVERLAY_MAP;
// Find help and overlay files with the given name.
function findHelpFile(file) {
let result = [];
@@ -570,6 +557,19 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
tagMap[tag] = file;
}
if (!force && !this.helpInitialized) {
if ("noscriptOverlay" in window) {
noscriptOverlay.safeAllow("chrome-data:", true, false);
noscriptOverlay.safeAllow("dactyl:", true, false);
}
let namespaces = ["locale-local", "locale"];
services["dactyl:"].init({});
let tagMap = services["dactyl:"].HELP_TAGS;
let fileMap = services["dactyl:"].FILE_MAP;
let overlayMap = services["dactyl:"].OVERLAY_MAP;
// Scrape the list of help files from all.xml
// Manually process main and overlay files, since XSLTProcessor and
// XMLHttpRequest don't allow access to chrome documents.
@@ -658,32 +658,22 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
dactyl.initHelp();
if (FILE.isDirectory()) {
function addDataEntry(file, data) FILE.child(file).write(data);
function addURIEntry(file, uri) addDataEntry(file, util.httpGet(uri).responseText);
var addDataEntry = function addDataEntry(file, data) FILE.child(file).write(data);
var addURIEntry = function addURIEntry(file, uri) addDataEntry(file, util.httpGet(uri).responseText);
}
else {
var zip = services.ZipWriter();
zip.open(FILE, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
function addURIEntry(file, uri)
addURIEntry = function addURIEntry(file, uri)
zip.addEntryChannel(PATH + file, TIME, 9,
services.io.newChannel(uri, null, null), false);
function addDataEntry(file, data) // Unideal to an extreme.
addDataEntry = function addDataEntry(file, data) // Unideal to an extreme.
addURIEntry(file, "data:text/plain;charset=UTF-8," + encodeURI(data));
}
let empty = set("area base basefont br col frame hr img input isindex link meta param"
.split(" "));
let chromeFiles = {};
let styles = {};
for (let [file, ] in Iterator(services["dactyl:"].FILE_MAP)) {
dactyl.open("dactyl://help/" + file);
dactyl.modules.events.waitForPageLoad();
let data = [
'<?xml version="1.0" encoding="UTF-8"?>\n',
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n',
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
];
function fix(node) {
switch(node.nodeType) {
case Node.ELEMENT_NODE:
@@ -733,6 +723,17 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
data.push(<>{node.textContent}</>.toXMLString());
}
}
let chromeFiles = {};
let styles = {};
for (let [file, ] in Iterator(services["dactyl:"].FILE_MAP)) {
dactyl.open("dactyl://help/" + file);
dactyl.modules.events.waitForPageLoad();
let data = [
'<?xml version="1.0" encoding="UTF-8"?>\n',
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n',
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
];
fix(content.document.documentElement);
addDataEntry(file + ".xhtml", data.join(""));
}
@@ -1893,12 +1894,12 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
"Force " + config.appName + " to restart",
function () { dactyl.restart(); });
var toolbox = document.getElementById("navigator-toolbox");
if (toolbox) {
function findToolbar(name) util.evaluateXPath(
"./*[@toolbarname=" + util.escapeString(name, "'") + "]",
document, toolbox).snapshotItem(0);
var toolbox = document.getElementById("navigator-toolbox");
if (toolbox) {
let toolbarCommand = function (names, desc, action, filter) {
commands.add(names, desc,
function (args) {

View File

@@ -307,6 +307,21 @@ var Editor = Module("editor", {
}
});
function update(force) {
if (force !== true && tmpfile.lastModifiedTime <= lastUpdate)
return;
lastUpdate = Date.now();
let val = tmpfile.read();
if (textBox)
textBox.value = val;
else {
while (editor.rootElement.firstChild)
editor.rootElement.removeChild(editor.rootElement.firstChild);
editor.rootElement.innerHTML = val;
}
}
try {
var tmpfile = io.createTempFile();
if (!tmpfile)
@@ -322,20 +337,6 @@ var Editor = Module("editor", {
"file encoding");
let lastUpdate = Date.now();
function update(force) {
if (force !== true && tmpfile.lastModifiedTime <= lastUpdate)
return;
lastUpdate = Date.now();
let val = tmpfile.read();
if (textBox)
textBox.value = val;
else {
while (editor.rootElement.firstChild)
editor.rootElement.removeChild(editor.rootElement.firstChild);
editor.rootElement.innerHTML = val;
}
}
var timer = services.Timer(update, 100, services.Timer.TYPE_REPEATING_SLACK);
this.editFileExternally({ file: tmpfile.path, line: line, column: column }, cleanup);

View File

@@ -899,15 +899,15 @@ var Events = Module("events", {
return killEvent();
}
function shouldPass()
(!dactyl.focusedElement || events.isContentNode(dactyl.focusedElement)) &&
options.get("passkeys").has(events.toString(event));
try {
let mode = modes.getStack(0);
if (event.dactylMode)
mode = Modes.StackElement(event.dactylMode);
function shouldPass()
(!dactyl.focusedElement || events.isContentNode(dactyl.focusedElement)) &&
options.get("passkeys").has(events.toString(event));
let input = this._input;
this._input = null;
if (!input) {

View File

@@ -43,7 +43,7 @@ var Tabs = Module("tabs", {
cleanup: function cleanup() {
for (let [i, tab] in Iterator(this.allTabs)) {
function node(clas) document.getAnonymousElementByAttribute(tab, "class", clas);
let node = function node(clas) document.getAnonymousElementByAttribute(tab, "class", clas);
for (let elem in values(["dactyl-tab-icon-number", "dactyl-tab-number"].map(node)))
if (elem)
elem.parentNode.parentNode.removeChild(elem.parentNode);
@@ -53,7 +53,7 @@ var Tabs = Module("tabs", {
updateTabCount: function () {
for (let [i, tab] in Iterator(this.visibleTabs)) {
if (dactyl.has("Gecko2")) {
function node(clas) document.getAnonymousElementByAttribute(tab, "class", clas);
let node = function node(clas) document.getAnonymousElementByAttribute(tab, "class", clas);
if (!node("dactyl-tab-number")) {
let nodes = {};
let dom = util.xmlToDom(<xul xmlns:xul={XUL} xmlns:html={XHTML}

View File

@@ -309,15 +309,15 @@ var Styles = Module("Styles", {
*/
matchFilter: function (filter) {
if (filter === "*")
function test(uri) true;
var test = function test(uri) true;
else if (/[*]$/.test(filter)) {
let re = RegExp("^" + util.regexp.escape(filter.substr(0, filter.length - 1)));
function test(uri) re.test(uri.spec);
test = function test(uri) re.test(uri.spec);
}
else if (/[\/:]/.test(filter))
function test(uri) uri.spec === filter;
test = function test(uri) uri.spec === filter;
else
function test(uri) { try { return util.isSubdomain(uri.host, filter); } catch (e) { return false; } };
test = function test(uri) { try { return util.isSubdomain(uri.host, filter); } catch (e) { return false; } };
test.toString = function toString() filter;
if (arguments.length < 2)
return test;

View File

@@ -31,8 +31,8 @@ memoize(this, "Commands", function () {
var FailedAssertion = Class("FailedAssertion", ErrorBase);
var Point = Struct("x", "y");
function wrapCallback(fn)
fn.wrapper = function wrappedCallback () {
var wrapCallback = function wrapCallback(fn)
fn.wrapper = (function wrappedCallback () {
try {
return fn.apply(this, arguments);
}
@@ -40,7 +40,7 @@ function wrapCallback(fn)
util.reportError(e);
return undefined;
}
}
})
var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), {
init: function () {
@@ -820,6 +820,15 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
if (!isObject(object))
return String(object);
function namespaced(node) {
var ns = NAMESPACES[node.namespaceURI] || /^(?:(.*?):)?/.exec(node.name)[0];
if (!ns)
return node.localName;
if (color)
return <><span highlight="HelpXMLNamespace">{ns}</span>{node.localName}</>
return ns + ":" + node.localName;
}
if (object instanceof Ci.nsIDOMElement) {
const NAMESPACES = array.toObject([
[NS, "dactyl"],
@@ -830,14 +839,6 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
if (elem.nodeType == elem.TEXT_NODE)
return elem.data;
function namespaced(node) {
var ns = NAMESPACES[node.namespaceURI] || /^(?:(.*?):)?/.exec(node.name)[0];
if (!ns)
return node.localName;
if (color)
return <><span highlight="HelpXMLNamespace">{ns}</span>{node.localName}</>
return ns + ":" + node.localName;
}
try {
let hasChildren = elem.firstChild && (!/^\s*$/.test(elem.firstChild) || elem.firstChild.nextSibling)
if (color)