Files
winutil/functions/public/Invoke-WPFSelectedCheckboxesUpdate.ps1
T
GabiNun2 e8c1401cce feat: add config-driven AppX package removal tab
- Add config/appx.json with curated list of removable AppX packages

- Add AppX Removal tab (WPFTab6) with Select All, Clear, and Remove buttons

- Reuse existing Invoke-WPFUIElements engine for minimal code footprint

- Add Invoke-WPFAppxRemoval.ps1 for background runspace package removal

- Add theme colors for the new tab button in light and dark modes
2026-06-21 17:57:41 +03:00

100 lines
3.8 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" }
elseif ($appKey.StartsWith("WPFAppx")) { "Appx" }
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)
}
}
"Appx" {
if ($type -eq "Add") {
if (!$sync.selectedAppx.Contains($appKey)) {
$sync.selectedAppx.Add($appKey)
}
}
else{
$sync.selectedAppx.Remove($appKey)
}
}
default {
Write-Host "Unknown group for checkbox: $($appKey)"
}
}
}