mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-18 15:04:13 +01:00
Add cache module. Cleanup help and DTD generation. Fix :help version generation issues. Fix other assorted issues.
This commit is contained in:
@@ -1291,6 +1291,10 @@ var Buffer = Module("buffer", {
|
||||
if (!DOM(elem).isScrollable(horizontal ? "horizontal" : "vertical"))
|
||||
return false;
|
||||
|
||||
return this.canScroll(elem, dir, horizontal);
|
||||
},
|
||||
|
||||
canScroll: function canScroll(elem, dir, horizontal) {
|
||||
let pos = "scrollTop", size = "clientHeight", max = "scrollHeight", layoutSize = "offsetHeight",
|
||||
overflow = "overflowX", border1 = "borderTopWidth", border2 = "borderBottomWidth";
|
||||
if (horizontal)
|
||||
|
||||
@@ -111,6 +111,13 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
}
|
||||
},
|
||||
|
||||
signals: {
|
||||
"io.source": function ioSource(context, file, modTime) {
|
||||
if (context.INFO)
|
||||
help.flush("help/plugins.xml", modTime);
|
||||
}
|
||||
},
|
||||
|
||||
profileName: deprecated("config.profileName", { get: function profileName() config.profileName }),
|
||||
|
||||
/**
|
||||
@@ -484,8 +491,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
|
||||
if (fileName && fileName[0] == "[")
|
||||
fileName = "dactyl://command-line/";
|
||||
|
||||
if (!context && fileName && fileName[0] !== "[")
|
||||
else if (!context)
|
||||
context = ctxt || _userContext;
|
||||
|
||||
if (isinstance(context, ["Sandbox"]))
|
||||
@@ -659,82 +665,11 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
* @private
|
||||
* Initialize the help system.
|
||||
*/
|
||||
initHelp: function initHelp(force) {
|
||||
initHelp: function initHelp() {
|
||||
if ("noscriptOverlay" in window)
|
||||
noscriptOverlay.safeAllow("dactyl:", true, false);
|
||||
|
||||
if (!force && help.initialized)
|
||||
return;
|
||||
|
||||
help.initialize(force);
|
||||
|
||||
// Process plugin help entries.
|
||||
XML.ignoreWhiteSpace = XML.prettyPrinting = false;
|
||||
|
||||
let body = XML();
|
||||
for (let [, context] in Iterator(plugins.contexts))
|
||||
try {
|
||||
let info = contexts.getDocs(context);
|
||||
if (info instanceof XML) {
|
||||
if (info.*.@lang.length()) {
|
||||
let lang = config.bestLocale(String(a) for each (a in info.*.@lang));
|
||||
|
||||
info.* = info.*.(function::attribute("lang").length() == 0 || @lang == lang);
|
||||
|
||||
for each (let elem in info.NS::info)
|
||||
for each (let attr in ["@name", "@summary", "@href"])
|
||||
if (elem[attr].length())
|
||||
info[attr] = elem[attr];
|
||||
}
|
||||
body += <h2 xmlns={NS.uri} tag={info.@name + '-plugin'}>{info.@summary}</h2> +
|
||||
info;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
util.reportError(e);
|
||||
}
|
||||
|
||||
help.files["plugins"] = function () ['text/xml;charset=UTF-8',
|
||||
'<?xml version="1.0"?>\n' +
|
||||
'<?xml-stylesheet type="text/xsl" href="dactyl://content/help.xsl"?>\n' +
|
||||
'<!DOCTYPE document SYSTEM "resource://dactyl-content/dactyl.dtd">\n' +
|
||||
<document xmlns={NS}
|
||||
name="plugins" title={config.appName + " Plugins"}>
|
||||
<h1 tag="using-plugins">{_("help.title.Using Plugins")}</h1>
|
||||
<toc start="2"/>
|
||||
|
||||
{body}
|
||||
</document>.toXMLString()];
|
||||
|
||||
|
||||
default xml namespace = NS;
|
||||
|
||||
help.overlays["index"] = ['text/xml;charset=UTF-8',
|
||||
'<?xml version="1.0"?>\n' +
|
||||
<overlay xmlns={NS}>{
|
||||
template.map(dactyl.indices, function ([name, iter])
|
||||
<dl insertafter={name + "-index"}>{
|
||||
template.map(iter(), util.identity)
|
||||
}</dl>, <>{"\n\n"}</>)
|
||||
}</overlay>];
|
||||
|
||||
help.overlays["gui"] = ['text/xml;charset=UTF-8',
|
||||
'<?xml version="1.0"?>\n' +
|
||||
<overlay xmlns={NS}>
|
||||
<dl insertafter="dialog-list">{
|
||||
template.map(config.dialogs, function ([name, val])
|
||||
(!val[2] || val[2]())
|
||||
? <><dt>{name}</dt><dd>{val[0]}</dd></>
|
||||
: undefined,
|
||||
<>{"\n"}</>)
|
||||
}</dl>
|
||||
</overlay>];
|
||||
|
||||
help.tags["plugins"] = help.tags["plugins.xml"] = "plugins";
|
||||
help.tags["index"] = help.tags["index.xml"] = "index";
|
||||
|
||||
help.addTags("plugins", util.httpGet("dactyl://help/plugins").responseXML);
|
||||
help.addTags("index", util.httpGet("dactyl://help-overlay/index").responseXML);
|
||||
help.initialize();
|
||||
},
|
||||
|
||||
stringifyXML: function (xml) {
|
||||
@@ -1280,6 +1215,73 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
}, {
|
||||
toolbarHidden: function hidden(elem) (elem.getAttribute("autohide") || elem.getAttribute("collapsed")) == "true"
|
||||
}, {
|
||||
cache: function () {
|
||||
cache.register("help/plugins.xml", function () {
|
||||
// Process plugin help entries.
|
||||
XML.ignoreWhiteSpace = XML.prettyPrinting = false;
|
||||
|
||||
let body = XML();
|
||||
for (let [, context] in Iterator(plugins.contexts))
|
||||
try {
|
||||
let info = contexts.getDocs(context);
|
||||
if (info instanceof XML) {
|
||||
if (info.*.@lang.length()) {
|
||||
let lang = config.bestLocale(String(a) for each (a in info.*.@lang));
|
||||
|
||||
info.* = info.*.(function::attribute("lang").length() == 0 || @lang == lang);
|
||||
|
||||
for each (let elem in info.NS::info)
|
||||
for each (let attr in ["@name", "@summary", "@href"])
|
||||
if (elem[attr].length())
|
||||
info[attr] = elem[attr];
|
||||
}
|
||||
body += <h2 xmlns={NS.uri} tag={info.@name + '-plugin'}>{info.@summary}</h2> +
|
||||
info;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
util.reportError(e);
|
||||
}
|
||||
|
||||
return '<?xml version="1.0"?>\n' +
|
||||
'<?xml-stylesheet type="text/xsl" href="dactyl://content/help.xsl"?>\n' +
|
||||
'<!DOCTYPE document SYSTEM "resource://dactyl-content/dactyl.dtd">\n' +
|
||||
<document xmlns={NS}
|
||||
name="plugins" title={config.appName + " Plugins"}>
|
||||
<h1 tag="using-plugins">{_("help.title.Using Plugins")}</h1>
|
||||
<toc start="2"/>
|
||||
|
||||
{body}
|
||||
</document>.toXMLString();
|
||||
});
|
||||
|
||||
cache.register("help/index.xml", function () {
|
||||
default xml namespace = NS;
|
||||
|
||||
return '<?xml version="1.0"?>\n' +
|
||||
<overlay xmlns={NS}>{
|
||||
template.map(dactyl.indices, function ([name, iter])
|
||||
<dl insertafter={name + "-index"}>{
|
||||
template.map(iter(), util.identity)
|
||||
}</dl>, <>{"\n\n"}</>)
|
||||
}</overlay>;
|
||||
});
|
||||
|
||||
cache.register("help/gui.xml", function () {
|
||||
default xml namespace = NS;
|
||||
|
||||
return '<?xml version="1.0"?>\n' +
|
||||
<overlay xmlns={NS}>
|
||||
<dl insertafter="dialog-list">{
|
||||
template.map(config.dialogs, function ([name, val])
|
||||
(!val[2] || val[2]())
|
||||
? <><dt>{name}</dt><dd>{val[0]}</dd></>
|
||||
: undefined,
|
||||
<>{"\n"}</>)
|
||||
}</dl>
|
||||
</overlay>;
|
||||
});
|
||||
},
|
||||
events: function () {
|
||||
events.listen(window, dactyl, "events", true);
|
||||
},
|
||||
|
||||
@@ -213,57 +213,18 @@ var Modes = Module("modes", {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function makeTree() {
|
||||
let list = modes.all.filter(function (m) m.name !== m.description);
|
||||
|
||||
let tree = {};
|
||||
|
||||
for (let mode in values(list))
|
||||
tree[mode.name] = {};
|
||||
|
||||
for (let mode in values(list))
|
||||
for (let base in values(mode.bases))
|
||||
tree[base.name][mode.name] = tree[mode.name];
|
||||
|
||||
let roots = iter([m.name, tree[m.name]] for (m in values(list)) if (!m.bases.length)).toObject();
|
||||
|
||||
default xml namespace = NS;
|
||||
function rec(obj) {
|
||||
XML.ignoreWhitespace = XML.prettyPrinting = false;
|
||||
|
||||
let res = <ul dactyl:highlight="Dense" xmlns:dactyl={NS}/>;
|
||||
Object.keys(obj).sort().forEach(function (name) {
|
||||
let mode = modes.getMode(name);
|
||||
res.* += <li><em>{mode.displayName}</em>: {mode.description}{
|
||||
rec(obj[name])
|
||||
}</li>;
|
||||
});
|
||||
|
||||
if (res.*.length())
|
||||
return res;
|
||||
return <></>;
|
||||
}
|
||||
|
||||
return rec(roots);
|
||||
}
|
||||
|
||||
util.timeout(function () {
|
||||
// Waits for the add-on to become available, if necessary.
|
||||
config.addon;
|
||||
config.version;
|
||||
|
||||
services["dactyl:"].pages["modes.dtd"] = services["dactyl:"].pages["modes.dtd"]();
|
||||
});
|
||||
|
||||
services["dactyl:"].pages["modes.dtd"] = function () [null,
|
||||
util.makeDTD(iter({ "modes.tree": makeTree() },
|
||||
config.dtd))];
|
||||
},
|
||||
|
||||
cleanup: function cleanup() {
|
||||
modes.reset();
|
||||
},
|
||||
|
||||
signals: {
|
||||
"io.source": function ioSource(context, file, modTime) {
|
||||
cache.flushEntry("modes.dtd", modTime);
|
||||
}
|
||||
},
|
||||
|
||||
_getModeMessage: function _getModeMessage() {
|
||||
// when recording a macro
|
||||
let macromode = "";
|
||||
@@ -604,6 +565,45 @@ var Modes = Module("modes", {
|
||||
}, desc));
|
||||
}
|
||||
}, {
|
||||
cache: function initCache() {
|
||||
function makeTree() {
|
||||
let list = modes.all.filter(function (m) m.name !== m.description);
|
||||
|
||||
let tree = {};
|
||||
|
||||
for (let mode in values(list))
|
||||
tree[mode.name] = {};
|
||||
|
||||
for (let mode in values(list))
|
||||
for (let base in values(mode.bases))
|
||||
tree[base.name][mode.name] = tree[mode.name];
|
||||
|
||||
let roots = iter([m.name, tree[m.name]] for (m in values(list)) if (!m.bases.length)).toObject();
|
||||
|
||||
default xml namespace = NS;
|
||||
function rec(obj) {
|
||||
XML.ignoreWhitespace = XML.prettyPrinting = false;
|
||||
|
||||
let res = <ul dactyl:highlight="Dense" xmlns:dactyl={NS}/>;
|
||||
Object.keys(obj).sort().forEach(function (name) {
|
||||
let mode = modes.getMode(name);
|
||||
res.* += <li><em>{mode.displayName}</em>: {mode.description}{
|
||||
rec(obj[name])
|
||||
}</li>;
|
||||
});
|
||||
|
||||
if (res.*.length())
|
||||
return res;
|
||||
return <></>;
|
||||
}
|
||||
|
||||
return rec(roots);
|
||||
}
|
||||
|
||||
cache.register("modes.dtd", function ()
|
||||
util.makeDTD(iter({ "modes.tree": makeTree() },
|
||||
config.dtd)));
|
||||
},
|
||||
mappings: function initMappings() {
|
||||
mappings.add([modes.BASE, modes.NORMAL],
|
||||
["<Esc>", "<C-[>"],
|
||||
|
||||
@@ -21,7 +21,7 @@ var MOW = Module("mow", {
|
||||
if (modes.have(modes.OUTPUT_MULTILINE)) {
|
||||
this.resize(true);
|
||||
|
||||
if (options["more"] && this.isScrollable(1)) {
|
||||
if (options["more"] && this.canScroll(1)) {
|
||||
// start the last executed command's output at the top of the screen
|
||||
let elements = this.document.getElementsByClassName("ex-command-output");
|
||||
DOM(elements[elements.length - 1]).scrollIntoView(true);
|
||||
@@ -219,7 +219,7 @@ var MOW = Module("mow", {
|
||||
onKeyPress: function onKeyPress(eventList) {
|
||||
const KILL = false, PASS = true;
|
||||
|
||||
if (options["more"] && mow.isScrollable(1))
|
||||
if (options["more"] && mow.canScroll(1))
|
||||
this.updateMorePrompt(false, true);
|
||||
else {
|
||||
modes.pop();
|
||||
@@ -279,7 +279,7 @@ var MOW = Module("mow", {
|
||||
|
||||
if (showHelp)
|
||||
this.widgets.message = ["MoreMsg", _("mow.moreHelp")];
|
||||
else if (force || (options["more"] && Buffer.isScrollable(elem, 1)))
|
||||
else if (force || (options["more"] && Buffer.canScroll(elem, 1)))
|
||||
this.widgets.message = ["MoreMsg", _("mow.more")];
|
||||
else
|
||||
this.widgets.message = ["Question", _("mow.continue")];
|
||||
@@ -341,36 +341,36 @@ var MOW = Module("mow", {
|
||||
|
||||
bind(["j", "<C-e>", "<Down>"], "Scroll down one line",
|
||||
function ({ count }) { mow.scrollVertical("lines", 1 * (count || 1)); },
|
||||
function () mow.isScrollable(1), BEEP);
|
||||
function () mow.canScroll(1), BEEP);
|
||||
|
||||
bind(["k", "<C-y>", "<Up>"], "Scroll up one line",
|
||||
function ({ count }) { mow.scrollVertical("lines", -1 * (count || 1)); },
|
||||
function () mow.isScrollable(-1), BEEP);
|
||||
function () mow.canScroll(-1), BEEP);
|
||||
|
||||
bind(["<C-j>", "<C-m>", "<Return>"], "Scroll down one line, exit on last line",
|
||||
function ({ count }) { mow.scrollVertical("lines", 1 * (count || 1)); },
|
||||
function () mow.isScrollable(1), DROP);
|
||||
function () mow.canScroll(1), DROP);
|
||||
|
||||
// half page down
|
||||
bind(["<C-d>"], "Scroll down half a page",
|
||||
function ({ count }) { mow.scrollVertical("pages", .5 * (count || 1)); },
|
||||
function () mow.isScrollable(1), BEEP);
|
||||
function () mow.canScroll(1), BEEP);
|
||||
|
||||
bind(["<C-f>", "<PageDown>"], "Scroll down one page",
|
||||
function ({ count }) { mow.scrollVertical("pages", 1 * (count || 1)); },
|
||||
function () mow.isScrollable(1), BEEP);
|
||||
function () mow.canScroll(1), BEEP);
|
||||
|
||||
bind(["<Space>"], "Scroll down one page",
|
||||
function ({ count }) { mow.scrollVertical("pages", 1 * (count || 1)); },
|
||||
function () mow.isScrollable(1), DROP);
|
||||
function () mow.canScroll(1), DROP);
|
||||
|
||||
bind(["<C-u>"], "Scroll up half a page",
|
||||
function ({ count }) { mow.scrollVertical("pages", -.5 * (count || 1)); },
|
||||
function () mow.isScrollable(-1), BEEP);
|
||||
function () mow.canScroll(-1), BEEP);
|
||||
|
||||
bind(["<C-b>", "<PageUp>"], "Scroll up half a page",
|
||||
function ({ count }) { mow.scrollVertical("pages", -1 * (count || 1)); },
|
||||
function () mow.isScrollable(-1), BEEP);
|
||||
function () mow.canScroll(-1), BEEP);
|
||||
|
||||
bind(["gg"], "Scroll to the beginning of output",
|
||||
function () { mow.scrollToPercent(null, 0); });
|
||||
|
||||
Reference in New Issue
Block a user