Refactor: Centralize driver checkbox event handling

Moves the interdependent state logic for the driver-related checkboxes from the main UI script into a new, centralized function within the core module.

This change simplifies the event handling by using a single handler for all related checkboxes, which improves code readability and maintainability. The new function is also called during initialization to ensure the UI reflects the correct state on startup.
This commit is contained in:
rbalsleyMSFT
2025-06-19 15:42:57 -07:00
parent 2cfd947429
commit a4e9b70b27
4 changed files with 108 additions and 94 deletions
-35
View File
@@ -217,41 +217,6 @@ $window.Add_Loaded({
}
Update-CopyButtonState -State $script:uiState # Initial check
# General Browse Button Handlers (Keep existing logic)
# Driver Checkbox Conditional Logic
$script:uiState.Controls.chkInstallDrivers.Add_Checked({
$script:uiState.Controls.chkCopyDrivers.IsEnabled = $false
$script:uiState.Controls.chkCompressDriversToWIM.IsEnabled = $false
})
$script:uiState.Controls.chkInstallDrivers.Add_Unchecked({
# Only re-enable if the other checkboxes are not checked
if (-not $script:uiState.Controls.chkCopyDrivers.IsChecked) {
$script:uiState.Controls.chkCopyDrivers.IsEnabled = $true
}
if (-not $script:uiState.Controls.chkCompressDriversToWIM.IsChecked) {
$script:uiState.Controls.chkCompressDriversToWIM.IsEnabled = $true
}
})
$script:uiState.Controls.chkCopyDrivers.Add_Checked({
$script:uiState.Controls.chkInstallDrivers.IsEnabled = $false
})
$script:uiState.Controls.chkCopyDrivers.Add_Unchecked({
# Only re-enable if InstallDrivers is not checked
if (-not $script:uiState.Controls.chkInstallDrivers.IsChecked) { $script:uiState.Controls.chkInstallDrivers.IsEnabled = $true }
})
$script:uiState.Controls.chkCompressDriversToWIM.Add_Checked({
$script:uiState.Controls.chkInstallDrivers.IsEnabled = $false
})
$script:uiState.Controls.chkCompressDriversToWIM.Add_Unchecked({
# Only re-enable if InstallDrivers is not checked
if (-not $script:uiState.Controls.chkInstallDrivers.IsChecked) { $script:uiState.Controls.chkInstallDrivers.IsEnabled = $true }
})
# Set initial state based on defaults (assuming defaults are false)
$script:uiState.Controls.chkInstallDrivers.IsEnabled = $true
$script:uiState.Controls.chkCopyDrivers.IsEnabled = $true
$script:uiState.Controls.chkCompressDriversToWIM.IsEnabled = $true
# AppsScriptVariables Event Handlers
$script:uiState.Controls.chkDefineAppsScriptVariables.Add_Checked({
$script:uiState.Controls.appsScriptVariablesPanel.Visibility = 'Visible'