Add Menu.buildFromTemplate API to greatly simplify building menu.
This commit is contained in:
parent
e58f115b43
commit
eec8abf397
2 changed files with 84 additions and 46 deletions
|
@ -44,4 +44,16 @@ Menu.setApplicationMenu = (menu) ->
|
||||||
|
|
||||||
Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder
|
Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder
|
||||||
|
|
||||||
|
Menu.buildFromTemplate = (template) ->
|
||||||
|
throw new TypeError('Invalid template for Menu') unless Array.isArray template
|
||||||
|
|
||||||
|
menu = new Menu
|
||||||
|
for item in template
|
||||||
|
throw new TypeError('Invalid template for MenuItem') unless typeof item is 'object'
|
||||||
|
|
||||||
|
item.submenu = Menu.buildFromTemplate item.submenu if item.submenu?
|
||||||
|
menu.append new MenuItem(item)
|
||||||
|
|
||||||
|
menu
|
||||||
|
|
||||||
module.exports = Menu
|
module.exports = Menu
|
||||||
|
|
|
@ -28,53 +28,79 @@ delegate.browserMainParts.preMainMessageLoopRun = function() {
|
||||||
mainWindow = null;
|
mainWindow = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
menu = new Menu;
|
var template = [
|
||||||
|
{
|
||||||
var appleMenu = new Menu;
|
label: 'Atom Shell',
|
||||||
appleMenu.append(new MenuItem({
|
submenu: [
|
||||||
label: 'About Atom Shell',
|
{
|
||||||
selector: 'orderFrontStandardAboutPanel:'
|
label: 'About Atom Shell',
|
||||||
}));
|
selector: 'orderFrontStandardAboutPanel:'
|
||||||
appleMenu.append(new MenuItem({ type: 'separator' }));
|
},
|
||||||
appleMenu.append(new MenuItem({
|
{
|
||||||
label: 'Hide Atom Shell',
|
type: 'separator'
|
||||||
accelerator: 'Command+H',
|
},
|
||||||
selector: 'hide:'
|
{
|
||||||
}));
|
label: 'Hide Atom Shell',
|
||||||
appleMenu.append(new MenuItem({
|
accelerator: 'Command+H',
|
||||||
label: 'Hide Others',
|
selector: 'hide:'
|
||||||
accelerator: 'Command+Shift+H',
|
},
|
||||||
selector: 'hideOtherApplications:'
|
{
|
||||||
}));
|
label: 'Hide Others',
|
||||||
appleMenu.append(new MenuItem({ type: 'separator' }));
|
accelerator: 'Command+Shift+H',
|
||||||
appleMenu.append(new MenuItem({
|
selector: 'hideOtherApplications:'
|
||||||
label: 'Quit',
|
},
|
||||||
accelerator: 'Command+Q',
|
{
|
||||||
click: function() {
|
label: 'Show All',
|
||||||
app.quit();
|
selector: 'unhideAllApplications:'
|
||||||
}
|
},
|
||||||
}));
|
{
|
||||||
|
type: 'separator'
|
||||||
var windowMenu = new Menu;
|
},
|
||||||
windowMenu.append(new MenuItem({
|
{
|
||||||
label: 'Minimize',
|
label: 'Quit',
|
||||||
accelerator: 'Command+M',
|
accelerator: 'Command+Q',
|
||||||
selector: 'performMiniaturize:'
|
click: function() { app.quit(); }
|
||||||
}));
|
},
|
||||||
windowMenu.append(new MenuItem({
|
]
|
||||||
label: 'Close',
|
},
|
||||||
accelerator: 'Command+W',
|
{
|
||||||
selector: 'performClose:'
|
label: 'View',
|
||||||
}));
|
submenu: [
|
||||||
windowMenu.append(new MenuItem({ type: 'separator' }));
|
{
|
||||||
windowMenu.append(new MenuItem({
|
label: 'Reload',
|
||||||
label: 'Bring All to Front',
|
accelerator: 'Command+R',
|
||||||
selector: 'arrangeInFront:'
|
},
|
||||||
}));
|
{
|
||||||
|
label: 'Show DevTools',
|
||||||
menu.append(new MenuItem({ submenu: appleMenu }));
|
accelerator: 'Alt+Command+I',
|
||||||
menu.append(new MenuItem({ label: 'Window', submenu: windowMenu }));
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Window',
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: 'Minimize',
|
||||||
|
accelerator: 'Command+M',
|
||||||
|
selector: 'performMiniaturize:'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Close',
|
||||||
|
accelerator: 'Command+W',
|
||||||
|
selector: 'performClose:'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Bring All to Front',
|
||||||
|
selector: 'arrangeInFront:'
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
menu = Menu.buildFromTemplate(template);
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
|
|
||||||
ipc.on('message', function(processId, routingId, type) {
|
ipc.on('message', function(processId, routingId, type) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue