Refactor Applications tab UI event handling

Consolidates the scattered event handlers for the Applications tab checkboxes into a single, centralized function and a shared event handler. This new approach manages the visibility of all dependent UI panels based on the state of the checkboxes.

This refactoring simplifies the codebase, eliminates redundant logic, and ensures a more consistent and predictable user interface state.

Additionally, this change fixes bugs where clearing list views for Winget results and drivers did not properly update their "select all" header checkboxes.
This commit is contained in:
rbalsleyMSFT
2025-06-19 18:38:53 -07:00
parent c946e56a41
commit 4b7e815c68
4 changed files with 74 additions and 84 deletions
+40
View File
@@ -189,6 +189,46 @@ function Get-USBDrives {
}
}
# Function to manage the visibility of the application UI panels
function Update-ApplicationPanelVisibility {
param(
[PSCustomObject]$State,
[string]$TriggeringControlName # Optional: to know which control initiated the change
)
$installAppsChecked = $State.Controls.chkInstallApps.IsChecked
# If the main 'Install Apps' is unchecked, everything below it gets hidden and reset.
if ($TriggeringControlName -eq 'chkInstallApps' -and -not $installAppsChecked) {
$State.Controls.chkInstallWingetApps.IsChecked = $false
$State.Controls.chkBringYourOwnApps.IsChecked = $false
$State.Controls.chkDefineAppsScriptVariables.IsChecked = $false
}
$byoAppsChecked = $State.Controls.chkBringYourOwnApps.IsChecked
$wingetAppsChecked = $State.Controls.chkInstallWingetApps.IsChecked
$defineVarsChecked = $State.Controls.chkDefineAppsScriptVariables.IsChecked
# Visibility of primary sub-options
$subOptionVisibility = if ($installAppsChecked) { 'Visible' } else { 'Collapsed' }
$State.Controls.applicationPathPanel.Visibility = $subOptionVisibility
$State.Controls.appListJsonPathPanel.Visibility = $subOptionVisibility
$State.Controls.chkInstallWingetApps.Visibility = $subOptionVisibility
$State.Controls.chkBringYourOwnApps.Visibility = $subOptionVisibility
$State.Controls.chkDefineAppsScriptVariables.Visibility = $subOptionVisibility
# Visibility of panels dependent on sub-options
$State.Controls.byoApplicationPanel.Visibility = if ($installAppsChecked -and $byoAppsChecked) { 'Visible' } else { 'Collapsed' }
$State.Controls.wingetPanel.Visibility = if ($installAppsChecked -and $wingetAppsChecked) { 'Visible' } else { 'Collapsed' }
$State.Controls.appsScriptVariablesPanel.Visibility = if ($installAppsChecked -and $defineVarsChecked) { 'Visible' } else { 'Collapsed' }
# Special handling for wingetSearchPanel, which is shown by another button.
# We only collapse it if its parent becomes invisible.
if (-not ($installAppsChecked -and $wingetAppsChecked)) {
$State.Controls.wingetSearchPanel.Visibility = 'Collapsed'
}
}
# Function to manage the state of the main "Install Apps" checkbox based on selections in Updates/Office
function Update-InstallAppsState {
param([PSCustomObject]$State)