11var app = require ( 'app' ) ;
22var Menu = require ( 'menu' ) ;
3- var debug = require ( 'debug' ) ( 'scout-electron:menu' ) ;
43
5- function getTemplate ( _window ) {
6- if ( process . platform === 'darwin' ) {
7- return [
8- {
9- label : 'MongoDB Compass' ,
10- submenu : [
11- {
12- label : 'About Compass' ,
13- selector : 'orderFrontStandardAboutPanel:'
14- } ,
15- {
16- type : 'separator'
17- } ,
18- {
19- label : 'Hide' ,
20- accelerator : 'Command+H' ,
21- selector : 'hide:'
22- } ,
23- {
24- label : 'Hide Others' ,
25- accelerator : 'Command+Shift+H ' ,
26- selector : 'hideOtherApplications :'
27- } ,
28- {
29- label : 'Show All' ,
30- selector : 'unhideAllApplications:'
31- } ,
32- {
33- type : 'separator'
34- } ,
35- {
36- label : 'Quit' ,
37- accelerator : 'Command+Q ' ,
38- click : function ( ) {
39- app . quit ( ) ;
40- }
41- }
42- ]
43- } ,
44- {
45- label : 'Connect' ,
46- submenu : [
47- {
48- label : 'Connect to...' ,
49- accelerator : 'Command+N ' ,
50- click : function ( ) {
51- app . emit ( 'show connect dialog' ) ;
52- }
4+ var menu = ( function ( ) {
5+ return {
6+ init : function ( window ) {
7+ /* eslint-disable no-extra-parens */
8+ var menu = ( process . platform == 'darwin' )
9+ ? darwinMenu ( window ) : nonDarwinMenu ( window ) ;
10+ /* eslint-enable no-extra-parens */
11+ menu = Menu . buildFromTemplate ( menu ) ;
12+ Menu . setApplicationMenu ( menu ) ;
13+ }
14+ } ;
15+ } ( ) ) ;
16+
17+ // menus
18+ function darwinMenu ( window ) {
19+ return [
20+ {
21+ label : 'MongoDB Compass' ,
22+ submenu : [
23+ {
24+ label : 'About Compass ' ,
25+ selector : 'orderFrontStandardAboutPanel :'
26+ } ,
27+ {
28+ type : 'separator'
29+ } ,
30+ {
31+ label : 'Hide' ,
32+ accelerator : 'Command+H' ,
33+ selector : 'hide:'
34+ } ,
35+ {
36+ label : 'Hide Others ' ,
37+ accelerator : 'Command+Shift+H' ,
38+ selector : 'hideOtherApplications:'
39+ } ,
40+ {
41+ label : 'Show All' ,
42+ selector : 'unhideAllApplications:'
43+ } ,
44+ {
45+ type : 'separator'
46+ } ,
47+ {
48+ label : 'Quit ' ,
49+ accelerator : 'Command+Q' ,
50+ click : function ( ) {
51+ app . quit ( ) ;
5352 }
54- ]
55- } ,
56- {
57- label : 'Edit' ,
58- submenu : [
59- {
60- label : 'Undo' ,
61- accelerator : 'Command+Z' ,
62- role : 'undo'
63- } ,
64- {
65- label : 'Redo' ,
66- accelerator : 'Shift+Command+Z' ,
67- role : 'redo'
68- } ,
69- {
70- type : 'separator'
71- } ,
72- {
73- label : 'Cut' ,
74- accelerator : 'Command+X' ,
75- role : 'cut'
76- } ,
77- {
78- label : 'Copy' ,
79- accelerator : 'Command+C' ,
80- role : 'copy'
81- } ,
82- {
83- label : 'Paste' ,
84- accelerator : 'Command+V' ,
85- role : 'paste'
86- } ,
87- {
88- label : 'Select All' ,
89- accelerator : 'Command+A' ,
90- role : 'selectall'
53+ }
54+ ]
55+ } ,
56+ {
57+ label : 'Connect' ,
58+ submenu : [
59+ {
60+ label : 'Connect to...' ,
61+ accelerator : 'Command+N' ,
62+ click : function ( ) {
63+ app . emit ( 'show connect dialog' ) ;
9164 }
92- ]
93- } ,
94- {
95- label : 'View' ,
96- submenu : [
97- {
98- label : 'Reload' ,
99- accelerator : 'Command+R' ,
100- click : function ( ) {
101- _window . restart ( ) ;
102- }
103- } ,
104- {
105- label : 'Toggle DevTools' ,
106- accelerator : 'Alt+Command+I' ,
107- click : function ( ) {
108- _window . toggleDevTools ( ) ;
109- }
65+ }
66+ ]
67+ } ,
68+ {
69+ label : 'Edit' ,
70+ submenu : [
71+ {
72+ label : 'Undo' ,
73+ accelerator : 'Command+Z' ,
74+ role : 'undo'
75+ } ,
76+ {
77+ label : 'Redo' ,
78+ accelerator : 'Shift+Command+Z' ,
79+ role : 'redo'
80+ } ,
81+ {
82+ type : 'separator'
83+ } ,
84+ {
85+ label : 'Cut' ,
86+ accelerator : 'Command+X' ,
87+ role : 'cut'
88+ } ,
89+ {
90+ label : 'Copy' ,
91+ accelerator : 'Command+C' ,
92+ role : 'copy'
93+ } ,
94+ {
95+ label : 'Paste' ,
96+ accelerator : 'Command+V' ,
97+ role : 'paste'
98+ } ,
99+ {
100+ label : 'Select All' ,
101+ accelerator : 'Command+A' ,
102+ role : 'selectall'
103+ }
104+ ]
105+ } ,
106+ {
107+ label : 'View' ,
108+ submenu : [
109+ {
110+ label : 'Reload' ,
111+ accelerator : 'Command+R' ,
112+ click : function ( ) {
113+ window . restart ( ) ;
110114 }
111- ]
112- } ,
113- {
114- label : 'Share' ,
115- submenu : [
116- {
117- label : 'Share Schema as JSON' ,
118- accelerator : 'Alt+Command+S' ,
119- click : function ( ) {
120- _window . webContents . send ( 'message' , 'menu-share-schema-json' ) ;
121- }
115+ } ,
116+ {
117+ label : 'Toggle DevTools' ,
118+ accelerator : 'Alt+Command+I' ,
119+ click : function ( ) {
120+ window . toggleDevTools ( ) ;
122121 }
123- ]
124- } ,
125- {
126- label : 'Window' ,
127- submenu : [
128- {
129- label : 'Minimize' ,
130- accelerator : 'Command+M' ,
131- role : 'minimize'
132- } ,
133- {
134- label : 'Close' ,
135- accelerator : 'Command+W' ,
136- role : 'close'
137- } ,
138- {
139- type : 'separator'
140- } ,
141- {
142- label : 'Bring All to Front' ,
143- selector : 'arrangeInFront:'
122+ }
123+ ]
124+ } ,
125+
126+ {
127+ label : 'Share' ,
128+ submenu : [
129+ {
130+ label : 'Share Schema as JSON' ,
131+ accelerator : 'Alt+Command+S' ,
132+ click : function ( ) {
133+ window . webContents . send ( 'message' , 'menu-share-schema-json' ) ;
144134 }
145- ]
146- }
147- ] ;
148- }
135+ }
136+ ]
137+ } ,
138+ {
139+ label : 'Window' ,
140+ submenu : [
141+ {
142+ label : 'Minimize' ,
143+ accelerator : 'Command+M' ,
144+ role : 'minimize'
145+ } ,
146+ {
147+ label : 'Close' ,
148+ accelerator : 'Command+W' ,
149+ role : 'close'
150+ } ,
151+ {
152+ type : 'separator'
153+ } ,
154+ {
155+ label : 'Bring All to Front' ,
156+ selector : 'arrangeInFront:'
157+ }
158+ ]
159+ }
160+ ] ;
161+ } ;
149162
163+ function nonDarwinMenu ( window ) {
150164 return [
151165 {
152166 label : 'File' ,
@@ -177,28 +191,19 @@ function getTemplate(_window) {
177191 label : 'Reload' ,
178192 accelerator : 'Ctrl+R' ,
179193 click : function ( ) {
180- _window . restart ( ) ;
194+ window . restart ( ) ;
181195 }
182196 } ,
183197 {
184198 label : 'Toggle DevTools' ,
185199 accelerator : 'Alt+Ctrl+I' ,
186200 click : function ( ) {
187- _window . toggleDevTools ( ) ;
201+ window . toggleDevTools ( ) ;
188202 }
189203 }
190204 ]
191205 }
192206 ] ;
193- }
194-
195- /**
196- * @param {BrowserWindow } _window - The window to attach to.
197- * @see https://github.com/atom/electron/blob/master/docs/api/menu.md
198- */
199- module . exports = function ( _window ) {
200- debug ( 'attaching window menu' ) ;
201- var template = getTemplate ( _window ) ;
202- var menu = Menu . buildFromTemplate ( template ) ;
203- Menu . setApplicationMenu ( menu ) ;
204207} ;
208+
209+ module . exports = menu ;
0 commit comments