diff --git a/package.json b/package.json index ca22ed54db1..0ff9a8c0139 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "app", "auto-updater", "crash-reporter", + "dialog", "browser-window", "menu", "jade", diff --git a/src/electron/menu.js b/src/electron/menu.js index ffdb2d114eb..ce792ecf6c5 100644 --- a/src/electron/menu.js +++ b/src/electron/menu.js @@ -1,206 +1,244 @@ +// based off of https://github.com/atom/atom/blob/master/src/browser/application-menu.coffee +// use js2.coffee to convert it to JS + var app = require('app'); +var BrowserWindow = require('browser-window'); var Menu = require('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: 'Connect', - submenu: [ - { - label: 'Connect to...', - accelerator: 'Command+N', - click: function() { - app.emit('show connect dialog'); - } +// submenus +function quitSubMenu() { + return { + label: 'Quit', + accelerator: 'CmdOrCtrl+Q', + click: function() { + app.quit(); + } + }; +} + +function darwinCompassSubMenu() { + 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' + }, + quitSubMenu() + ] + }; +} + +function connectSubMenu() { + return { + label: 'Connect', + submenu: [ + { + label: 'Connect to...', + accelerator: 'CmdOrCtrl+N', + click: function() { + app.emit('show connect dialog'); } - ] - }, - { - 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' + } + ] + }; +} + +function editSubMenu() { + return { + 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' + } + ] + }; +} + +function nonDarwinCompassSubMenu() { + return { + label: 'MongoDB Compass', + submenu: [ + { + label: 'About Compass', + click: function() { + app.emit('show about dialog'); } - ] - }, - { - label: 'View', - submenu: [ - { - label: 'Reload', - accelerator: 'Command+R', - click: function() { - window.restart(); - } - }, - { - label: 'Toggle DevTools', - accelerator: 'Alt+Command+I', - click: function() { - window.toggleDevTools(); - } + }, + quitSubMenu() + ] + }; +} + +function shareSubMenu() { + return { + label: 'Share', + submenu: [ + { + label: 'Share Schema as JSON', + accelerator: 'Alt+CmdOrCtrl+S', + click: function() { + BrowserWindow.getFocusedWindow().webContents.send('message', 'menu-share-schema-json'); } - ] - }, - - { - label: 'Share', - submenu: [ - { - label: 'Share Schema as JSON', - accelerator: 'Alt+Command+S', - click: function() { - window.webContents.send('message', 'menu-share-schema-json'); - } + } + ] + }; +} + +function viewSubMenu() { + return { + label: 'View', + submenu: [ + { + label: 'Reload', + accelerator: 'CmdOrCtrl+R', + click: function() { + BrowserWindow.getFocusedWindow().restart(); } - ] - }, - { - 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: 'Toggle DevTools', + accelerator: 'Alt+CmdOrCtrl+I', + click: function() { + BrowserWindow.getFocusedWindow().toggleDevTools(); } - ] - } + } + ] + }; +} + +function windowSubMenu() { + return { + 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:' + } + ] + }; +} + +// menus +function darwinMenu(showConnectSubMenu, showShareSubMenu) { + var m = [ + darwinCompassSubMenu() ]; + + if (showConnectSubMenu) { + m.push(connectSubMenu()); + } + + m.push(editSubMenu()); + m.push(viewSubMenu()); + + if (showShareSubMenu) { + m.push(shareSubMenu()); + } + + m.push(windowSubMenu()); + + return m; } -function nonDarwinMenu(window) { - return [ - { - label: 'File', - submenu: [ - { - label: 'Connect to...', - accelerator: 'Ctrl+N', - click: function() { - app.emit('show connect dialog'); - } - }, - { - type: 'separator' - }, - { - label: 'Quit', - accelerator: 'Ctrl+Q', - click: function() { - app.quit(); - } - } - ] - }, - { - label: 'View', - submenu: [ - { - label: 'Reload', - accelerator: 'Ctrl+R', - click: function() { - window.restart(); - } - }, - { - label: 'Toggle DevTools', - accelerator: 'Alt+Ctrl+I', - click: function() { - window.toggleDevTools(); - } - } - ] - } +function nonDarwinMenu(showConnectSubMenu, showShareSubMenu) { + var m = [ + nonDarwinCompassSubMenu() ]; + + if (showConnectSubMenu) { + m.push(connectSubMenu()); + } + + m.push(viewSubMenu()); + + if (showShareSubMenu) { + m.push(shareSubMenu()); + } + + return m; } +// menu singleton var menu = (function() { return { - init: function(window) { + load: function(showConnectSubMenu, showShareSubMenu) { + if (typeof showConnectSubMenu === 'undefined') { + showConnectSubMenu = true; + } + + if (typeof showShareSubMenu === 'undefined') { + showShareSubMenu = true; + } + var m; if (process.platform === 'darwin') { - m = darwinMenu(window); + m = darwinMenu(showConnectSubMenu, showShareSubMenu); } else { - m = nonDarwinMenu(window); + m = nonDarwinMenu(showConnectSubMenu, showShareSubMenu); } m = Menu.buildFromTemplate(m); Menu.setApplicationMenu(m); diff --git a/src/electron/window-manager.js b/src/electron/window-manager.js index 4f6548c3bfb..b534354a9c0 100644 --- a/src/electron/window-manager.js +++ b/src/electron/window-manager.js @@ -9,6 +9,7 @@ var app = require('app'); var BrowserWindow = require('browser-window'); var config = require('./config'); var debug = require('debug')('scout-electron:window-manager'); +var dialog = require('dialog'); var menu = require('./menu'); /** @@ -62,7 +63,7 @@ module.exports.create = function(opts) { 'direct-write': true } }); - menu.init(_window); + menu.load(); // makes the application a single instance application // see "app.makeSingleInstance" in https://github.com/atom/electron/blob/master/docs/api/app.md @@ -141,6 +142,14 @@ app.on('show connect dialog', function(opts) { module.exports.create(opts); }); +app.on('show about dialog', function() { + dialog.showMessageBox({ + type: 'info', + message: 'MongoDB Compass Version: ' + app.getVersion(), + buttons: [] + }); +}); + /** * When electron's main renderer has completed setup, * we'll always show the [connect][./src/connect] dialog diff --git a/src/home/collection.js b/src/home/collection.js index 25bbe6f3166..93eb7409512 100644 --- a/src/home/collection.js +++ b/src/home/collection.js @@ -75,6 +75,7 @@ var MongoDBCollectionView = View.extend({ schemaIsSynced: function() { // only listen to share menu events if we have a sync'ed schema // @todo enable share menu item here + // GLOBAL.menu.showShareMenu(); this.listenTo(app, 'menu-share-schema-json', this.onShareSchema.bind(this)); }, schemaIsRequested: function() {