mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Add Clear List button to Save/Import functionality and fixed sorting issues with winget app list.
This commit is contained in:
@@ -11,8 +11,7 @@ $AppsPath = Join-Path $FFUDevelopmentPath "Apps"
|
||||
# Add the new function for USB drive detection
|
||||
function Get-USBDrives {
|
||||
Get-WmiObject Win32_DiskDrive | Where-Object {
|
||||
($_.MediaType -eq 'Removable Media' -or $_.MediaType -eq 'External hard disk media') -and
|
||||
$_.InterfaceType -eq 'USB'
|
||||
($_.MediaType -eq 'Removable Media' -or $_.MediaType -eq 'External hard disk media')
|
||||
} | ForEach-Object {
|
||||
$size = [math]::Round($_.Size / 1GB, 2)
|
||||
$serialNumber = if ($_.SerialNumber) { $_.SerialNumber.Trim() } else { "N/A" }
|
||||
@@ -336,7 +335,8 @@ function Get-UIConfig {
|
||||
VMLocation = $window.FindName('txtVMLocation').Text
|
||||
VMSwitchName = if ($window.FindName('cmbVMSwitchName').SelectedItem -eq 'Other') {
|
||||
$window.FindName('txtCustomVMSwitchName').Text
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$window.FindName('cmbVMSwitchName').SelectedItem
|
||||
}
|
||||
WindowsArch = $window.FindName('cmbWindowsArch').SelectedItem
|
||||
@@ -495,7 +495,8 @@ $script:UpdateInstallAppsBasedOnUpdates = {
|
||||
}
|
||||
$window.FindName('chkInstallApps').IsChecked = $true
|
||||
$window.FindName('chkInstallApps').IsEnabled = $false
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if ($script:installAppsForcedByUpdates) {
|
||||
$window.FindName('chkInstallApps').IsChecked = $script:prevInstallAppsStateBeforeUpdates
|
||||
$script:installAppsForcedByUpdates = $false
|
||||
@@ -543,11 +544,11 @@ function Add-SortableColumn {
|
||||
$column.DisplayMemberBinding = New-Object System.Windows.Data.Binding($binding)
|
||||
}
|
||||
|
||||
# Create the header with sorting support
|
||||
$columnHeader = New-Object System.Windows.Controls.GridViewColumnHeader
|
||||
$columnHeader.Content = $header
|
||||
$columnHeader.Tag = $binding
|
||||
$column.Header = $columnHeader
|
||||
# Create a header with the binding information stored in its Tag
|
||||
$headerTemplate = New-Object System.Windows.Controls.GridViewColumnHeader
|
||||
$headerTemplate.Content = $header
|
||||
$headerTemplate.Tag = $binding
|
||||
$column.Header = $headerTemplate
|
||||
|
||||
if ($width -ne 'Auto') {
|
||||
$column.Width = $width
|
||||
@@ -570,12 +571,13 @@ function Invoke-ListViewSort {
|
||||
# Toggle sort direction if clicking the same column
|
||||
if ($script:lastSortProperty -eq $property) {
|
||||
$script:lastSortAscending = -not $script:lastSortAscending
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$script:lastSortAscending = $true
|
||||
}
|
||||
$script:lastSortProperty = $property
|
||||
|
||||
# Convert ListView items to array and split into selected and unselected
|
||||
# Store selected items
|
||||
$items = @($listView.Items)
|
||||
$selectedItems = @($items | Where-Object { $_.IsSelected })
|
||||
$unselectedItems = @($items | Where-Object { -not $_.IsSelected })
|
||||
@@ -583,19 +585,22 @@ function Invoke-ListViewSort {
|
||||
# Sort unselected items
|
||||
$sortedUnselected = if ($script:lastSortAscending) {
|
||||
@($unselectedItems | Sort-Object -Property $property)
|
||||
} else {
|
||||
@($unselectedUnselected | Sort-Object -Property $property -Descending)
|
||||
}
|
||||
else {
|
||||
@($unselectedItems | Sort-Object -Property $property -Descending)
|
||||
}
|
||||
|
||||
# Clear and repopulate ListView
|
||||
$listView.Items.Clear()
|
||||
|
||||
# Add items back in correct order (selected first, then sorted unselected)
|
||||
# Add selected items first
|
||||
foreach ($item in $selectedItems) {
|
||||
$listView.Items.Add($item)
|
||||
[void]$listView.Items.Add($item)
|
||||
}
|
||||
|
||||
# Add sorted unselected items
|
||||
foreach ($item in $sortedUnselected) {
|
||||
$listView.Items.Add($item)
|
||||
[void]$listView.Items.Add($item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -775,7 +780,8 @@ $window.Add_Loaded({
|
||||
}
|
||||
$window.FindName('chkInstallApps').IsChecked = $true
|
||||
$window.FindName('chkInstallApps').IsEnabled = $false
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if ($script:installAppsForcedByUpdates) {
|
||||
$window.FindName('chkInstallApps').IsChecked = $script:prevInstallAppsStateBeforeUpdates
|
||||
$script:installAppsForcedByUpdates = $false
|
||||
@@ -996,6 +1002,7 @@ $window.Add_Loaded({
|
||||
$script:lstWingetResults = $window.FindName('lstWingetResults')
|
||||
$script:btnSaveWingetList = $window.FindName('btnSaveWingetList')
|
||||
$script:btnImportWingetList = $window.FindName('btnImportWingetList')
|
||||
$script:btnClearWingetList = $window.FindName('btnClearWingetList')
|
||||
|
||||
# Initialize ListView with GridView columns
|
||||
$gridView = New-Object System.Windows.Controls.GridView
|
||||
@@ -1006,6 +1013,18 @@ $window.Add_Loaded({
|
||||
Add-SortableColumn -gridView $gridView -header "Source" -binding "Source" -width 100
|
||||
$script:lstWingetResults.View = $gridView
|
||||
|
||||
# Add column header click handler for sorting
|
||||
$script:lstWingetResults.AddHandler(
|
||||
[System.Windows.Controls.GridViewColumnHeader]::ClickEvent,
|
||||
[System.Windows.RoutedEventHandler] {
|
||||
param($sender, $e)
|
||||
$header = $e.OriginalSource
|
||||
if ($header -is [System.Windows.Controls.GridViewColumnHeader] -and $header.Tag) {
|
||||
Invoke-ListViewSort -listView $script:lstWingetResults -property $header.Tag
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
# Hide search panel initially
|
||||
$script:wingetSearchPanel.Visibility = 'Collapsed'
|
||||
|
||||
@@ -1022,15 +1041,6 @@ $window.Add_Loaded({
|
||||
}
|
||||
})
|
||||
|
||||
# Save and Import buttons
|
||||
$script:btnSaveWingetList.Add_Click({
|
||||
Save-WingetList
|
||||
})
|
||||
|
||||
$script:btnImportWingetList.Add_Click({
|
||||
Import-WingetList
|
||||
})
|
||||
|
||||
# Show search panel after successful Winget validation
|
||||
$script:btnCheckWingetModule.Add_Click({
|
||||
# ...existing code...
|
||||
@@ -1054,21 +1064,14 @@ $window.Add_Loaded({
|
||||
}
|
||||
})
|
||||
|
||||
$script:lstWingetResults.Add_PreviewMouseLeftButtonUp({
|
||||
param($eventSrc, $mouseEventArgs)
|
||||
$originalSource = $mouseEventArgs.OriginalSource
|
||||
$header = [System.Windows.Media.VisualTreeHelper]::GetParent($originalSource)
|
||||
while ($header -ne $null -and $header -isnot [System.Windows.Controls.GridViewColumnHeader]) {
|
||||
$header = [System.Windows.Media.VisualTreeHelper]::GetParent($header)
|
||||
}
|
||||
|
||||
if ($header -is [System.Windows.Controls.GridViewColumnHeader]) {
|
||||
$headerContent = $header.Column.Header
|
||||
if ($headerContent -is [System.Windows.Controls.GridViewColumnHeader]) {
|
||||
if ($headerContent.Tag) {
|
||||
Invoke-ListViewSort -listView $script:lstWingetResults -property $headerContent.Tag
|
||||
}
|
||||
}
|
||||
# Add handlers for Winget app list buttons
|
||||
$script:btnSaveWingetList.Add_Click({ Save-WingetList })
|
||||
$script:btnImportWingetList.Add_Click({ Import-WingetList })
|
||||
$script:btnClearWingetList.Add_Click({
|
||||
$script:lstWingetResults.Items.Clear()
|
||||
$script:txtWingetSearch.Text = "" # Clear the Winget search textbox
|
||||
if ($script:txtStatus) {
|
||||
$script:txtStatus.Text = "Cleared all applications from the list"
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -637,7 +637,7 @@
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"/>
|
||||
|
||||
<!-- Save/Import Buttons -->
|
||||
<!-- Save/Import/Clear Buttons -->
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||
<Button x:Name="btnSaveWingetList"
|
||||
Content="Save Applist.json"
|
||||
@@ -647,7 +647,12 @@
|
||||
<Button x:Name="btnImportWingetList"
|
||||
Content="Import Applist.json"
|
||||
Padding="15,5"
|
||||
Margin="0,0,10,0"
|
||||
ToolTip="Import applications from a JSON file"/>
|
||||
<Button x:Name="btnClearWingetList"
|
||||
Content="Clear List"
|
||||
Padding="15,5"
|
||||
ToolTip="Clear all applications from the list"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
Reference in New Issue
Block a user