@@ -25,33 +25,68 @@ 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 INITIALLY_DISABLED_ITEM_INFO : Record <
47
+ ( typeof INITIALLY_DISABLED_MENU_ITEMS ) [ number ] ,
48
+ Item
49
+ > = {
50
+ save : { label : 'Save' , id : 'save' } ,
51
+ followUp : { label : 'Follow-Up' , id : 'follow-up' } ,
52
+ compactComponentList : {
53
+ label : 'Compact component list' ,
54
+ id : 'compact-list' ,
55
+ } ,
56
+ detailedComponentList : {
57
+ label : 'Detailed component list' ,
58
+ id : 'detailed-list' ,
59
+ } ,
60
+ spdxYAML : { label : 'SPDX (yaml)' , id : 'spdx-yaml' } ,
61
+ spdxJSON : { label : 'SPDX (json)' , id : 'spdx-json' } ,
62
+ projectMetadata : { label : 'Project Metadata' , id : 'project-metadata' } ,
63
+ projectStatistics : {
64
+ label : 'Project Statistics' ,
65
+ id : 'project-statistics' ,
66
+ } ,
67
+ selectAll : { label : 'Select All' , id : 'select-all' } ,
68
+ searchAttributions : {
69
+ label : 'Search Attributions' ,
70
+ id : 'search-attributions' ,
71
+ } ,
72
+ searchSignals : { label : 'Search Signals' , id : 'search-signals' } ,
73
+ searchResourcesAll : {
74
+ label : 'Search All Resources' ,
75
+ id : 'search-resources-all' ,
76
+ } ,
77
+ searchResourceLinked : {
78
+ label : 'Search Linked Resources' ,
79
+ id : 'search-resources-linked' ,
80
+ } ,
81
+ } ;
47
82
48
83
export async function createMenu ( mainWindow : BrowserWindow ) : Promise < Menu > {
49
84
const webContents = mainWindow . webContents ;
50
85
const qaMode = await UserSettings . get ( 'qaMode' ) ;
51
86
52
87
return Menu . buildFromTemplate ( [
53
88
{
54
- label : MENU_ITEMS . file . label ,
89
+ label : 'File' ,
55
90
submenu : [
56
91
{
57
92
icon : getIconBasedOnTheme (
@@ -69,27 +104,25 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
69
104
'icons/save-white.png' ,
70
105
'icons/save-black.png' ,
71
106
) ,
72
- label : MENU_ITEMS . save . label ,
107
+ label : INITIALLY_DISABLED_ITEM_INFO . save . label ,
73
108
accelerator : 'CmdOrCtrl+S' ,
74
109
click : ( ) => {
75
110
webContents . send ( AllowedFrontendChannels . SaveFileRequest , {
76
111
saveFile : true ,
77
112
} ) ;
78
113
} ,
79
- id : MENU_ITEMS . save . id ,
114
+ id : INITIALLY_DISABLED_ITEM_INFO . save . id ,
80
115
enabled : false ,
81
116
} ,
82
117
{
83
- label : MENU_ITEMS . export . label ,
118
+ label : 'Export' ,
84
119
icon : getIconBasedOnTheme (
85
120
'icons/export-white.png' ,
86
121
'icons/export-black.png' ,
87
122
) ,
88
- id : MENU_ITEMS . export . id ,
89
- enabled : false ,
90
123
submenu : [
91
124
{
92
- label : MENU_ITEMS . followUp . label ,
125
+ label : INITIALLY_DISABLED_ITEM_INFO . followUp . label ,
93
126
icon : getIconBasedOnTheme (
94
127
'icons/follow-up-white.png' ,
95
128
'icons/follow-up-black.png' ,
@@ -102,13 +135,15 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
102
135
ExportType . FollowUp ,
103
136
) ;
104
137
} ,
138
+ id : INITIALLY_DISABLED_ITEM_INFO . followUp . id ,
139
+ enabled : false ,
105
140
} ,
106
141
{
107
142
icon : getIconBasedOnTheme (
108
143
'icons/com-list-white.png' ,
109
144
'icons/com-list-black.png' ,
110
145
) ,
111
- label : MENU_ITEMS . compactComponentList . label ,
146
+ label : INITIALLY_DISABLED_ITEM_INFO . compactComponentList . label ,
112
147
click : ( ) => {
113
148
setLoadingState ( mainWindow . webContents , true ) ;
114
149
logger . info ( 'Preparing data for compact component list export' ) ;
@@ -117,14 +152,15 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
117
152
ExportType . CompactBom ,
118
153
) ;
119
154
} ,
120
-
155
+ id : INITIALLY_DISABLED_ITEM_INFO . compactComponentList . id ,
156
+ enabled : false ,
121
157
} ,
122
158
{
123
159
icon : getIconBasedOnTheme (
124
160
'icons/det-list-white.png' ,
125
161
'icons/det-list-black.png' ,
126
162
) ,
127
- label : MENU_ITEMS . detailedComponentList . label ,
163
+ label : INITIALLY_DISABLED_ITEM_INFO . detailedComponentList . label ,
128
164
click : ( ) => {
129
165
setLoadingState ( mainWindow . webContents , true ) ;
130
166
logger . info (
@@ -135,13 +171,15 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
135
171
ExportType . DetailedBom ,
136
172
) ;
137
173
} ,
174
+ id : INITIALLY_DISABLED_ITEM_INFO . detailedComponentList . id ,
175
+ enabled : false ,
138
176
} ,
139
177
{
140
178
icon : getIconBasedOnTheme (
141
179
'icons/yaml-white.png' ,
142
180
'icons/yaml-black.png' ,
143
181
) ,
144
- label : MENU_ITEMS . spdxYAML . label ,
182
+ label : INITIALLY_DISABLED_ITEM_INFO . spdxYAML . label ,
145
183
click : ( ) => {
146
184
setLoadingState ( mainWindow . webContents , true ) ;
147
185
logger . info ( 'Preparing data for SPDX (yaml) export' ) ;
@@ -150,13 +188,15 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
150
188
ExportType . SpdxDocumentYaml ,
151
189
) ;
152
190
} ,
191
+ id : INITIALLY_DISABLED_ITEM_INFO . spdxYAML . id ,
192
+ enabled : false ,
153
193
} ,
154
194
{
155
195
icon : getIconBasedOnTheme (
156
196
'icons/json-white.png' ,
157
197
'icons/json-black.png' ,
158
198
) ,
159
- label : MENU_ITEMS . spdxJSON . label ,
199
+ label : INITIALLY_DISABLED_ITEM_INFO . spdxJSON . label ,
160
200
click : ( ) => {
161
201
setLoadingState ( mainWindow . webContents , true ) ;
162
202
logger . info ( 'Preparing data for SPDX (json) export' ) ;
@@ -165,6 +205,8 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
165
205
ExportType . SpdxDocumentJson ,
166
206
) ;
167
207
} ,
208
+ id : INITIALLY_DISABLED_ITEM_INFO . spdxJSON . id ,
209
+ enabled : false ,
168
210
} ,
169
211
] ,
170
212
} ,
@@ -173,7 +215,7 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
173
215
'icons/about-white.png' ,
174
216
'icons/about-black.png' ,
175
217
) ,
176
- label : MENU_ITEMS . projectMetadata . label ,
218
+ label : INITIALLY_DISABLED_ITEM_INFO . projectMetadata . label ,
177
219
click : ( ) => {
178
220
if ( isFileLoaded ( getGlobalBackendState ( ) ) ) {
179
221
webContents . send (
@@ -184,15 +226,15 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
184
226
) ;
185
227
}
186
228
} ,
187
- id : MENU_ITEMS . projectMetadata . id ,
229
+ id : INITIALLY_DISABLED_ITEM_INFO . projectMetadata . id ,
188
230
enabled : false ,
189
231
} ,
190
232
{
191
233
icon : getIconBasedOnTheme (
192
234
'icons/statictics-white.png' ,
193
235
'icons/statictics-black.png' ,
194
236
) ,
195
- label : MENU_ITEMS . projectStatistics . label ,
237
+ label : INITIALLY_DISABLED_ITEM_INFO . projectStatistics . label ,
196
238
click : ( ) => {
197
239
if ( isFileLoaded ( getGlobalBackendState ( ) ) ) {
198
240
webContents . send (
@@ -203,15 +245,15 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
203
245
) ;
204
246
}
205
247
} ,
206
- id : MENU_ITEMS . projectStatistics . id ,
248
+ id : INITIALLY_DISABLED_ITEM_INFO . projectStatistics . id ,
207
249
enabled : false ,
208
250
} ,
209
251
{
210
252
icon : getIconBasedOnTheme (
211
253
'icons/restore-white.png' ,
212
254
'icons/restore-black.png' ,
213
255
) ,
214
- label : MENU_ITEMS . pathToSources . label ,
256
+ label : 'Set Path to Sources' ,
215
257
click : ( ) => {
216
258
getSelectBaseURLListener ( mainWindow ) ( ) ;
217
259
} ,
@@ -221,7 +263,7 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
221
263
'icons/quit-white.png' ,
222
264
'icons/quit-black.png' ,
223
265
) ,
224
- label : MENU_ITEMS . quit . label ,
266
+ label : 'Quit' ,
225
267
accelerator : 'CmdOrCtrl+Q' ,
226
268
click : ( ) => {
227
269
app . quit ( ) ;
@@ -283,62 +325,72 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
283
325
'icons/select-all-white.png' ,
284
326
'icons/select-all-black.png' ,
285
327
) ,
286
- label : 'Select All' ,
328
+ label : INITIALLY_DISABLED_ITEM_INFO . selectAll . label ,
287
329
accelerator : 'CmdOrCtrl+A' ,
288
330
role : 'selectAll' ,
331
+ id : INITIALLY_DISABLED_ITEM_INFO . selectAll . id ,
332
+ enabled : false ,
289
333
} ,
290
334
{ type : 'separator' } ,
291
335
{
292
336
icon : getIconBasedOnTheme (
293
337
'icons/magnifying-glass-white.png' ,
294
338
'icons/magnifying-glass-black.png' ,
295
339
) ,
296
- label : 'Search Attributions' ,
340
+ label : INITIALLY_DISABLED_ITEM_INFO . searchAttributions . label ,
297
341
accelerator : 'CmdOrCtrl+Shift+A' ,
298
342
click : ( ) => {
299
343
if ( isFileLoaded ( getGlobalBackendState ( ) ) ) {
300
344
webContents . send ( AllowedFrontendChannels . SearchAttributions ) ;
301
345
}
302
346
} ,
347
+ id : INITIALLY_DISABLED_ITEM_INFO . searchAttributions . id ,
348
+ enabled : false ,
303
349
} ,
304
350
{
305
351
icon : getIconBasedOnTheme (
306
352
'icons/magnifying-glass-white.png' ,
307
353
'icons/magnifying-glass-black.png' ,
308
354
) ,
309
- label : 'Search Signals' ,
355
+ label : INITIALLY_DISABLED_ITEM_INFO . searchSignals . label ,
310
356
accelerator : 'CmdOrCtrl+Shift+S' ,
311
357
click : ( ) => {
312
358
if ( isFileLoaded ( getGlobalBackendState ( ) ) ) {
313
359
webContents . send ( AllowedFrontendChannels . SearchSignals ) ;
314
360
}
315
361
} ,
362
+ id : INITIALLY_DISABLED_ITEM_INFO . searchSignals . id ,
363
+ enabled : false ,
316
364
} ,
317
365
{
318
366
icon : getIconBasedOnTheme (
319
367
'icons/search-white.png' ,
320
368
'icons/search-black.png' ,
321
369
) ,
322
- label : 'Search All Resources' ,
370
+ label : INITIALLY_DISABLED_ITEM_INFO . searchResourcesAll . label ,
323
371
accelerator : 'CmdOrCtrl+Shift+R' ,
324
372
click : ( ) => {
325
373
if ( isFileLoaded ( getGlobalBackendState ( ) ) ) {
326
374
webContents . send ( AllowedFrontendChannels . SearchResources ) ;
327
375
}
328
376
} ,
377
+ id : INITIALLY_DISABLED_ITEM_INFO . searchResourcesAll . id ,
378
+ enabled : false ,
329
379
} ,
330
380
{
331
381
icon : getIconBasedOnTheme (
332
382
'icons/search-white.png' ,
333
383
'icons/search-black.png' ,
334
384
) ,
335
- label : 'Search Linked Resources' ,
385
+ label : INITIALLY_DISABLED_ITEM_INFO . searchResourceLinked . label ,
336
386
accelerator : 'CmdOrCtrl+Shift+L' ,
337
387
click : ( ) => {
338
388
if ( isFileLoaded ( getGlobalBackendState ( ) ) ) {
339
389
webContents . send ( AllowedFrontendChannels . SearchLinkedResources ) ;
340
390
}
341
391
} ,
392
+ id : INITIALLY_DISABLED_ITEM_INFO . searchResourceLinked . id ,
393
+ enabled : false ,
342
394
} ,
343
395
] ,
344
396
} ,
@@ -480,19 +532,14 @@ export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
480
532
] ) ;
481
533
}
482
534
483
- export function activateMenuOptions ( ) : void {
535
+ export function activateMenuItems ( ) : void {
484
536
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
- }
537
+ INITIALLY_DISABLED_MENU_ITEMS . forEach ( ( key ) => {
538
+ const menuItem = menu ?. getMenuItemById (
539
+ INITIALLY_DISABLED_ITEM_INFO [ key ] . id ,
540
+ ) ;
541
+ if ( menuItem ) {
542
+ menuItem . enabled = true ;
543
+ }
544
+ } ) ;
498
545
}
0 commit comments