@@ -108,9 +108,6 @@ let settings = document.querySelectorAll(".setting");
108
108
let complexSettings = document . querySelectorAll ( ".complex-setting" ) ;
109
109
let listSettings = document . querySelectorAll ( ".list-setting" ) ;
110
110
111
- let overridesDisabled = false ;
112
- let suffixDisabled = false ;
113
-
114
111
function isSameValue ( a , b ) {
115
112
if ( typeof a != typeof b )
116
113
return false ;
@@ -353,6 +350,61 @@ function getPlatformSuffix(forSetting) {
353
350
return suffix ;
354
351
}
355
352
353
+ /**
354
+ * @param {HTMLElement } setting
355
+ * @param {Function } cb
356
+ */
357
+ function iterateSettingInputs ( setting , cb ) {
358
+ if ( setting . tagName == "VSCODE-TEXT-AREA"
359
+ || setting . tagName == "VSCODE-TEXT-FIELD"
360
+ || setting . tagName == "VSCODE-DROPDOWN"
361
+ || setting . tagName == "INPUT"
362
+ || setting . tagName == "TEXTAREA" )
363
+ cb ( setting ) ;
364
+ else
365
+ {
366
+ var inputs = setting . querySelectorAll ( "input, textarea" ) ;
367
+ inputs . forEach ( i => {
368
+ cb ( i ) ;
369
+ } ) ;
370
+ }
371
+ }
372
+
373
+ /**
374
+ * @param {HTMLElement } setting
375
+ */
376
+ function enableSetting ( setting ) {
377
+ if ( ! setting . classList . contains ( "disabled" ) )
378
+ return ;
379
+ let oldTitle = setting . getAttribute ( "data-old-title" ) ;
380
+ setting . title = oldTitle || "" ;
381
+ setting . classList . remove ( "disabled" ) ;
382
+ iterateSettingInputs ( setting , s => s . disabled = false ) ;
383
+
384
+ let resetBtn = getResetButton ( setting ) ;
385
+ if ( resetBtn )
386
+ resetBtn . disabled = false ;
387
+ }
388
+
389
+ /**
390
+ * @param {HTMLElement } setting
391
+ * @param {string } reason disabling reason
392
+ */
393
+ function disableSetting ( setting , reason ) {
394
+ if ( setting . classList . contains ( "disabled" ) )
395
+ return ;
396
+ let oldTitle = setting . getAttribute ( "data-old-title" ) ;
397
+ if ( ! oldTitle )
398
+ setting . setAttribute ( "data-old-title" , setting . title ) ;
399
+ setting . title = reason ;
400
+ setting . classList . add ( "disabled" ) ;
401
+ iterateSettingInputs ( setting , s => s . disabled = true ) ;
402
+
403
+ let resetBtn = getResetButton ( setting ) ;
404
+ if ( resetBtn )
405
+ resetBtn . disabled = true ;
406
+ }
407
+
356
408
function updateOverrides ( ) {
357
409
/**
358
410
* @type {[string, string][] }
@@ -413,16 +465,6 @@ function updateOverrides() {
413
465
overridesSelector . value = selected ;
414
466
}
415
467
416
- function fixSelectors ( ) {
417
- if ( overridesSelector . value != OPTION_EMPTY_VALUE && overridesDisabled ) {
418
- overridesSelector . value = OPTION_EMPTY_VALUE ;
419
- overridesSelector . setAttribute ( "disabled" , "disabled" ) ;
420
- console . log ( "Disabled configurationSelector" ) ;
421
- }
422
- else if ( ! overridesDisabled )
423
- overridesSelector . removeAttribute ( "disabled" ) ;
424
- }
425
-
426
468
/**
427
469
* @param {HTMLElement } setting
428
470
* @returns {HTMLElement | undefined }
@@ -539,6 +581,18 @@ function makeSetInLabel(setting, usedAccess) {
539
581
}
540
582
}
541
583
584
+ /**
585
+ * @param {HTMLElement } setting
586
+ * @returns {HTMLButtonElement | null }
587
+ */
588
+ function getResetButton ( setting ) {
589
+ let next = /** @type {HTMLElement } */ ( setting . nextElementSibling ) ;
590
+ if ( next && next . classList . contains ( "reset-btn" ) ) {
591
+ return next ;
592
+ }
593
+ return null ;
594
+ }
595
+
542
596
let didStartup = false ;
543
597
function ready ( ) {
544
598
if ( didStartup ) return ;
@@ -579,25 +633,18 @@ function ready() {
579
633
setState ( "dub.activeTab" , activeTab ) ;
580
634
var hasSuffixMembers = ! ! element . getAttribute ( "has-suffix" ) ;
581
635
var hasOverride = element . getAttribute ( "has-override" ) != "false" ;
582
- if ( hasSuffixMembers ) {
583
- platformSelector . removeAttribute ( "disabled" ) ;
584
- architectureSelector . removeAttribute ( "disabled" ) ;
585
- compilerSelector . removeAttribute ( "disabled" ) ;
586
- }
587
- else {
588
- platformSelector . setAttribute ( "disabled" , "disabled" ) ;
589
- architectureSelector . setAttribute ( "disabled" , "disabled" ) ;
590
- compilerSelector . setAttribute ( "disabled" , "disabled" ) ;
591
- }
592
636
593
- if ( hasOverride )
594
- overridesSelector . removeAttribute ( "disabled" ) ;
595
- else
596
- overridesSelector . setAttribute ( "disabled" , "disabled" )
637
+ platformSelector . disabled = ! hasSuffixMembers ;
638
+ architectureSelector . disabled = ! hasSuffixMembers ;
639
+ compilerSelector . disabled = ! hasSuffixMembers ;
640
+
641
+ let suffixDisabled = ! hasSuffixMembers ;
642
+ let overridesDisabled = ! hasOverride ;
597
643
598
- suffixDisabled = ! hasSuffixMembers ;
599
- overridesDisabled = ! hasOverride ;
600
- fixSelectors ( ) ;
644
+ if ( overridesDisabled )
645
+ overridesSelector . classList . add ( "effectless" ) ;
646
+ else
647
+ overridesSelector . classList . remove ( "effectless" ) ;
601
648
}
602
649
603
650
var tabsMenu = document . getElementById ( "tabs" ) . querySelectorAll ( "li" ) ;
@@ -657,6 +704,15 @@ function refreshSettings() {
657
704
}
658
705
659
706
function loadJsonIntoUI ( ) {
707
+ const currentDubConfig = getDUBConfig ( ) ;
708
+ const currentDubBuildType = getDUBBuildType ( ) ;
709
+ const currentPlatformSuffix = getPlatformSuffix ( ) ;
710
+
711
+ console . log ( "loading settings for" ) ;
712
+ console . log ( "- config: " , currentDubConfig ) ;
713
+ console . log ( "- build: " , currentDubBuildType ) ;
714
+ console . log ( "- platform: " , currentPlatformSuffix ) ;
715
+
660
716
for ( let i = 0 ; i < settings . length ; i ++ ) {
661
717
let setting = /** @type {HTMLInputElement } */ ( settings [ i ] ) ;
662
718
// json-path="description"
@@ -783,6 +839,28 @@ function loadJsonIntoUI() {
783
839
} ) ;
784
840
setPath ( configPath , value ) ;
785
841
} ) . bind ( this , setting , configPath , path , encode ) ;
842
+
843
+ var changable = true ;
844
+ var disabledReason = "" ;
845
+ if ( currentDubConfig && setting ?. getAttribute ( "has-config" ) == "false" )
846
+ {
847
+ changable = false ;
848
+ disabledReason += "This setting can't be changed inside a custom configuration. " ;
849
+ }
850
+ if ( ( currentDubBuildType || currentPlatformSuffix ) && setting ?. getAttribute ( "has-suffix" ) != "true" )
851
+ {
852
+ changable = false ;
853
+ disabledReason += "This setting can't be changed with build configuration or target platform suffix. " ;
854
+ }
855
+
856
+ if ( changable )
857
+ enableSetting ( setting ) ;
858
+ else
859
+ disableSetting ( setting , disabledReason . trim ( ) ) ;
860
+
861
+ if ( ! changable )
862
+ continue ;
863
+
786
864
if ( setting . tagName == "VSCODE-TEXT-FIELD" || setting . tagName == "VSCODE-TEXT-AREA" )
787
865
setting . oninput = changeFun ;
788
866
else
0 commit comments