diff --git a/common/components/chrome-data.js b/common/components/protocols.js similarity index 81% rename from common/components/chrome-data.js rename to common/components/protocols.js index d2471fd1..201d410f 100644 --- a/common/components/chrome-data.js +++ b/common/components/protocols.js @@ -97,12 +97,7 @@ function Liberator() this.__defineGetter__("helpNamespaces", function () NAMESPACES ? NAMESPACES.slice() : null); this.__defineSetter__("helpNamespaces", function (namespaces) { if (!NAMESPACES) - NAMESPACES = Array.slice(namespaces) - }); - this.__defineGetter__("helpFiles", function () HELP_FILES ? HELP_FILES.slice() : null); - this.__defineSetter__("helpFiles", function (files) { - if (!HELP_FILES) - parseHelpTags(files); + parseHelpTags(namespaces); }); function xpath(doc, expression) @@ -131,36 +126,53 @@ function Liberator() const self = this; this.HELP_TAGS = {}; - this.FILE_MAP = {}; + this.FILE_MAP = { all: "chrome://liberator/locale/all.xml" }; var NAMESPACES = null; var HELP_FILES = null; - function parseHelpTags(files) + function XSLTProcessor(sheet) { - const XSLT = Cc["@mozilla.org/document-transformer;1?type=xslt"].createInstance(Ci.nsIXSLTProcessor); - XSLT.importStylesheet(httpGet("chrome://liberator/content/help.xsl").responseXML); + let xslt = Cc["@mozilla.org/document-transformer;1?type=xslt"].createInstance(Ci.nsIXSLTProcessor); + xslt.importStylesheet(httpGet(sheet).responseXML); + return xslt; + } + + function findHelpFile(file) + { + for each (let namespace in NAMESPACES) + { + let url = ["chrome://", namespace, "/locale/", file, ".xml"].join(""); + let res = httpGet(url); + if (res && res.responseXML.documentElement.localName == "document") + return [url, res.responseXML]; + } + return [] + } + + function parseHelpTags(namespaces) + { + NAMESPACES = Array.slice(namespaces); + let files = xpath( + XSLTProcessor("chrome://liberator/content/overlay.xsl") + .transformToDocument(httpGet(self.FILE_MAP.all).responseXML), + "//liberator:include/@href"); + self.HELP_TAGS.all = "all"; + const XSLT = XSLTProcessor("chrome://liberator/content/help.xsl"); for each (let file in files) { try { - for each (let namespace in NAMESPACES) - { - let url = ["chrome://", namespace, "/locale/", file, ".xml"].join(""); - let res = httpGet(url); - if (res && res.responseXML.documentElement.localName == "document") - { - self.FILE_MAP[file] = url; - let doc = XSLT.transformToDocument(res.responseXML); - for (let elem in xpath(doc, "//liberator:tag/text()")) - self.HELP_TAGS[elem.textContent] = file; - break; - } - } + let [url, doc] = findHelpFile(file.value); + if (doc) + self.FILE_MAP[file.value] = url; + doc = XSLT.transformToDocument(doc); + for (let elem in xpath(doc, "//liberator:tag/text()")) + self.HELP_TAGS[elem.textContent] = file.value; } catch (e) { Components.utils.reportError(e); - dump(e); + dump(e + "\n"); } } HELP_FILES = Array.slice(files); diff --git a/common/content/configbase.js b/common/content/configbase.js index 41a5ada2..51a59608 100644 --- a/common/content/configbase.js +++ b/common/content/configbase.js @@ -50,13 +50,6 @@ const configbase = { //{{{ */ hostApplication: null, - /** - * @property {[string]} A list of HTML help files available under - * chrome://liberator/locale/. Used to generate help tag indexes for - * the :help command. - */ - helpFiles: [], - /** * @property {function} Called on liberator startup to allow for any * arbitrary application-specific initialization code. diff --git a/common/content/help.xsl b/common/content/help.xsl index 5763d4e3..e2e7f896 100644 --- a/common/content/help.xsl +++ b/common/content/help.xsl @@ -10,9 +10,6 @@ - - - @@ -142,6 +139,12 @@ + + + + diff --git a/common/content/liberator.js b/common/content/liberator.js index 6daf3c58..96006379 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -215,7 +215,7 @@ const liberator = (function () //{{{ options.add(["helpfile", "hf"], "Name of the main help file", - "string", "intro.html"); + "string", "intro"); options.add(["loadplugins", "lpl"], "Load plugin scripts when starting up", @@ -1356,6 +1356,8 @@ const liberator = (function () //{{{ */ findHelp: function (topic, unchunked) { + if (topic in services.get("liberator:").FILE_MAP) + return topic; unchunked = !!unchunked; let items = completion._runCompleter("help", topic, null, unchunked).items; let partialMatch = null; @@ -1388,8 +1390,8 @@ const liberator = (function () //{{{ if (!topic && !unchunked) { let helpFile = options["helpfile"]; - if (config.helpFiles.indexOf(helpFile) != -1) - liberator.open("liberator://help/" + helpFile.replace(/\.html$/, ""), { from: "help" }); + if (helpFile in services.get("liberator:").FILE_MAP) + liberator.open("liberator://help/" + helpFile, { from: "help" }); else liberator.echomsg("Sorry, help file " + helpFile.quote() + " not found"); return; @@ -1725,7 +1727,6 @@ const liberator = (function () //{{{ liberator.log("Initializing liberator object...", 0); services.get("liberator:").helpNamespaces = [config.name.toLowerCase(), "liberator"]; - services.get("liberator:").helpFiles = config.helpFiles.map(function (f) f.replace(/\..*/, "")); config.features.push(getPlatformFeature()); diff --git a/common/content/overlay.xsl b/common/content/overlay.xsl new file mode 100644 index 00000000..4e4dd393 --- /dev/null +++ b/common/content/overlay.xsl @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vimperator/content/config.js b/vimperator/content/config.js index 63653e0e..55ceb097 100644 --- a/vimperator/content/config.js +++ b/vimperator/content/config.js @@ -97,16 +97,6 @@ const config = { //{{{ hasTabbrowser: true, - // they are sorted by relevance, not alphabetically - helpFiles: [ - "intro.html", "tutorial.html", "starting.html", "browsing.html", - "buffer.html", "cmdline.html", "insert.html", "options.html", - "pattern.html", "tabs.html", "hints.html", "map.html", "eval.html", - "marks.html", "repeat.html", "autocommands.html", "print.html", - "gui.html", "styling.html", "message.html", "developer.html", - "various.html", "version.html", "index.html" - ], - get ignoreKeys() { delete this.ignoreKeys; return this.ignoreKeys = { diff --git a/xulmus/content/config.js b/xulmus/content/config.js index 546a82c7..153c0117 100644 --- a/xulmus/content/config.js +++ b/xulmus/content/config.js @@ -135,17 +135,6 @@ const config = { //{{{ hasTabbrowser: true, - // TODO : Write intro.html and tutorial.html - // they are sorted by relevance, not alphabetically - helpFiles: [ - "intro.html", /*"tutorial.html",*/ "starting.html", "player.html", - "browsing.html", "buffer.html", "cmdline.html", "insert.html", - "options.html", "pattern.html", "tabs.html", "hints.html", "map.html", - "eval.html", "marks.html", "repeat.html", "autocommands.html", - "print.html", "gui.html", "styling.html", "message.html", - "developer.html", "various.html", "index.html", "version.html" - ], - modes: [["PLAYER", { char: "p" }]], get ignoreKeys() {