mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 05:37:58 +01:00
Lazy load help files. Store command names in a map.
--HG-- branch : testing
This commit is contained in:
@@ -73,9 +73,9 @@ const Command = Class("Command", {
|
|||||||
modifiers = modifiers || {};
|
modifiers = modifiers || {};
|
||||||
|
|
||||||
let self = this;
|
let self = this;
|
||||||
function exec(args) {
|
function exec(command) {
|
||||||
// FIXME: Move to parseCommand?
|
// FIXME: Move to parseCommand?
|
||||||
args = self.parseArgs(args);
|
args = self.parseArgs(command);
|
||||||
if (!args)
|
if (!args)
|
||||||
return;
|
return;
|
||||||
args.count = count;
|
args.count = count;
|
||||||
@@ -237,6 +237,7 @@ const ArgType = Struct("description", "parse");
|
|||||||
const Commands = Module("commands", {
|
const Commands = Module("commands", {
|
||||||
init: function () {
|
init: function () {
|
||||||
this._exCommands = [];
|
this._exCommands = [];
|
||||||
|
this._exMap = {};
|
||||||
},
|
},
|
||||||
|
|
||||||
// FIXME: remove later, when our option handler is better
|
// FIXME: remove later, when our option handler is better
|
||||||
@@ -304,7 +305,7 @@ const Commands = Module("commands", {
|
|||||||
repeat: null,
|
repeat: null,
|
||||||
|
|
||||||
_addCommand: function (command, replace) {
|
_addCommand: function (command, replace) {
|
||||||
if (this._exCommands.some(function (c) c.hasName(command.name))) {
|
if (command.name in this._exMap) {
|
||||||
if (command.user && replace)
|
if (command.user && replace)
|
||||||
commands.removeUserCommand(command.name);
|
commands.removeUserCommand(command.name);
|
||||||
else {
|
else {
|
||||||
@@ -314,6 +315,8 @@ const Commands = Module("commands", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._exCommands.push(command);
|
this._exCommands.push(command);
|
||||||
|
for(let [,name] in Iterator(command.names))
|
||||||
|
this._exMap[name] = command;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@@ -387,7 +390,7 @@ const Commands = Module("commands", {
|
|||||||
* @returns {Command}
|
* @returns {Command}
|
||||||
*/
|
*/
|
||||||
get: function (name) {
|
get: function (name) {
|
||||||
return this._exCommands.filter(function (cmd) cmd.hasName(name))[0] || null;
|
return this._exMap[name] || this._exCommands.filter(function (cmd) cmd.hasName(name))[0] || null;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -762,6 +765,10 @@ const Commands = Module("commands", {
|
|||||||
* any of the command's names.
|
* any of the command's names.
|
||||||
*/
|
*/
|
||||||
removeUserCommand: function (name) {
|
removeUserCommand: function (name) {
|
||||||
|
for(let [,cmd] in Iterator(this._exCommands))
|
||||||
|
if(cmd.user && cmd.hasName(name))
|
||||||
|
for(let [,name] in Iterator(cmd.names))
|
||||||
|
delete this._exMap[name];
|
||||||
this._exCommands = this._exCommands.filter(function (cmd) !(cmd.user && cmd.hasName(name)));
|
this._exCommands = this._exCommands.filter(function (cmd) !(cmd.user && cmd.hasName(name)));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -597,6 +597,8 @@ lookup:
|
|||||||
*/
|
*/
|
||||||
source: function (filename, silent) {
|
source: function (filename, silent) {
|
||||||
let wasSourcing = this.sourcing;
|
let wasSourcing = this.sourcing;
|
||||||
|
liberator.dump("sourcing " + filename);
|
||||||
|
let time = Date.now();
|
||||||
try {
|
try {
|
||||||
var file = File(filename);
|
var file = File(filename);
|
||||||
this.sourcing = {
|
this.sourcing = {
|
||||||
@@ -715,6 +717,7 @@ lookup:
|
|||||||
liberator.echoerr(message);
|
liberator.echoerr(message);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
liberator.dump("done sourcing " + filename + ": " + (Date.now() - time) + "ms");
|
||||||
this.sourcing = wasSourcing;
|
this.sourcing = wasSourcing;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -544,6 +544,7 @@ const Liberator = Module("liberator", {
|
|||||||
* Initialize the help system.
|
* Initialize the help system.
|
||||||
*/
|
*/
|
||||||
initHelp: function () {
|
initHelp: function () {
|
||||||
|
if(!this.helpInitialized) {
|
||||||
let namespaces = [config.name.toLowerCase(), "liberator"];
|
let namespaces = [config.name.toLowerCase(), "liberator"];
|
||||||
services.get("liberator:").init({});
|
services.get("liberator:").init({});
|
||||||
|
|
||||||
@@ -623,6 +624,8 @@ const Liberator = Module("liberator", {
|
|||||||
fileMap["plugins"] = function () ['text/xml;charset=UTF-8', help];
|
fileMap["plugins"] = function () ['text/xml;charset=UTF-8', help];
|
||||||
|
|
||||||
addTags("plugins", util.httpGet("liberator://help/plugins").responseXML);
|
addTags("plugins", util.httpGet("liberator://help/plugins").responseXML);
|
||||||
|
this.helpInitialized = true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -634,6 +637,7 @@ const Liberator = Module("liberator", {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
help: function (topic, unchunked) {
|
help: function (topic, unchunked) {
|
||||||
|
liberator.initHelp();
|
||||||
if (!topic) {
|
if (!topic) {
|
||||||
let helpFile = unchunked ? "all" : options["helpfile"];
|
let helpFile = unchunked ? "all" : options["helpfile"];
|
||||||
if (helpFile in services.get("liberator:").FILE_MAP)
|
if (helpFile in services.get("liberator:").FILE_MAP)
|
||||||
@@ -1717,6 +1721,7 @@ const Liberator = Module("liberator", {
|
|||||||
};
|
};
|
||||||
|
|
||||||
completion.help = function help(context, unchunked) {
|
completion.help = function help(context, unchunked) {
|
||||||
|
liberator.initHelp();
|
||||||
context.title = ["Help"];
|
context.title = ["Help"];
|
||||||
context.anchored = false;
|
context.anchored = false;
|
||||||
context.completions = services.get("liberator:").HELP_TAGS;
|
context.completions = services.get("liberator:").HELP_TAGS;
|
||||||
@@ -1820,8 +1825,6 @@ const Liberator = Module("liberator", {
|
|||||||
if (options["loadplugins"])
|
if (options["loadplugins"])
|
||||||
liberator.loadPlugins();
|
liberator.loadPlugins();
|
||||||
|
|
||||||
liberator.initHelp();
|
|
||||||
|
|
||||||
// after sourcing the initialization files, this function will set
|
// after sourcing the initialization files, this function will set
|
||||||
// all gui options to their default values, if they have not been
|
// all gui options to their default values, if they have not been
|
||||||
// set before by any RC file
|
// set before by any RC file
|
||||||
|
|||||||
Reference in New Issue
Block a user