Skip to content

Instantly share code, notes, and snippets.

@daverave1212
Created October 20, 2018 12:59
Show Gist options
  • Save daverave1212/1f2b7e554bf194a54d0612713b16bd64 to your computer and use it in GitHub Desktop.
Save daverave1212/1f2b7e554bf194a54d0612713b16bd64 to your computer and use it in GitHub Desktop.
// Custom MenuItem creator/parser
function createMenuItem(arrayObject){
var nw = require("nw.gui");
var thisItem;
if(arrayObject[1] && (typeof arrayObject[1]) != "string" && !Array.isArray(arrayObject[1])){
thisItem = new nw.MenuItem({
label : arrayObject[0],
click : arrayObject[1]});}
else{
var innerSubmenu = new nw.Menu();
for(var i = 0; i<arrayObject[1].length; i++){
innerSubmenu.append(createMenuItem(arrayObject[1][i]));
}
thisItem = new nw.MenuItem({
label : arrayObject[0],
submenu : innerSubmenu
});
}
return thisItem;
}
// Example
/*
function foo(){alert("Ello");}
var myMenu = createMenuItem(["MyMenu", [
["Help", [
["About", foo],
["Hello", foo]
]],
["File", [
["Save", foo],
["New", foo]
]],
["Close", foo]
]]);
var windowMenu = new require('nw.gui').Menu({
type: 'menubar'
});
windowMenu.append(myMenu);
require('nw.gui').Window.get().menu = windowMenu;
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment