@@ -25,33 +25,66 @@ import {
25
25
} from './notice-document-helpers' ;
26
26
import { UserSettings } from './user-settings' ;
27
27
28
- // type Item = {label: string, id: string}
28
+ const INITIALLY_DISABLED_MENU_ITEMS = [
29
+ 'save' ,
30
+ 'projectMetadata' ,
31
+ 'projectStatistics' ,
32
+ 'followUp' ,
33
+ 'compactComponentList' ,
34
+ 'detailedComponentList' ,
35
+ 'spdxYAML' ,
36
+ 'spdxJSON' ,
37
+ 'selectAll' ,
38
+ 'searchAttributions' ,
39
+ 'searchSignals' ,
40
+ 'searchResourcesAll' ,
41
+ 'searchResourceLinked' ,
42
+ ] as const ;
29
43
30
- const MENU_ITEMS = {
31
- file : { label : 'File' , id : 'file' } ,
32
- open : { label : 'Open File' , id : 'open' } ,
33
- save : { label : 'Save' , id : 'save' } ,
34
- export : { label : 'Export' , id : 'export' } ,
35
- followUp : { label : 'Follow-Up' , id : 'follow-up' } ,
36
- compactComponentList : { label : 'Compact component list' , id : 'compact-list' } ,
37
- detailedComponentList : { label : 'Detailed component list' , id : 'detailed-list' } ,
38
- spdxYAML : { label : 'SPDX (yaml)' , id : 'spdx-yaml' } ,
39
- spdxJSON : { label : 'SPDX (json)' , id : 'spdx-json' } ,
40
- projectMetadata : { label : 'Project Metadata' , id : 'project-metadata' } ,
41
- projectStatistics : { label : 'Project Statistics' , id : 'project-statistics' } ,
42
- pathToSources : { label : 'Set Path to Sources' , id : 'path-to-sources' } ,
43
- quit : { label : 'Quit' , id : 'quit' } ,
44
- }
44
+ type Item = { label : string ; id : string } ;
45
45
46
- const INITIALLY_DISABLED_MENU_ITEM_IDS : Array < string > = [ MENU_ITEMS . save . id , MENU_ITEMS . export . id , MENU_ITEMS . projectMetadata . id , MENU_ITEMS . projectStatistics . id ]
46
+ const MENU_ITEMS : Record < ( typeof INITIALLY_DISABLED_MENU_ITEMS ) [ number ] , Item > =
47
+ {
48
+ save : { label : 'Save' , id : 'save' } ,
49
+ followUp : { label : 'Follow-Up' , id : 'follow-up' } ,
50
+ compactComponentList : {
51
+ label : 'Compact component list' ,
52
+ id : 'compact-list' ,
53
+ } ,
54
+ detailedComponentList : {
55
+ label : 'Detailed component list' ,
56
+ id : 'detailed-list' ,
57
+ } ,
58
+ spdxYAML : { label : 'SPDX (yaml)' , id : 'spdx-yaml' } ,
59
+ spdxJSON : { label : 'SPDX (json)' , id : 'spdx-json' } ,
60
+ projectMetadata : { label : 'Project Metadata' , id : 'project-metadata' } ,
61
+ projectStatistics : {
62
+ label : 'Project Statistics' ,
63
+ id : 'project-statistics' ,
64
+ } ,
65
+ selectAll : { label : 'Select All' , id : 'select-all' } ,
66
+ searchAttributions : {
67
+ label : 'Search Attributions' ,
68
+ id : 'search-attributions' ,
69
+ } ,
70
+ searchSignals : { label : 'Search Signals' , id : 'search-signals' } ,
71
+ searchResourcesAll : {
72
+ label : 'Search All Resources' ,
73
+ id : 'search-resources-all' ,
74
+ } ,
75
+ searchResourceLinked : {
76
+ label : 'Search Linked Resources' ,
77
+ id : 'search-resources-linked' ,
78
+ } ,
79
+ } ;
47
80
48
81
export async function createMenu ( mainWindow : BrowserWindow ) : Promise < Menu > {
49
82
const webContents = mainWindow . webContents ;
50
83
const qaMode = await UserSettings . get ( 'qaMode' ) ;
51
84
52
85
return Menu . buildFromTemplate ( [
53
86
{
54
- label : MENU_ITEMS . file . label ,
87
+ label : 'File' ,
55
88
submenu : [
56
89
{
57
90
icon : getIconBasedOnTheme (
@@ -80,13 +113,11 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
80
113
enabled : false ,
81
114
} ,
82
115
{
83
- label : MENU_ITEMS . export . label ,
116
+ label : 'Export' ,
84
117
icon : getIconBasedOnTheme (
85
118
'icons/export-white.png' ,
86
119
'icons/export-black.png' ,
87
120
) ,
88
- id : MENU_ITEMS . export . id ,
89
- enabled : false ,
90
121
submenu : [
91
122
{
92
123
label : MENU_ITEMS . followUp . label ,
@@ -102,6 +133,8 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
102
133
ExportType . FollowUp ,
103
134
) ;
104
135
} ,
136
+ id : MENU_ITEMS . followUp . id ,
137
+ enabled : false ,
105
138
} ,
106
139
{
107
140
icon : getIconBasedOnTheme (
@@ -117,7 +150,8 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
117
150
ExportType . CompactBom ,
118
151
) ;
119
152
} ,
120
-
153
+ id : MENU_ITEMS . compactComponentList . id ,
154
+ enabled : false ,
121
155
} ,
122
156
{
123
157
icon : getIconBasedOnTheme (
@@ -135,6 +169,8 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
135
169
ExportType . DetailedBom ,
136
170
) ;
137
171
} ,
172
+ id : MENU_ITEMS . detailedComponentList . id ,
173
+ enabled : false ,
138
174
} ,
139
175
{
140
176
icon : getIconBasedOnTheme (
@@ -150,6 +186,8 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
150
186
ExportType . SpdxDocumentYaml ,
151
187
) ;
152
188
} ,
189
+ id : MENU_ITEMS . spdxYAML . id ,
190
+ enabled : false ,
153
191
} ,
154
192
{
155
193
icon : getIconBasedOnTheme (
@@ -165,6 +203,8 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
165
203
ExportType . SpdxDocumentJson ,
166
204
) ;
167
205
} ,
206
+ id : MENU_ITEMS . spdxJSON . id ,
207
+ enabled : false ,
168
208
} ,
169
209
] ,
170
210
} ,
@@ -211,7 +251,7 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
211
251
'icons/restore-white.png' ,
212
252
'icons/restore-black.png' ,
213
253
) ,
214
- label : MENU_ITEMS . pathToSources . label ,
254
+ label : 'Set Path to Sources' ,
215
255
click : ( ) => {
216
256
getSelectBaseURLListener ( mainWindow ) ( ) ;
217
257
} ,
@@ -221,7 +261,7 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
221
261
'icons/quit-white.png' ,
222
262
'icons/quit-black.png' ,
223
263
) ,
224
- label : MENU_ITEMS . quit . label ,
264
+ label : 'Quit' ,
225
265
accelerator : 'CmdOrCtrl+Q' ,
226
266
click : ( ) => {
227
267
app . quit ( ) ;
@@ -283,62 +323,72 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
283
323
'icons/select-all-white.png' ,
284
324
'icons/select-all-black.png' ,
285
325
) ,
286
- label : 'Select All' ,
326
+ label : MENU_ITEMS . selectAll . label ,
287
327
accelerator : 'CmdOrCtrl+A' ,
288
328
role : 'selectAll' ,
329
+ id : MENU_ITEMS . selectAll . id ,
330
+ enabled : false ,
289
331
} ,
290
332
{ type : 'separator' } ,
291
333
{
292
334
icon : getIconBasedOnTheme (
293
335
'icons/magnifying-glass-white.png' ,
294
336
'icons/magnifying-glass-black.png' ,
295
337
) ,
296
- label : 'Search Attributions' ,
338
+ label : MENU_ITEMS . searchAttributions . label ,
297
339
accelerator : 'CmdOrCtrl+Shift+A' ,
298
340
click : ( ) => {
299
341
if ( isFileLoaded ( getGlobalBackendState ( ) ) ) {
300
342
webContents . send ( AllowedFrontendChannels . SearchAttributions ) ;
301
343
}
302
344
} ,
345
+ id : MENU_ITEMS . searchAttributions . id ,
346
+ enabled : false ,
303
347
} ,
304
348
{
305
349
icon : getIconBasedOnTheme (
306
350
'icons/magnifying-glass-white.png' ,
307
351
'icons/magnifying-glass-black.png' ,
308
352
) ,
309
- label : 'Search Signals' ,
353
+ label : MENU_ITEMS . searchSignals . label ,
310
354
accelerator : 'CmdOrCtrl+Shift+S' ,
311
355
click : ( ) => {
312
356
if ( isFileLoaded ( getGlobalBackendState ( ) ) ) {
313
357
webContents . send ( AllowedFrontendChannels . SearchSignals ) ;
314
358
}
315
359
} ,
360
+ id : MENU_ITEMS . searchSignals . id ,
361
+ enabled : false ,
316
362
} ,
317
363
{
318
364
icon : getIconBasedOnTheme (
319
365
'icons/search-white.png' ,
320
366
'icons/search-black.png' ,
321
367
) ,
322
- label : 'Search All Resources' ,
368
+ label : MENU_ITEMS . searchResourcesAll . label ,
323
369
accelerator : 'CmdOrCtrl+Shift+R' ,
324
370
click : ( ) => {
325
371
if ( isFileLoaded ( getGlobalBackendState ( ) ) ) {
326
372
webContents . send ( AllowedFrontendChannels . SearchResources ) ;
327
373
}
328
374
} ,
375
+ id : MENU_ITEMS . searchResourcesAll . id ,
376
+ enabled : false ,
329
377
} ,
330
378
{
331
379
icon : getIconBasedOnTheme (
332
380
'icons/search-white.png' ,
333
381
'icons/search-black.png' ,
334
382
) ,
335
- label : 'Search Linked Resources' ,
383
+ label : MENU_ITEMS . searchResourceLinked . label ,
336
384
accelerator : 'CmdOrCtrl+Shift+L' ,
337
385
click : ( ) => {
338
386
if ( isFileLoaded ( getGlobalBackendState ( ) ) ) {
339
387
webContents . send ( AllowedFrontendChannels . SearchLinkedResources ) ;
340
388
}
341
389
} ,
390
+ id : MENU_ITEMS . searchResourceLinked . id ,
391
+ enabled : false ,
342
392
} ,
343
393
] ,
344
394
} ,
@@ -482,17 +532,10 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
482
532
483
533
export function activateMenuOptions ( ) : void {
484
534
const menu = Menu . getApplicationMenu ( ) ;
485
- // INITIALLY_DISABLED_MENU_ITEM_IDS.forEach((id) => {
486
- // console.log("key: ", id)
487
- // const item = menu?.getMenuItemById(id)
488
- // if (item) {
489
- // console.log("enable: ", item.label)
490
- // item.enabled = true;
491
- // }
492
- // })
493
- const save = menu ?. getMenuItemById ( MENU_ITEMS [ 'save' ] . id )
494
- if ( save ) {
495
- console . log ( "heeereeeee" ) ;
496
- save . enabled = true ;
497
- }
535
+ INITIALLY_DISABLED_MENU_ITEMS . forEach ( ( key ) => {
536
+ const menuItem = menu ?. getMenuItemById ( MENU_ITEMS [ key ] . id ) ;
537
+ if ( menuItem ) {
538
+ menuItem . enabled = true ;
539
+ }
540
+ } ) ;
498
541
}
0 commit comments