@@ -108,9 +108,6 @@ let settings = document.querySelectorAll(".setting");
108108let complexSettings = document . querySelectorAll ( ".complex-setting" ) ;
109109let listSettings = document . querySelectorAll ( ".list-setting" ) ;
110110
111- let overridesDisabled = false ;
112- let suffixDisabled = false ;
113-
114111function isSameValue ( a , b ) {
115112 if ( typeof a != typeof b )
116113 return false ;
@@ -353,6 +350,61 @@ function getPlatformSuffix(forSetting) {
353350 return suffix ;
354351}
355352
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+
356408function updateOverrides ( ) {
357409 /**
358410 * @type {[string, string][] }
@@ -413,16 +465,6 @@ function updateOverrides() {
413465 overridesSelector . value = selected ;
414466}
415467
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-
426468/**
427469 * @param {HTMLElement } setting
428470 * @returns {HTMLElement | undefined }
@@ -539,6 +581,18 @@ function makeSetInLabel(setting, usedAccess) {
539581 }
540582}
541583
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+
542596let didStartup = false ;
543597function ready ( ) {
544598 if ( didStartup ) return ;
@@ -579,25 +633,18 @@ function ready() {
579633 setState ( "dub.activeTab" , activeTab ) ;
580634 var hasSuffixMembers = ! ! element . getAttribute ( "has-suffix" ) ;
581635 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- }
592636
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 ;
597643
598- suffixDisabled = ! hasSuffixMembers ;
599- overridesDisabled = ! hasOverride ;
600- fixSelectors ( ) ;
644+ if ( overridesDisabled )
645+ overridesSelector . classList . add ( "effectless" ) ;
646+ else
647+ overridesSelector . classList . remove ( "effectless" ) ;
601648 }
602649
603650 var tabsMenu = document . getElementById ( "tabs" ) . querySelectorAll ( "li" ) ;
@@ -657,6 +704,15 @@ function refreshSettings() {
657704}
658705
659706function 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+
660716 for ( let i = 0 ; i < settings . length ; i ++ ) {
661717 let setting = /** @type {HTMLInputElement } */ ( settings [ i ] ) ;
662718 // json-path="description"
@@ -783,6 +839,28 @@ function loadJsonIntoUI() {
783839 } ) ;
784840 setPath ( configPath , value ) ;
785841 } ) . 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+
786864 if ( setting . tagName == "VSCODE-TEXT-FIELD" || setting . tagName == "VSCODE-TEXT-AREA" )
787865 setting . oninput = changeFun ;
788866 else
0 commit comments