Hide Category title if empty

This commit is contained in:
Marterich 2024-05-18 23:28:38 +02:00
parent 2354645b47
commit f453534f74
2 changed files with 27 additions and 3 deletions

View File

@ -77,7 +77,10 @@ function Get-TabXaml {
$panelcount++
}
}
$blockXml += "<Label Content=""$($category -replace '^.__', '')"" FontSize=""16""/>`n"
$categorycontent = $($category -replace '^.__', '')
# Remove all special Characters from the name because it will later be used as a Powershell Variable
$categoryname = "WPFLabel"+$($categorycontent -replace '[^a-zA-Z0-9]','')
$blockXml += "<Label Name=""$categoryname"" Content=""$categorycontent"" FontSize=""16""/>`n"
$sortedApps = $organizedData[$panel][$category].Keys | Sort-Object
foreach ($appName in $sortedApps) {
$count++

View File

@ -363,6 +363,15 @@ Add-Type @"
})
# Load Checkboxes and Labels outside of the Filter fuction only once on startup for performance reasons
$filter = Get-WinUtilVariables -Type CheckBox
$CheckBoxes = $sync.GetEnumerator() | Where-Object { $psitem.Key -in $filter }
$filter = Get-WinUtilVariables -Type Label
$labels = $sync.GetEnumerator() | Where-Object {$PSItem.Key -in $filter}
$allCategories = $checkBoxes.Name | ForEach-Object {$sync.configs.applications.$_} | Select-Object -Unique -ExpandProperty category
$sync["CheckboxFilter"].Add_TextChanged({
if ($sync.CheckboxFilter.Text -ne "") {
@ -372,8 +381,7 @@ $sync["CheckboxFilter"].Add_TextChanged({
$sync.CheckboxFilterClear.Visibility = "Collapsed"
}
$filter = Get-WinUtilVariables -Type CheckBox
$CheckBoxes = $sync.GetEnumerator() | Where-Object { $psitem.Key -in $filter }
$activeApplications = @()
foreach ($CheckBox in $CheckBoxes) {
# Check if the checkbox is null or if it doesn't have content
@ -390,6 +398,7 @@ $sync["CheckboxFilter"].Add_TextChanged({
if ($CheckBox.Value.Content.ToLower().Contains($textToSearch)) {
$CheckBox.Value.Visibility = "Visible"
$activeApplications += $sync.configs.applications.$checkboxName
# Set the corresponding text block visibility
if ($textBlock -ne $null) {
$textBlock.Visibility = "Visible"
@ -403,6 +412,18 @@ $sync["CheckboxFilter"].Add_TextChanged({
}
}
}
$activeCategories = $activeApplications | Select-Object -ExpandProperty category -Unique
foreach ($category in $activeCategories){
$label = $Labels | Where-Object {$_.Key -eq "WPFLabel"+$($category -replace '[^a-zA-Z0-9]','')}
$label.Value.Visibility = "Visible"
}
if ($activeCategories -ne $null){
$inactiveCategories = Compare-Object -ReferenceObject $allCategories -DifferenceObject $activeCategories -PassThru
foreach ($category in $inactiveCategories){
$label = $Labels | Where-Object {$_.Key -eq "WPFLabel"+$($category -replace '[^a-zA-Z0-9]','')}
$label.Value.Visibility = "Collapsed"}
}
})