mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-17 10:17:44 -06:00
Optimize Display Behaviour of Category Labels (#1979)
* Hide Category title if empty * Changed labels to a hashtable for faster access * Extract WPFNamecreation to function, fix hide all if none match
This commit is contained in:
parent
ef81968a85
commit
0ec64eaf74
@ -77,7 +77,13 @@ function Get-TabXaml {
|
||||
$panelcount++
|
||||
}
|
||||
}
|
||||
$blockXml += "<Label Content=""$($category -replace '^.__', '')"" FontSize=""16""/>`n"
|
||||
|
||||
# Dot-source the Get-WPFObjectName function
|
||||
. .\functions\private\Get-WPFObjectName
|
||||
|
||||
$categorycontent = $($category -replace '^.__', '')
|
||||
$categoryname = Get-WPFObjectName -type "Label" -name $categorycontent
|
||||
$blockXml += "<Label Name=""$categoryname"" Content=""$categorycontent"" FontSize=""16""/>`n"
|
||||
$sortedApps = $organizedData[$panel][$category].Keys | Sort-Object
|
||||
foreach ($appName in $sortedApps) {
|
||||
$count++
|
||||
|
27
functions/private/Get-WPFObjectName.ps1
Normal file
27
functions/private/Get-WPFObjectName.ps1
Normal file
@ -0,0 +1,27 @@
|
||||
function Get-WPFObjectName {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
This is a helper function that generates an objectname with the prefix WPF that can be used as a Powershell Variable after compilation.
|
||||
To achieve this, all characters that are not a-z, A-Z or 0-9 are simply removed from the name.
|
||||
.PARAMETER type
|
||||
The type of object for which the name should be generated. (e.g. Label, Button, CheckBox...)
|
||||
.PARAMETER name
|
||||
The name or description to be used for the object. (invalid characters are removed)
|
||||
.OUTPUTS
|
||||
A string that can be used as a object/variable name in powershell.
|
||||
For example: WPFLabelMicrosoftTools
|
||||
|
||||
.EXAMPLE
|
||||
Get-WPFObjectName -type Label -name "Microsoft Tools"
|
||||
#>
|
||||
|
||||
param( [Parameter(Mandatory=$true)]
|
||||
$type,
|
||||
$name
|
||||
)
|
||||
|
||||
$Output = $("WPF"+$type+$name) -replace '[^a-zA-Z0-9]', ''
|
||||
|
||||
return $Output
|
||||
|
||||
}
|
@ -367,6 +367,16 @@ 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} | ForEach-Object {$labels[$_.Key] = $_.Value}
|
||||
|
||||
$allCategories = $checkBoxes.Name | ForEach-Object {$sync.configs.applications.$_} | Select-Object -Unique -ExpandProperty category
|
||||
|
||||
$sync["CheckboxFilter"].Add_TextChanged({
|
||||
|
||||
if ($sync.CheckboxFilter.Text -ne "") {
|
||||
@ -376,8 +386,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
|
||||
@ -394,6 +403,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"
|
||||
@ -407,7 +417,21 @@ $sync["CheckboxFilter"].Add_TextChanged({
|
||||
}
|
||||
}
|
||||
}
|
||||
$activeCategories = $activeApplications | Select-Object -ExpandProperty category -Unique
|
||||
|
||||
foreach ($category in $activeCategories){
|
||||
$label = $labels[$(Get-WPFObjectName -type "Label" -name $category)]
|
||||
$label.Visibility = "Visible"
|
||||
}
|
||||
if ($activeCategories){
|
||||
$inactiveCategories = Compare-Object -ReferenceObject $allCategories -DifferenceObject $activeCategories -PassThru
|
||||
}
|
||||
else{
|
||||
$inactiveCategories = $allCategories
|
||||
}
|
||||
foreach ($category in $inactiveCategories){
|
||||
$label = $labels[$(Get-WPFObjectName -type "Label" -name $category)]
|
||||
$label.Visibility = "Collapsed"}
|
||||
})
|
||||
|
||||
# Define event handler for button click
|
||||
|
Loading…
Reference in New Issue
Block a user