mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Refactor USB drive event handlers to core module
Moves the event handling logic for the USB drive selection controls from the main UI script to the `FFUUI.Core.Handlers` module. This change improves code organization by centralizing UI logic. The handlers were also improved to correctly manage the "Select All" checkbox state.
This commit is contained in:
@@ -194,31 +194,6 @@ $window.Add_Loaded({
|
||||
$script:uiState.Controls.chkLatestCU.IsEnabled = -not $script:uiState.Controls.chkPreviewCU.IsChecked
|
||||
|
||||
# USB Drive Detection/Selection logic (Keep existing logic)
|
||||
$script:uiState.Controls.chkSelectAllUSBDrives.Add_Checked({
|
||||
foreach ($item in $script:uiState.Controls.lstUSBDrives.Items) { $item.IsSelected = $true }
|
||||
$script:uiState.Controls.lstUSBDrives.Items.Refresh()
|
||||
})
|
||||
$script:uiState.Controls.chkSelectAllUSBDrives.Add_Unchecked({
|
||||
foreach ($item in $script:uiState.Controls.lstUSBDrives.Items) { $item.IsSelected = $false }
|
||||
$script:uiState.Controls.lstUSBDrives.Items.Refresh()
|
||||
})
|
||||
$script:uiState.Controls.lstUSBDrives.Add_KeyDown({
|
||||
param($eventSource, $keyEvent)
|
||||
if ($keyEvent.Key -eq 'Space') {
|
||||
$selectedItem = $script:uiState.Controls.lstUSBDrives.SelectedItem
|
||||
if ($selectedItem) {
|
||||
$selectedItem.IsSelected = !$selectedItem.IsSelected
|
||||
$script:uiState.Controls.lstUSBDrives.Items.Refresh()
|
||||
$allSelected = -not ($script:uiState.Controls.lstUSBDrives.Items | Where-Object { -not $_.IsSelected })
|
||||
$script:uiState.Controls.chkSelectAllUSBDrives.IsChecked = $allSelected
|
||||
}
|
||||
}
|
||||
})
|
||||
$script:uiState.Controls.lstUSBDrives.Add_SelectionChanged({
|
||||
param($eventSource, $selChangeEvent)
|
||||
$allSelected = -not ($script:uiState.Controls.lstUSBDrives.Items | Where-Object { -not $_.IsSelected })
|
||||
$script:uiState.Controls.chkSelectAllUSBDrives.IsChecked = $allSelected
|
||||
})
|
||||
$script:uiState.Controls.usbSection.Visibility = if ($script:uiState.Controls.chkBuildUSBDriveEnable.IsChecked) { 'Visible' } else { 'Collapsed' }
|
||||
$script:uiState.Controls.usbSelectionPanel.Visibility = if ($script:uiState.Controls.chkSelectSpecificUSBDrives.IsChecked) { 'Visible' } else { 'Collapsed' }
|
||||
$script:uiState.Controls.chkBuildUSBDriveEnable.Add_Checked({
|
||||
|
||||
@@ -3,6 +3,7 @@ function Register-EventHandlers {
|
||||
WriteLog "Registering UI event handlers..."
|
||||
|
||||
# Build Tab Event Handlers
|
||||
# Build USB Drive Settings Event Handlers
|
||||
$State.Controls.btnCheckUSBDrives.Add_Click({
|
||||
param($eventSource, $routedEventArgs)
|
||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||
@@ -18,6 +19,49 @@ function Register-EventHandlers {
|
||||
}
|
||||
})
|
||||
|
||||
$State.Controls.chkSelectAllUSBDrives.Add_Checked({
|
||||
param($eventSource, $routedEventArgs)
|
||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||
$localState = $window.Tag
|
||||
foreach ($item in $localState.Controls.lstUSBDrives.Items) { $item.IsSelected = $true }
|
||||
$localState.Controls.lstUSBDrives.Items.Refresh()
|
||||
})
|
||||
$State.Controls.chkSelectAllUSBDrives.Add_Unchecked({
|
||||
param($eventSource, $routedEventArgs)
|
||||
# This event also fires for indeterminate state, so only act if it's explicitly false.
|
||||
if ($eventSource.IsChecked -eq $false) {
|
||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||
$localState = $window.Tag
|
||||
foreach ($item in $localState.Controls.lstUSBDrives.Items) { $item.IsSelected = $false }
|
||||
$localState.Controls.lstUSBDrives.Items.Refresh()
|
||||
}
|
||||
})
|
||||
$State.Controls.lstUSBDrives.Add_KeyDown({
|
||||
param($eventSource, $keyEvent)
|
||||
if ($keyEvent.Key -eq 'Space') {
|
||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||
$localState = $window.Tag
|
||||
$selectedItem = $localState.Controls.lstUSBDrives.SelectedItem
|
||||
if ($selectedItem) {
|
||||
$selectedItem.IsSelected = -not $selectedItem.IsSelected
|
||||
$localState.Controls.lstUSBDrives.Items.Refresh()
|
||||
# After toggling, update the 'Select All' checkbox state
|
||||
$items = $localState.Controls.lstUSBDrives.Items
|
||||
$allSelected = $items.Count -gt 0 -and ($items | Where-Object { -not $_.IsSelected }).Count -eq 0
|
||||
$localState.Controls.chkSelectAllUSBDrives.IsChecked = $allSelected
|
||||
}
|
||||
}
|
||||
})
|
||||
$State.Controls.lstUSBDrives.Add_SelectionChanged({
|
||||
param($eventSource, $selChangeEvent)
|
||||
$window = [System.Windows.Window]::GetWindow($eventSource)
|
||||
$localState = $window.Tag
|
||||
$items = $localState.Controls.lstUSBDrives.Items
|
||||
# Update the 'Select All' checkbox state based on current selections
|
||||
$allSelected = $items.Count -gt 0 -and ($items | Where-Object { -not $_.IsSelected }).Count -eq 0
|
||||
$localState.Controls.chkSelectAllUSBDrives.IsChecked = $allSelected
|
||||
})
|
||||
|
||||
# Hyper-V tab event handlers
|
||||
$State.Controls.cmbVMSwitchName.Add_SelectionChanged({
|
||||
param($eventSource, $selectionChangedEventArgs)
|
||||
|
||||
Reference in New Issue
Block a user