pointvec/sources/scripts/controller.js

47 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-01-12 08:09:26 +00:00
function Controller()
{
this.menu = {default:{}};
this.mode = "default";
this.app = require('electron').remote.app;
this.start = function()
{
}
this.add = function(mode,cat,label,fn,accelerator)
{
if(!this.menu[mode]){ this.menu[mode] = {}; }
if(!this.menu[mode][cat]){ this.menu[mode][cat] = {}; }
this.menu[mode][cat][label] = {fn:fn,accelerator:accelerator};
2018-01-13 03:03:21 +00:00
console.log(`${mode}/${cat}/${label} <${accelerator}>`);
2018-01-12 08:09:26 +00:00
}
2018-01-13 03:03:21 +00:00
this.format = function()
2018-01-12 08:09:26 +00:00
{
var f = [];
var m = this.menu[this.mode];
for(cat in m){
var submenu = [];
for(name in m[cat]){
var option = m[cat][name];
submenu.push({label:name,accelerator:option.accelerator,click:option.fn})
}
f.push({label:cat,submenu:submenu});
}
2018-01-13 03:03:21 +00:00
return f;
}
this.commit = function()
{
this.app.inject_menu(this.format());
}
this.docs = function()
{
console.log("Generating docs..");
this.app.generate_docs(this.format());
2018-01-12 08:09:26 +00:00
}
}
module.exports = new Controller();