Refactor code structure for improved readability and maintainability (#473)

* Add ToolTips to Tweaks
This commit is contained in:
Jeffrey
2026-02-15 23:08:54 +01:00
committed by GitHub
parent 95dc490b6e
commit 65aabbc050
31 changed files with 2877 additions and 2813 deletions

View File

@@ -0,0 +1,80 @@
# Applies settings from a JSON object to UI controls (checkboxes and comboboxes)
# Used by LoadDefaultsBtn and LoadLastUsedBtn in the UI
function ApplySettingsToUiControls {
param (
$window,
$settingsJson,
$uiControlMappings
)
if (-not $settingsJson -or -not $settingsJson.Settings) {
return $false
}
# First, reset all tweaks to "No Change" (index 0) or unchecked
if ($uiControlMappings) {
foreach ($comboName in $uiControlMappings.Keys) {
$control = $window.FindName($comboName)
if ($control -is [System.Windows.Controls.CheckBox]) {
$control.IsChecked = $false
}
elseif ($control -is [System.Windows.Controls.ComboBox]) {
$control.SelectedIndex = 0
}
}
}
# Also uncheck RestorePointCheckBox
$restorePointCheckBox = $window.FindName('RestorePointCheckBox')
if ($restorePointCheckBox) {
$restorePointCheckBox.IsChecked = $false
}
# Apply settings from JSON
foreach ($setting in $settingsJson.Settings) {
if ($setting.Value -ne $true) { continue }
$paramName = $setting.Name
# Handle RestorePointCheckBox separately
if ($paramName -eq 'CreateRestorePoint') {
if ($restorePointCheckBox) { $restorePointCheckBox.IsChecked = $true }
continue
}
if ($uiControlMappings) {
foreach ($comboName in $uiControlMappings.Keys) {
$mapping = $uiControlMappings[$comboName]
if ($mapping.Type -eq 'group') {
$i = 1
foreach ($val in $mapping.Values) {
if ($val.FeatureIds -contains $paramName) {
$control = $window.FindName($comboName)
if ($control -and $control.Visibility -eq 'Visible') {
if ($control -is [System.Windows.Controls.ComboBox]) {
$control.SelectedIndex = $i
}
}
break
}
$i++
}
}
elseif ($mapping.Type -eq 'feature') {
if ($mapping.FeatureId -eq $paramName) {
$control = $window.FindName($comboName)
if ($control -and $control.Visibility -eq 'Visible') {
if ($control -is [System.Windows.Controls.CheckBox]) {
$control.IsChecked = $true
}
elseif ($control -is [System.Windows.Controls.ComboBox]) {
$control.SelectedIndex = 1
}
}
}
}
}
}
}
return $true
}