From cc3066e7466402e14c04c4f58d96552fd4651fae Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 4 Jun 2015 14:54:53 +0800 Subject: [PATCH] Create a default menu for apps ran by default_app --- atom/browser/default_app/default_app.js | 214 --------------------- atom/browser/default_app/main.js | 242 ++++++++++++++++++++++++ 2 files changed, 242 insertions(+), 214 deletions(-) diff --git a/atom/browser/default_app/default_app.js b/atom/browser/default_app/default_app.js index 6b52d3f2..2378902b 100644 --- a/atom/browser/default_app/default_app.js +++ b/atom/browser/default_app/default_app.js @@ -1,10 +1,7 @@ var app = require('app'); -var Menu = require('menu'); -var MenuItem = require('menu-item'); var BrowserWindow = require('browser-window'); var mainWindow = null; -var menu = null; // Quit when all windows are closed. app.on('window-all-closed', function() { @@ -20,215 +17,4 @@ app.on('ready', function() { }); mainWindow.loadUrl('file://' + __dirname + '/index.html'); mainWindow.focus(); - - if (process.platform == 'darwin') { - var template = [ - { - label: 'Electron', - submenu: [ - { - label: 'About Electron', - selector: 'orderFrontStandardAboutPanel:' - }, - { - type: 'separator' - }, - { - label: 'Services', - submenu: [] - }, - { - type: 'separator' - }, - { - label: 'Hide Electron', - accelerator: 'Command+H', - selector: 'hide:' - }, - { - label: 'Hide Others', - accelerator: 'Command+Shift+H', - selector: 'hideOtherApplications:' - }, - { - label: 'Show All', - selector: 'unhideAllApplications:' - }, - { - type: 'separator' - }, - { - label: 'Quit', - accelerator: 'Command+Q', - click: function() { app.quit(); } - }, - ] - }, - { - label: 'Edit', - submenu: [ - { - label: 'Undo', - accelerator: 'Command+Z', - selector: 'undo:' - }, - { - label: 'Redo', - accelerator: 'Shift+Command+Z', - selector: 'redo:' - }, - { - type: 'separator' - }, - { - label: 'Cut', - accelerator: 'Command+X', - selector: 'cut:' - }, - { - label: 'Copy', - accelerator: 'Command+C', - selector: 'copy:' - }, - { - label: 'Paste', - accelerator: 'Command+V', - selector: 'paste:' - }, - { - label: 'Select All', - accelerator: 'Command+A', - selector: 'selectAll:' - }, - ] - }, - { - label: 'View', - submenu: [ - { - label: 'Reload', - accelerator: 'Command+R', - click: function() { mainWindow.restart(); } - }, - { - label: 'Toggle Full Screen', - accelerator: 'Ctrl+Command+F', - click: function() { mainWindow.setFullScreen(!mainWindow.isFullScreen()); } - }, - { - label: 'Toggle Developer Tools', - accelerator: 'Alt+Command+I', - click: function() { mainWindow.toggleDevTools(); } - }, - ] - }, - { - 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:' - }, - ] - }, - { - label: 'Help', - submenu: [ - { - label: 'Learn More', - click: function() { require('shell').openExternal('http://electron.atom.io') } - }, - { - label: 'Documentation', - click: function() { require('shell').openExternal('https://github.com/atom/electron/tree/master/docs#readme') } - }, - { - label: 'Community Discussions', - click: function() { require('shell').openExternal('https://discuss.atom.io/c/electron') } - }, - { - label: 'Search Issues', - click: function() { require('shell').openExternal('https://github.com/atom/electron/issues') } - } - ] - } - ]; - - menu = Menu.buildFromTemplate(template); - Menu.setApplicationMenu(menu); - } else { - var template = [ - { - label: '&File', - submenu: [ - { - label: '&Open', - accelerator: 'Ctrl+O', - }, - { - label: '&Close', - accelerator: 'Ctrl+W', - click: function() { mainWindow.close(); } - }, - ] - }, - { - label: '&View', - submenu: [ - { - label: '&Reload', - accelerator: 'Ctrl+R', - click: function() { mainWindow.restart(); } - }, - { - label: 'Toggle &Full Screen', - accelerator: 'F11', - click: function() { mainWindow.setFullScreen(!mainWindow.isFullScreen()); } - }, - { - label: 'Toggle &Developer Tools', - accelerator: 'Alt+Ctrl+I', - click: function() { mainWindow.toggleDevTools(); } - }, - ] - }, - { - label: 'Help', - submenu: [ - { - label: 'Learn More', - click: function() { require('shell').openExternal('http://electron.atom.io') } - }, - { - label: 'Documentation', - click: function() { require('shell').openExternal('https://github.com/atom/electron/tree/master/docs#readme') } - }, - { - label: 'Community Discussions', - click: function() { require('shell').openExternal('https://discuss.atom.io/c/electron') } - }, - { - label: 'Search Issues', - click: function() { require('shell').openExternal('https://github.com/atom/electron/issues') } - } - ] - } - ]; - - menu = Menu.buildFromTemplate(template); - mainWindow.setMenu(menu); - } }); diff --git a/atom/browser/default_app/main.js b/atom/browser/default_app/main.js index 1726ffba..3ca8081e 100644 --- a/atom/browser/default_app/main.js +++ b/atom/browser/default_app/main.js @@ -2,6 +2,8 @@ var app = require('app'); var dialog = require('dialog'); var fs = require('fs'); var path = require('path'); +var Menu = require('menu'); +var BrowserWindow = require('browser-window'); // Quit when all windows are closed and no other one is listening to this. app.on('window-all-closed', function() { @@ -29,6 +31,246 @@ for (var i in argv) { } } +// Create default menu. +app.once('ready', function() { + var template; + if (process.platform == 'darwin') { + template = [ + { + label: 'Electron', + submenu: [ + { + label: 'About Electron', + selector: 'orderFrontStandardAboutPanel:' + }, + { + type: 'separator' + }, + { + label: 'Services', + submenu: [] + }, + { + type: 'separator' + }, + { + label: 'Hide Electron', + accelerator: 'Command+H', + selector: 'hide:' + }, + { + label: 'Hide Others', + accelerator: 'Command+Shift+H', + selector: 'hideOtherApplications:' + }, + { + label: 'Show All', + selector: 'unhideAllApplications:' + }, + { + type: 'separator' + }, + { + label: 'Quit', + accelerator: 'Command+Q', + click: function() { app.quit(); } + }, + ] + }, + { + label: 'Edit', + submenu: [ + { + label: 'Undo', + accelerator: 'Command+Z', + selector: 'undo:' + }, + { + label: 'Redo', + accelerator: 'Shift+Command+Z', + selector: 'redo:' + }, + { + type: 'separator' + }, + { + label: 'Cut', + accelerator: 'Command+X', + selector: 'cut:' + }, + { + label: 'Copy', + accelerator: 'Command+C', + selector: 'copy:' + }, + { + label: 'Paste', + accelerator: 'Command+V', + selector: 'paste:' + }, + { + label: 'Select All', + accelerator: 'Command+A', + selector: 'selectAll:' + }, + ] + }, + { + label: 'View', + submenu: [ + { + label: 'Reload', + accelerator: 'Command+R', + click: function() { + var focusedWindow = BrowserWindow.getFocusedWindow(); + if (focusedWindow) + mainWindow.restart(); + } + }, + { + label: 'Toggle Full Screen', + accelerator: 'Ctrl+Command+F', + click: function() { + var focusedWindow = BrowserWindow.getFocusedWindow(); + if (focusedWindow) + focusedWindow.setFullScreen(!focusedWindow.isFullScreen()); + } + }, + { + label: 'Toggle Developer Tools', + accelerator: 'Alt+Command+I', + click: function() { + var focusedWindow = BrowserWindow.getFocusedWindow(); + if (focusedWindow) + focusedWindow.toggleDevTools(); + } + }, + ] + }, + { + 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:' + }, + ] + }, + { + label: 'Help', + submenu: [ + { + label: 'Learn More', + click: function() { require('shell').openExternal('http://electron.atom.io') } + }, + { + label: 'Documentation', + click: function() { require('shell').openExternal('https://github.com/atom/electron/tree/master/docs#readme') } + }, + { + label: 'Community Discussions', + click: function() { require('shell').openExternal('https://discuss.atom.io/c/electron') } + }, + { + label: 'Search Issues', + click: function() { require('shell').openExternal('https://github.com/atom/electron/issues') } + } + ] + } + ]; + } else { + template = [ + { + label: '&File', + submenu: [ + { + label: '&Open', + accelerator: 'Ctrl+O', + }, + { + label: '&Close', + accelerator: 'Ctrl+W', + click: function() { + var focusedWindow = BrowserWindow.getFocusedWindow(); + if (focusedWindow) + focusedWindow.close(); + } + }, + ] + }, + { + label: '&View', + submenu: [ + { + label: '&Reload', + accelerator: 'Ctrl+R', + click: function() { + var focusedWindow = BrowserWindow.getFocusedWindow(); + if (focusedWindow) + focusedWindow.reload(); + } + }, + { + label: 'Toggle &Full Screen', + accelerator: 'F11', + click: function() { + var focusedWindow = BrowserWindow.getFocusedWindow(); + if (focusedWindow) + focusedWindow.setFullScreen(!focusedWindow.isFullScreen()); + } + }, + { + label: 'Toggle &Developer Tools', + accelerator: 'Alt+Ctrl+I', + click: function() { + var focusedWindow = BrowserWindow.getFocusedWindow(); + if (focusedWindow) + focusedWindow.toggleDevTools(); + } + }, + ] + }, + { + label: 'Help', + submenu: [ + { + label: 'Learn More', + click: function() { require('shell').openExternal('http://electron.atom.io') } + }, + { + label: 'Documentation', + click: function() { require('shell').openExternal('https://github.com/atom/electron/tree/master/docs#readme') } + }, + { + label: 'Community Discussions', + click: function() { require('shell').openExternal('https://discuss.atom.io/c/electron') } + }, + { + label: 'Search Issues', + click: function() { require('shell').openExternal('https://github.com/atom/electron/issues') } + } + ] + } + ]; + } + + var menu = Menu.buildFromTemplate(template); + Menu.setApplicationMenu(menu); +}); + // Start the specified app if there is one specified in command line, otherwise // start the default app. if (option.file && !option.webdriver) { -- 2.43.0