Files
winutil/functions/public/Invoke-WPFSelectedCheckboxesUpdate.ps1
T
Gabi 8034e85521 Remove Write-Debug (#4498)
* Update Invoke-WinUtilCurrentSystem.ps1

* Update Invoke-WinUtilFontScaling.ps1

* Update Invoke-WinUtilTweaks.ps1

* Update Reset-WPFCheckBoxes.ps1

* Update Set-Preferences.ps1

* Update Update-WinUtilSelections.ps1

* Update Invoke-WPFSelectedCheckboxesUpdate.ps1

* Update Invoke-WPFtweaksbutton.ps1

* Update main.ps1

* Update main.ps1

* Update main.ps1

* Update main.ps1

* Update main.ps1

* Merge branch 'main' into Remove-Write-Debug
2026-05-19 13:16:06 -05:00

89 lines
3.4 KiB
PowerShell

function Invoke-WPFSelectedCheckboxesUpdate{
<#
.SYNOPSIS
This is a helper function that is called by the Checked and Unchecked events of the Checkboxes.
It also Updates the "Selected Apps" selectedAppLabel on the Install Tab to represent the current collection
.PARAMETER type
Either: Add | Remove
.PARAMETER checkboxName
should contain the name of the current instance of the checkbox that triggered the Event.
Most of the time will be the automatic variable $this.Parent.Tag
.EXAMPLE
$checkbox.Add_Unchecked({Invoke-WPFSelectedCheckboxesUpdate -type "Remove" -checkboxName $this.Parent.Tag})
OR
Invoke-WPFSelectedCheckboxesUpdate -type "Add" -checkboxName $specificCheckbox.Parent.Tag
#>
param (
$type,
$checkboxName
)
if (($type -ne "Add") -and ($type -ne "Remove"))
{
Write-Error "Type: $type not implemented"
return
}
# Get the actual Name from the selectedAppLabel inside the Checkbox
$appKey = $checkboxName
$group = if ($appKey.StartsWith("WPFInstall")) { "Install" }
elseif ($appKey.StartsWith("WPFTweaks")) { "Tweaks" }
elseif ($appKey.StartsWith("WPFToggle")) { "Toggle" }
elseif ($appKey.StartsWith("WPFFeature")) { "Feature" }
else { "na" }
switch ($group) {
"Install" {
if ($type -eq "Add") {
if (!$sync.selectedApps.Contains($appKey)) {
$sync.selectedApps.Add($appKey)
# The List type needs to be specified again, because otherwise Sort-Object will convert the list to a string if there is only a single entry
[System.Collections.Generic.List[string]]$sync.selectedApps = $sync.SelectedApps | Sort-Object
}
}
else{
$sync.selectedApps.Remove($appKey)
}
$count = $sync.SelectedApps.Count
$sync.WPFselectedAppsButton.Content = "Selected Apps: $count"
# On every change, remove all entries inside the Popup Menu. This is done, so we can keep the alphabetical order even if elements are selected in a random way
$sync.selectedAppsstackPanel.Children.Clear()
$sync.selectedApps | Foreach-Object { Add-SelectedAppsMenuItem -name $($sync.configs.applicationsHashtable.$_.Content) -key $_ }
}
"Tweaks" {
if ($type -eq "Add") {
if (!$sync.selectedTweaks.Contains($appKey)) {
$sync.selectedTweaks.Add($appKey)
}
}
else{
$sync.selectedTweaks.Remove($appKey)
}
}
"Toggle" {
if ($type -eq "Add") {
if (!$sync.selectedToggles.Contains($appKey)) {
$sync.selectedToggles.Add($appKey)
}
}
else{
$sync.selectedToggles.Remove($appKey)
}
}
"Feature" {
if ($type -eq "Add") {
if (!$sync.selectedFeatures.Contains($appKey)) {
$sync.selectedFeatures.Add($appKey)
}
}
else{
$sync.selectedFeatures.Remove($appKey)
}
}
default {
Write-Host "Unknown group for checkbox: $($appKey)"
}
}
}