Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
311 changes: 158 additions & 153 deletions src/electron/menu.js
Original file line number Diff line number Diff line change
@@ -1,152 +1,166 @@
var app = require('app');
var Menu = require('menu');
var debug = require('debug')('scout-electron:menu');

function getTemplate(_window) {
if (process.platform === 'darwin') {
return [
{
label: 'MongoDB Compass',
submenu: [
{
label: 'About Compass',
selector: 'orderFrontStandardAboutPanel:'
},
{
type: 'separator'
},
{
label: 'Hide',
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: 'Connect',
submenu: [
{
label: 'Connect to...',
accelerator: 'Command+N',
click: function() {
app.emit('show connect dialog');
}
var menu = (function() {
return {
init: function(window) {
/* eslint-disable no-extra-parens */
var menu = (process.platform == 'darwin')
? darwinMenu(window) : nonDarwinMenu(window);
/* eslint-enable no-extra-parens */
menu = Menu.buildFromTemplate(menu);
Menu.setApplicationMenu(menu);
}
};
}());

// menus
function darwinMenu(window) {
return [
{
label: 'MongoDB Compass',
submenu: [
{
label: 'About Compass',
selector: 'orderFrontStandardAboutPanel:'
},
{
type: 'separator'
},
{
label: 'Hide',
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',
role: 'undo'
},
{
label: 'Redo',
accelerator: 'Shift+Command+Z',
role: 'redo'
},
{
type: 'separator'
},
{
label: 'Cut',
accelerator: 'Command+X',
role: 'cut'
},
{
label: 'Copy',
accelerator: 'Command+C',
role: 'copy'
},
{
label: 'Paste',
accelerator: 'Command+V',
role: 'paste'
},
{
label: 'Select All',
accelerator: 'Command+A',
role: 'selectall'
}
]
},
{
label: 'Connect',
submenu: [
{
label: 'Connect to...',
accelerator: 'Command+N',
click: function() {
app.emit('show connect dialog');
}
]
},
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: function() {
_window.restart();
}
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function() {
_window.toggleDevTools();
}
}
]
},
{
label: 'Edit',
submenu: [
{
label: 'Undo',
accelerator: 'Command+Z',
role: 'undo'
},
{
label: 'Redo',
accelerator: 'Shift+Command+Z',
role: 'redo'
},
{
type: 'separator'
},
{
label: 'Cut',
accelerator: 'Command+X',
role: 'cut'
},
{
label: 'Copy',
accelerator: 'Command+C',
role: 'copy'
},
{
label: 'Paste',
accelerator: 'Command+V',
role: 'paste'
},
{
label: 'Select All',
accelerator: 'Command+A',
role: 'selectall'
}
]
},
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: function() {
window.restart();
}
]
},
{
label: 'Share',
submenu: [
{
label: 'Share Schema as JSON',
accelerator: 'Alt+Command+S',
click: function() {
_window.webContents.send('message', 'menu-share-schema-json');
}
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
click: function() {
window.toggleDevTools();
}
]
},
{
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
role: 'minimize'
},
{
label: 'Close',
accelerator: 'Command+W',
role: 'close'
},
{
type: 'separator'
},
{
label: 'Bring All to Front',
selector: 'arrangeInFront:'
}
]
},

{
label: 'Share',
submenu: [
{
label: 'Share Schema as JSON',
accelerator: 'Alt+Command+S',
click: function() {
window.webContents.send('message', 'menu-share-schema-json');
}
]
}
];
}
}
]
},
{
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
role: 'minimize'
},
{
label: 'Close',
accelerator: 'Command+W',
role: 'close'
},
{
type: 'separator'
},
{
label: 'Bring All to Front',
selector: 'arrangeInFront:'
}
]
}
];
};

function nonDarwinMenu(window) {
return [
{
label: 'File',
Expand Down Expand Up @@ -177,28 +191,19 @@ function getTemplate(_window) {
label: 'Reload',
accelerator: 'Ctrl+R',
click: function() {
_window.restart();
window.restart();
}
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Ctrl+I',
click: function() {
_window.toggleDevTools();
window.toggleDevTools();
}
}
]
}
];
}

/**
* @param {BrowserWindow} _window - The window to attach to.
* @see https://github.com/atom/electron/blob/master/docs/api/menu.md
*/
module.exports = function(_window) {
debug('attaching window menu');
var template = getTemplate(_window);
var menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
};

module.exports = menu;
4 changes: 2 additions & 2 deletions src/electron/window-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
var path = require('path');
var _ = require('lodash');
var app = require('app');
var attachMenu = require('./menu');
var BrowserWindow = require('browser-window');
var config = require('./config');
var debug = require('debug')('scout-electron:window-manager');
var menu = require('./menu');

/**
* When running in electron, we're in `RESOURCES/src/electron`.
Expand Down Expand Up @@ -62,6 +62,7 @@ module.exports.create = function(opts) {
'direct-write': true
}
});
menu.init(_window);

// makes the application a single instance application
// see "app.makeSingleInstance" in https://github.com/atom/electron/blob/master/docs/api/app.md
Expand All @@ -79,7 +80,6 @@ module.exports.create = function(opts) {
return;
}

attachMenu(_window);
_window.loadUrl(opts.url);

_window.webContents.on('new-window', function(event, url) {
Expand Down