mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-02-06 16:00:10 +00:00
finish new install GUI
This commit is contained in:
51
functions/public/Invoke-WPFToggleAllCategories.ps1
Normal file
51
functions/public/Invoke-WPFToggleAllCategories.ps1
Normal file
@@ -0,0 +1,51 @@
|
||||
function Invoke-WPFToggleAllCategories {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Expands or collapses all categories in the Install tab
|
||||
|
||||
.PARAMETER Action
|
||||
The action to perform: "Expand" or "Collapse"
|
||||
|
||||
.DESCRIPTION
|
||||
This function iterates through all category containers in the Install tab
|
||||
and expands or collapses their WrapPanels while updating the toggle button labels
|
||||
#>
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[ValidateSet("Expand", "Collapse")]
|
||||
[string]$Action
|
||||
)
|
||||
|
||||
try {
|
||||
if ($null -eq $sync.ItemsControl) {
|
||||
Write-Warning "ItemsControl not initialized"
|
||||
return
|
||||
}
|
||||
|
||||
$targetVisibility = if ($Action -eq "Expand") { [Windows.Visibility]::Visible } else { [Windows.Visibility]::Collapsed }
|
||||
$targetPrefix = if ($Action -eq "Expand") { "-" } else { "+" }
|
||||
$sourcePrefix = if ($Action -eq "Expand") { "+" } else { "-" }
|
||||
|
||||
# Iterate through all items in the ItemsControl
|
||||
$sync.ItemsControl.Items | ForEach-Object {
|
||||
$categoryContainer = $_
|
||||
|
||||
# Check if this is a category container (StackPanel with children)
|
||||
if ($categoryContainer -is [System.Windows.Controls.StackPanel] -and $categoryContainer.Children.Count -ge 2) {
|
||||
# Get the WrapPanel (second child)
|
||||
$wrapPanel = $categoryContainer.Children[1]
|
||||
$wrapPanel.Visibility = $targetVisibility
|
||||
|
||||
# Update the label to show the correct state
|
||||
$categoryLabel = $categoryContainer.Children[0]
|
||||
if ($categoryLabel.Content -like "$sourcePrefix*") {
|
||||
$categoryLabel.Content = $categoryLabel.Content -replace "^$sourcePrefix ", "$targetPrefix "
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Error toggling categories: $_"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user