Files
winutil/functions/private/Find-AppsByNameOrDescription.ps1
T

81 lines
3.1 KiB
PowerShell
Raw Normal View History

2025-03-01 20:50:12 +01:00
function Find-AppsByNameOrDescription {
<#
.SYNOPSIS
Searches through the Apps on the Install Tab and hides all entries that do not match the string
.PARAMETER SearchString
The string to be searched for
#>
param(
[Parameter(Mandatory=$false)]
[string]$SearchString = ""
)
# Reset the visibility if the search string is empty or the search is cleared
if ([string]::IsNullOrWhiteSpace($SearchString)) {
2025-05-12 22:45:57 +02:00
$sync.ItemsControl.Items | ForEach-Object {
2026-02-06 10:26:29 -06:00
# Each item is a StackPanel container
2025-05-12 22:45:57 +02:00
$_.Visibility = [Windows.Visibility]::Visible
2026-02-06 10:26:29 -06:00
if ($_.Children.Count -ge 2) {
$categoryLabel = $_.Children[0]
$wrapPanel = $_.Children[1]
# Keep category label visible
$categoryLabel.Visibility = [Windows.Visibility]::Visible
# Respect the collapsed state of categories (indicated by + prefix)
if ($categoryLabel.Content -like "+*") {
$wrapPanel.Visibility = [Windows.Visibility]::Collapsed
} else {
$wrapPanel.Visibility = [Windows.Visibility]::Visible
2025-05-12 22:45:57 +02:00
}
2026-02-06 10:26:29 -06:00
# Show all apps within the category
$wrapPanel.Children | ForEach-Object {
$_.Visibility = [Windows.Visibility]::Visible
}
2025-05-12 22:45:57 +02:00
}
}
return
2025-03-01 20:50:12 +01:00
}
2026-02-06 10:26:29 -06:00
# Perform search
2025-03-01 20:50:12 +01:00
$sync.ItemsControl.Items | ForEach-Object {
2026-02-06 10:26:29 -06:00
# Each item is a StackPanel container with Children[0] = label, Children[1] = WrapPanel
if ($_.Children.Count -ge 2) {
$categoryLabel = $_.Children[0]
$wrapPanel = $_.Children[1]
$categoryHasMatch = $false
# Keep category label visible
$categoryLabel.Visibility = [Windows.Visibility]::Visible
# Search through apps in this category
$wrapPanel.Children | ForEach-Object {
$appEntry = $sync.configs.applicationsHashtable.$($_.Tag)
if ($appEntry.Content -like "*$SearchString*" -or $appEntry.Description -like "*$SearchString*") {
2026-02-06 10:26:29 -06:00
# Show the App and mark that this category has a match
2025-03-01 20:50:12 +01:00
$_.Visibility = [Windows.Visibility]::Visible
2026-02-06 10:26:29 -06:00
$categoryHasMatch = $true
2025-03-01 20:50:12 +01:00
}
else {
$_.Visibility = [Windows.Visibility]::Collapsed
}
}
2026-02-06 10:26:29 -06:00
# If category has matches, show the WrapPanel and update the category label to expanded state
if ($categoryHasMatch) {
$wrapPanel.Visibility = [Windows.Visibility]::Visible
$_.Visibility = [Windows.Visibility]::Visible
# Update category label to show expanded state (-)
if ($categoryLabel.Content -like "+*") {
$categoryLabel.Content = $categoryLabel.Content -replace "^\+ ", "- "
}
} else {
# Hide the entire category container if no matches
$_.Visibility = [Windows.Visibility]::Collapsed
}
2025-03-01 20:50:12 +01:00
}
}
}