//TODO: force this to be re-evaluated all the time
//if(CmdUtils.getDocument().location.href.indexOf("https://bespin.mozilla.com/") == 0){
var bespin = {cmd : {commands : {}}};
bespin.cmd.commands.add = function(obj){
var cmd = {};
var roles = ["object", "goal", "source", "location", "time"];
var ubiqArgs = [];
for(i in obj.takes){
ubiqArgs[i] = {role:roles[i],
nountype: noun_arb_text,
label : obj.takes[i]};
}
var names = [obj.name];
if(obj.aliases){
names = names.concat(obj.aliases);
}
var preview = obj.preview?obj.preview:"" +
"
" + obj.usage?" Usage — " + obj.usage:"";
cmd["takes"] = null;
cmd["names"] = names;
cmd["icon"] = "https://bespin.mozilla.com/favicon.ico";
cmd["arguments"] = ubiqArgs;
cmd["description"] = obj.description?obj.description : "";
cmd["preview"] = preview;
cmd["execute"] = function( arguments ){
if(CmdUtils.getDocument().location.href.indexOf("https://bespin.mozilla.com/") != 0){
displayMessage("The command you just executed is a Bespin command and will only work if Bespin is your active tab.");
return;
}
var bespin = CmdUtils.getWindowInsecure().bespin;
var window = CmdUtils.getWindow();
var args = [];
for (i in obj.takes){
args.push(arguments[roles[i]].text?arguments[roles[i]].text:null);
}
bespin.get("actions").focusCommandline();
bespin.get("commandLine").executeCommand( obj.name + " " + args.join(" "), false);
}
CmdUtils.CreateCommand(cmd);
};
//TODO: stop the key event from propagating
//TODO: don't show hidden commands?
// ** {{{bespin.cmd.commands.add}}} **
//
// Add the command to the store which has a name -> command hash
// bespin.cmd.commands.add = function(command) {
// bespin.cmd.commands.store[command.name] = command;
// };
//
// // ** {{{bespin.cmd.commands.get}}} **
// //
// // Return a command from the store
// bespin.cmd.commands.get = function(commandname) {
// return bespin.cmd.commands.store[commandname];
// };
//
// // ** {{{Command: bespin.cmd.commands.toArgArray}}} **
// // Helper for when you have a command that needs to get a hold of it's params
// // as an array for processing
// bespin.cmd.commands.toArgArray = function(args) {
// if (args == null) {
// return [];
// }
// else {
// var spliten = args.split(" ");
// if (spliten.length == 1 && spliten[0] == "") {
// return [];
// }
// else {
// return spliten;
// }
// }
// };
//
// // == Start adding commands to the store ==
// //
// bespin.cmd.displayHelp = function(commandStore, instruction, extra, morehelpoutput) {
// var commands = [];
// var command, name;
//
// if (commandStore.commands[extra]) { // caught a real command
// command = commandStore.commands[extra];
// commands.push(command['description'] ? command.description : command.preview);
// } else {
// var showHidden = false;
//
// var subcmdextra = "";
// if (commandStore.subcommandFor) subcmdextra = " for " + commandStore.subcommandFor;
//
// if (extra) {
// if (extra == "hidden") { // sneaky, sneaky.
// extra = "";
// showHidden = true;
// }
// commands.push("Commands starting with '" + extra + "'.
");
// }
//
// var tobesorted = [];
// for (name in commandStore.commands) {
// tobesorted.push(name);
// }
//
// var sorted = tobesorted.sort();
//
// commands.push("
| ' + name + ' | '); // commands.push('' + command.preview + " | "); // commands.push('' + args + ' | '); // commands.push("
|---|
| " + keyInfo + " | → | " + descriptions[keys] + " |
| " + x + " | → | " + aliases[x] + " |
| ' + count + ' | '); output.push('' + instruction.typed + " | "); output.push("
|---|