mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-22 10:25:47 +01:00
Death to E4X and stuff.
This commit is contained in:
@@ -262,33 +262,29 @@ var Abbreviations = Module("abbreviations", {
|
|||||||
function abbrevs(hive)
|
function abbrevs(hive)
|
||||||
hive.merged.filter(function (abbr) (abbr.inModes(modes) && abbr.lhs.indexOf(lhs) == 0));
|
hive.merged.filter(function (abbr) (abbr.inModes(modes) && abbr.lhs.indexOf(lhs) == 0));
|
||||||
|
|
||||||
let list = <table>
|
let list = ["table", {},
|
||||||
<tr highlight="Title">
|
["tr", { highlight: "Title" },
|
||||||
<td/>
|
["td"],
|
||||||
<td style="padding-right: 1em;">{_("title.Mode")}</td>
|
["td", { style: "padding-right: 1em;" }, _("title.Mode")],
|
||||||
<td style="padding-right: 1em;">{_("title.Abbrev")}</td>
|
["td", { style: "padding-right: 1em;" }, _("title.Abbrev")],
|
||||||
<td style="padding-right: 1em;">{_("title.Replacement")}</td>
|
["td", { style: "padding-right: 1em;" }, _("title.Replacement")]],
|
||||||
</tr>
|
["col", { style: "min-width: 6em; padding-right: 1em;" }],
|
||||||
<col style="min-width: 6em; padding-right: 1em;"/>
|
hives.map(function (hive) let (i = 0) [
|
||||||
{
|
["tr", { style: "height: .5ex;" }],
|
||||||
template.map(hives, function (hive) let (i = 0)
|
abbrevs(hive).map(function (abbrev)
|
||||||
<tr style="height: .5ex;"/> +
|
["tr", {},
|
||||||
template.map(abbrevs(hive), function (abbrev)
|
["td", { highlight: "Title" }, !i++ ? String(hive.name) : ""],
|
||||||
<tr>
|
["td", {}, abbrev.modeChar],
|
||||||
<td highlight="Title">{!i++ ? hive.name : ""}</td>
|
["td", {}, abbrev.lhs],
|
||||||
<td>{abbrev.modeChar}</td>
|
["td", {}, abbrev.rhs]]),
|
||||||
<td>{abbrev.lhs}</td>
|
["tr", { style: "height: .5ex;" }]])];
|
||||||
<td>{abbrev.rhs}</td>
|
|
||||||
</tr>) +
|
|
||||||
<tr style="height: .5ex;"/>)
|
|
||||||
}
|
|
||||||
</table>;
|
|
||||||
|
|
||||||
// TODO: Move this to an ItemList to show this automatically
|
// FIXME?
|
||||||
if (list.*.length() === list.text().length() + 2)
|
// // TODO: Move this to an ItemList to show this automatically
|
||||||
dactyl.echomsg(_("abbreviation.none"));
|
// if (list.*.length() === list.text().length() + 2)
|
||||||
else
|
// dactyl.echomsg(_("abbreviation.none"));
|
||||||
commandline.commandOutput(list);
|
// else
|
||||||
|
commandline.commandOutput(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@@ -665,10 +665,14 @@ var CommandLine = Module("commandline", {
|
|||||||
*/
|
*/
|
||||||
commandOutput: function commandOutput(xml) {
|
commandOutput: function commandOutput(xml) {
|
||||||
XML.ignoreWhitespace = XML.prettyPrinting = false;
|
XML.ignoreWhitespace = XML.prettyPrinting = false;
|
||||||
if (this.command)
|
if (!this.command)
|
||||||
this.echo(<><div xmlns={XHTML}>:{this.command}</div>
{xml}</>, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
|
|
||||||
else
|
|
||||||
this.echo(xml, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
|
this.echo(xml, this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
|
||||||
|
else if (isXML(xml))
|
||||||
|
this.echo(<><div xmlns={XHTML}>:{this.command}</div>
{xml}</>,
|
||||||
|
this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
|
||||||
|
else
|
||||||
|
this.echo([["div", { xmlns: "html" }, ":" + this.command], "\n", xml],
|
||||||
|
this.HIGHLIGHT_NORMAL, this.FORCE_MULTILINE);
|
||||||
this.command = null;
|
this.command = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -699,7 +703,7 @@ var CommandLine = Module("commandline", {
|
|||||||
let field = this.widgets.active.message.inputField;
|
let field = this.widgets.active.message.inputField;
|
||||||
if (field.value && !forceSingle && field.editor.rootElement.scrollWidth > field.scrollWidth) {
|
if (field.value && !forceSingle && field.editor.rootElement.scrollWidth > field.scrollWidth) {
|
||||||
this.widgets.message = null;
|
this.widgets.message = null;
|
||||||
mow.echo(<span highlight="Message">{str}</span>, highlightGroup, true);
|
mow.echo(["span", { highlight: "Message" }, str], highlightGroup, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -737,7 +741,7 @@ var CommandLine = Module("commandline", {
|
|||||||
highlightGroup = highlightGroup || this.HL_NORMAL;
|
highlightGroup = highlightGroup || this.HL_NORMAL;
|
||||||
|
|
||||||
if (flags & this.APPEND_TO_MESSAGES) {
|
if (flags & this.APPEND_TO_MESSAGES) {
|
||||||
let message = isObject(data) ? data : { message: data };
|
let message = isObject(data) && !DOM.isJSONXML(data) ? data : { message: data };
|
||||||
|
|
||||||
// Make sure the memoized message property is an instance property.
|
// Make sure the memoized message property is an instance property.
|
||||||
message.message;
|
message.message;
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ var MOW = Module("mow", {
|
|||||||
|
|
||||||
highlightGroup = "CommandOutput " + (highlightGroup || "");
|
highlightGroup = "CommandOutput " + (highlightGroup || "");
|
||||||
|
|
||||||
if (isObject(data) && !isinstance(data, _)) {
|
if (isObject(data) && !isinstance(data, _) && !DOM.isJSONXML(data)) {
|
||||||
this.lastOutput = null;
|
this.lastOutput = null;
|
||||||
|
|
||||||
var output = DOM(["div", { style: "white-space: nowrap", highlight: highlightGroup }],
|
var output = DOM(["div", { style: "white-space: nowrap", highlight: highlightGroup }],
|
||||||
@@ -127,9 +127,16 @@ var MOW = Module("mow", {
|
|||||||
}
|
}
|
||||||
this.messages.push(data);
|
this.messages.push(data);
|
||||||
}
|
}
|
||||||
|
else if (DOM.isJSONXML(data) || isString(data)) {
|
||||||
|
let style = isString(data) ? "pre-wrap" : "nowrap";
|
||||||
|
this.lastOutput = ["div", { style: "white-space: " + style, highlight: highlightGroup },
|
||||||
|
data];
|
||||||
|
|
||||||
|
var output = DOM(this.lastOutput, this.document);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
let style = isString(data) ? "pre-wrap" : "nowrap";
|
let style = isString(data) ? "pre-wrap" : "nowrap";
|
||||||
this.lastOutput = <div style={"white-space: " + style} highlight={highlightGroup}>{data}</div>;
|
this.lastOutput = <div style="white-space: nowrap" highlight={highlightGroup}>{data}</div>;
|
||||||
|
|
||||||
var output = DOM(this.lastOutput, this.document);
|
var output = DOM(this.lastOutput, this.document);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ defineModule("dom", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
lazyRequire("highlight", ["highlight"]);
|
lazyRequire("highlight", ["highlight"]);
|
||||||
|
lazyRequire("messages", ["_"]);
|
||||||
lazyRequire("template", ["template"]);
|
lazyRequire("template", ["template"]);
|
||||||
|
|
||||||
var XBL = Namespace("xbl", "http://www.mozilla.org/xbl");
|
var XBL = Namespace("xbl", "http://www.mozilla.org/xbl");
|
||||||
@@ -1383,7 +1384,7 @@ var DOM = Class("DOM", {
|
|||||||
? function (elem, dir) services.dactyl.getScrollable(elem) & (dir ? services.dactyl["DIRECTION_" + dir.toUpperCase()] : ~0)
|
? function (elem, dir) services.dactyl.getScrollable(elem) & (dir ? services.dactyl["DIRECTION_" + dir.toUpperCase()] : ~0)
|
||||||
: function (elem, dir) true),
|
: function (elem, dir) true),
|
||||||
|
|
||||||
isJSONXML: function isJSONXML(val) isArray(val) && isString(val[0]) || isObject(val) && "toDOM" in val,
|
isJSONXML: function isJSONXML(val) isArray(val) && (isString(val[0]) || isArray(val[0])) || isObject(val) && "toDOM" in val,
|
||||||
|
|
||||||
DOMString: function (val) ({
|
DOMString: function (val) ({
|
||||||
toDOM: function toDOM(doc) doc.createTextNode(val)
|
toDOM: function toDOM(doc) doc.createTextNode(val)
|
||||||
@@ -1555,7 +1556,11 @@ var DOM = Class("DOM", {
|
|||||||
function tag(args, namespaces) {
|
function tag(args, namespaces) {
|
||||||
let _namespaces = namespaces;
|
let _namespaces = namespaces;
|
||||||
|
|
||||||
|
if (isinstance(args, ["String", _]))
|
||||||
|
return doc.createTextNode(args);
|
||||||
|
|
||||||
let [name, attr] = args;
|
let [name, attr] = args;
|
||||||
|
attr = attr || {};
|
||||||
|
|
||||||
if (Array.isArray(name) || args.length == 0) {
|
if (Array.isArray(name) || args.length == 0) {
|
||||||
var frag = doc.createDocumentFragment();
|
var frag = doc.createDocumentFragment();
|
||||||
@@ -1607,8 +1612,7 @@ var DOM = Class("DOM", {
|
|||||||
elem.setAttribute(key, val);
|
elem.setAttribute(key, val);
|
||||||
}
|
}
|
||||||
args.forEach(function(e) {
|
args.forEach(function(e) {
|
||||||
elem.appendChild(typeof e == "object" ? tag(e, namespaces) :
|
elem.appendChild(e instanceof Ci.nsIDOMNode ? e : tag(e, namespaces));
|
||||||
e instanceof Node ? e : doc.createTextNode(e));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if ("highlight" in attr)
|
if ("highlight" in attr)
|
||||||
|
|||||||
@@ -1024,6 +1024,63 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
return color ? <div style="white-space: pre-wrap;">{string}</div> : [s for each (s in string)].join("");
|
return color ? <div style="white-space: pre-wrap;">{string}</div> : [s for each (s in string)].join("");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
prettifyJSON: function prettifyJSON(data, indent) {
|
||||||
|
const INDENT = indent || " ";
|
||||||
|
|
||||||
|
function rec(data, level, seen) {
|
||||||
|
if (isObject(data)) {
|
||||||
|
if (~seen.indexOf(data))
|
||||||
|
throw Error("Recursive object passed");
|
||||||
|
seen = seen.concat([data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let prefix = level + INDENT;
|
||||||
|
|
||||||
|
if (data === undefined)
|
||||||
|
data = null;
|
||||||
|
|
||||||
|
if (~["boolean", "number"].indexOf(typeof data) || data === null)
|
||||||
|
res.push(String(data));
|
||||||
|
else if (isinstance(data, ["String", _]))
|
||||||
|
res.push(String.quote(data));
|
||||||
|
else if (isArray(data)) {
|
||||||
|
if (data.length == 0)
|
||||||
|
res.push("[]");
|
||||||
|
else {
|
||||||
|
res.push("[\n")
|
||||||
|
for (let [i, val] in Iterator(data)) {
|
||||||
|
if (i)
|
||||||
|
res.push(",\n");
|
||||||
|
res.push(prefix)
|
||||||
|
rec(val, prefix, seen);
|
||||||
|
}
|
||||||
|
res.push("\n", level, "]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isObject(data)) {
|
||||||
|
res.push("{\n")
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
for (let [key, val] in Iterator(data)) {
|
||||||
|
if (i++)
|
||||||
|
res.push(",\n");
|
||||||
|
res.push(prefix, String.quote(key), ": ")
|
||||||
|
rec(val, prefix, seen);
|
||||||
|
}
|
||||||
|
if (i > 0)
|
||||||
|
res.push("\n", level, "}")
|
||||||
|
else
|
||||||
|
res[res.length - 1] = "{}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw Error("Invalid JSON object");
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = [];
|
||||||
|
rec(data, "", []);
|
||||||
|
return res.join("");
|
||||||
|
},
|
||||||
|
|
||||||
observers: {
|
observers: {
|
||||||
"dactyl-cleanup-modules": function (subject, reason) {
|
"dactyl-cleanup-modules": function (subject, reason) {
|
||||||
defineModule.loadLog.push("dactyl: util: observe: dactyl-cleanup-modules " + reason);
|
defineModule.loadLog.push("dactyl: util: observe: dactyl-cleanup-modules " + reason);
|
||||||
|
|||||||
Reference in New Issue
Block a user