mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-17 18:27:42 -06:00
Extract WPFNamecreation to function, fix hide all if none match
This commit is contained in:
parent
0e613f029a
commit
9b46ec1a12
@ -77,9 +77,12 @@ function Get-TabXaml {
|
||||
$panelcount++
|
||||
}
|
||||
}
|
||||
|
||||
# Dot-source the Get-WPFObjectName function
|
||||
. .\functions\private\Get-WPFObjectName
|
||||
|
||||
$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]','')
|
||||
$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) {
|
||||
|
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
|
||||
|
||||
}
|
@ -416,16 +416,18 @@ $sync["CheckboxFilter"].Add_TextChanged({
|
||||
$activeCategories = $activeApplications | Select-Object -ExpandProperty category -Unique
|
||||
|
||||
foreach ($category in $activeCategories){
|
||||
$label = $labels["WPFLabel"+$($category -replace '[^a-zA-Z0-9]')]
|
||||
$label = $labels[$(Get-WPFObjectName -type "Label" -name $category)]
|
||||
$label.Visibility = "Visible"
|
||||
}
|
||||
if ($activeCategories -ne $null){
|
||||
if ($activeCategories){
|
||||
$inactiveCategories = Compare-Object -ReferenceObject $allCategories -DifferenceObject $activeCategories -PassThru
|
||||
foreach ($category in $inactiveCategories){
|
||||
$label = $labels["WPFLabel"+$($category -replace '[^a-zA-Z0-9]')]
|
||||
$label.Visibility = "Collapsed"}
|
||||
}
|
||||
|
||||
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