Show a simple menu in default_app on Windows.

This commit is contained in:
Cheng Zhao 2013-10-02 21:51:19 +08:00
parent 5c8566e0d4
commit 6748573dee

View file

@ -31,7 +31,6 @@ app.on('finish-launching', function() {
}); });
mainWindow.on('closed', function() { mainWindow.on('closed', function() {
console.log('closed');
mainWindow = null; mainWindow = null;
}); });
@ -39,131 +38,167 @@ app.on('finish-launching', function() {
console.log('unresponsive'); console.log('unresponsive');
}); });
var template = [ if (process.platform == 'darwin') {
{ var template = [
label: 'Atom Shell', {
submenu: [ label: 'Atom Shell',
{ submenu: [
label: 'About Atom Shell', {
selector: 'orderFrontStandardAboutPanel:' label: 'About Atom Shell',
}, selector: 'orderFrontStandardAboutPanel:'
{ },
type: 'separator' {
}, type: 'separator'
{ },
label: 'Hide Atom Shell', {
accelerator: 'Command+H', label: 'Hide Atom Shell',
selector: 'hide:' accelerator: 'Command+H',
}, selector: 'hide:'
{ },
label: 'Hide Others', {
accelerator: 'Command+Shift+H', label: 'Hide Others',
selector: 'hideOtherApplications:' accelerator: 'Command+Shift+H',
}, selector: 'hideOtherApplications:'
{ },
label: 'Show All', {
selector: 'unhideAllApplications:' label: 'Show All',
}, selector: 'unhideAllApplications:'
{ },
type: 'separator' {
}, type: 'separator'
{ },
label: 'Quit', {
accelerator: 'Command+Q', label: 'Quit',
click: function() { app.quit(); } accelerator: 'Command+Q',
}, click: function() { app.quit(); }
] },
}, ]
{ },
label: 'Edit', {
submenu: [ label: 'Edit',
{ submenu: [
label: 'Undo', {
accelerator: 'Command+Z', label: 'Undo',
selector: 'undo:' accelerator: 'Command+Z',
}, selector: 'undo:'
{ },
label: 'Redo', {
accelerator: 'Shift+Command+Z', label: 'Redo',
selector: 'redo:' accelerator: 'Shift+Command+Z',
}, selector: 'redo:'
{ },
type: 'separator' {
}, type: 'separator'
{ },
label: 'Cut', {
accelerator: 'Command+X', label: 'Cut',
selector: 'cut:' accelerator: 'Command+X',
}, selector: 'cut:'
{ },
label: 'Copy', {
accelerator: 'Command+C', label: 'Copy',
selector: 'copy:' accelerator: 'Command+C',
}, selector: 'copy:'
{ },
label: 'Paste', {
accelerator: 'Command+V', label: 'Paste',
selector: 'paste:' accelerator: 'Command+V',
}, selector: 'paste:'
{ },
label: 'Select All', {
accelerator: 'Command+A', label: 'Select All',
selector: 'selectAll:' accelerator: 'Command+A',
}, selector: 'selectAll:'
] },
}, ]
{ },
label: 'View', {
submenu: [ label: 'View',
{ submenu: [
label: 'Reload', {
accelerator: 'Command+R', label: 'Reload',
click: function() { BrowserWindow.getFocusedWindow().restart(); } accelerator: 'Command+R',
}, click: function() { BrowserWindow.getFocusedWindow().restart(); }
{ },
label: 'Enter Fullscreen', {
click: function() { BrowserWindow.getFocusedWindow().setFullscreen(true); } label: 'Enter Fullscreen',
}, click: function() { BrowserWindow.getFocusedWindow().setFullscreen(true); }
{ },
label: 'Toggle DevTools', {
accelerator: 'Alt+Command+I', label: 'Toggle DevTools',
click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); } accelerator: 'Alt+Command+I',
}, click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); }
] },
}, ]
{ },
label: 'Window', {
submenu: [ label: 'Window',
{ submenu: [
label: 'Minimize', {
accelerator: 'Command+M', label: 'Minimize',
selector: 'performMiniaturize:' accelerator: 'Command+M',
}, selector: 'performMiniaturize:'
{ },
label: 'Close', {
accelerator: 'Command+W', label: 'Close',
selector: 'performClose:' accelerator: 'Command+W',
}, selector: 'performClose:'
{ },
type: 'separator' {
}, type: 'separator'
{ },
label: 'Bring All to Front', {
selector: 'arrangeInFront:' label: 'Bring All to Front',
}, selector: 'arrangeInFront:'
] },
}, ]
]; },
];
menu = Menu.buildFromTemplate(template); menu = Menu.buildFromTemplate(template);
if (process.platform == 'darwin')
Menu.setApplicationMenu(menu); Menu.setApplicationMenu(menu);
else } else {
var template = [
{
label: 'File',
submenu: [
{
label: 'Open',
accelerator: 'Command+O',
},
{
label: 'Close',
accelerator: 'Command+W',
click: function() { mainWindow.close(); }
},
]
},
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: function() { mainWindow.restart(); }
},
{
label: 'Enter Fullscreen',
click: function() { mainWindow.setFullscreen(true); }
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function() { mainWindow.toggleDevTools(); }
},
]
},
];
menu = Menu.buildFromTemplate(template);
mainWindow.setMenu(menu); mainWindow.setMenu(menu);
}
ipc.on('message', function(processId, routingId, type) { ipc.on('message', function(processId, routingId, type) {
console.log(type);
if (type == 'menu') if (type == 'menu')
menu.popup(mainWindow); menu.popup(mainWindow);
}); });