mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-02-06 16:00:10 +00:00
Fix search
This commit is contained in:
@@ -13,46 +13,45 @@ function Find-AppsByNameOrDescription {
|
|||||||
# Reset the visibility if the search string is empty or the search is cleared
|
# Reset the visibility if the search string is empty or the search is cleared
|
||||||
if ([string]::IsNullOrWhiteSpace($SearchString)) {
|
if ([string]::IsNullOrWhiteSpace($SearchString)) {
|
||||||
$sync.ItemsControl.Items | ForEach-Object {
|
$sync.ItemsControl.Items | ForEach-Object {
|
||||||
|
# Each item is a StackPanel container
|
||||||
$_.Visibility = [Windows.Visibility]::Visible
|
$_.Visibility = [Windows.Visibility]::Visible
|
||||||
$_.Children | ForEach-Object {
|
|
||||||
if ($null -ne $_) {
|
if ($_.Children.Count -ge 2) {
|
||||||
# Respect the collapsed state of categories (indicated by + prefix)
|
$categoryLabel = $_.Children[0]
|
||||||
if ($_.Tag -like "CategoryToggleButton" -and $_.Content -like "+*") {
|
$wrapPanel = $_.Children[1]
|
||||||
# Keep category label visible but don't expand the WrapPanel
|
|
||||||
$_.Visibility = [Windows.Visibility]::Visible
|
# Keep category label visible
|
||||||
}
|
$categoryLabel.Visibility = [Windows.Visibility]::Visible
|
||||||
elseif ($_.Tag -like "CategoryWrapPanel_*") {
|
|
||||||
# Check if parent category is collapsed (has + prefix)
|
# Respect the collapsed state of categories (indicated by + prefix)
|
||||||
$categoryLabel = $_.Parent.Children[0]
|
if ($categoryLabel.Content -like "+*") {
|
||||||
if ($categoryLabel.Content -like "+*") {
|
$wrapPanel.Visibility = [Windows.Visibility]::Collapsed
|
||||||
# Keep collapsed
|
} else {
|
||||||
$_.Visibility = [Windows.Visibility]::Collapsed
|
$wrapPanel.Visibility = [Windows.Visibility]::Visible
|
||||||
} else {
|
|
||||||
# Expand
|
|
||||||
$_.Visibility = [Windows.Visibility]::Visible
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$_.Visibility = [Windows.Visibility]::Visible
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Show all apps within the category
|
||||||
|
$wrapPanel.Children | ForEach-Object {
|
||||||
|
$_.Visibility = [Windows.Visibility]::Visible
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Perform search
|
||||||
$sync.ItemsControl.Items | ForEach-Object {
|
$sync.ItemsControl.Items | ForEach-Object {
|
||||||
# Ensure ToggleButtons remain visible
|
# Each item is a StackPanel container with Children[0] = label, Children[1] = WrapPanel
|
||||||
if ($_.Tag -like "CategoryToggleButton") {
|
if ($_.Children.Count -ge 2) {
|
||||||
$_.Visibility = [Windows.Visibility]::Visible
|
$categoryLabel = $_.Children[0]
|
||||||
return
|
$wrapPanel = $_.Children[1]
|
||||||
}
|
|
||||||
# Hide all CategoryWrapPanel and ToggleButton
|
|
||||||
$_.Visibility = [Windows.Visibility]::Collapsed
|
|
||||||
if ($_.Tag -like "CategoryWrapPanel_*") {
|
|
||||||
$categoryHasMatch = $false
|
$categoryHasMatch = $false
|
||||||
# Search for Apps that match the search string
|
|
||||||
$_.Children | Foreach-Object {
|
# Keep category label visible
|
||||||
|
$categoryLabel.Visibility = [Windows.Visibility]::Visible
|
||||||
|
|
||||||
|
# Search through apps in this category
|
||||||
|
$wrapPanel.Children | ForEach-Object {
|
||||||
$appEntry = $sync.configs.applicationsHashtable.$($_.Tag)
|
$appEntry = $sync.configs.applicationsHashtable.$($_.Tag)
|
||||||
if ($appEntry.Content -like "*$SearchString*" -or $appEntry.Description -like "*$SearchString*") {
|
if ($appEntry.Content -like "*$SearchString*" -or $appEntry.Description -like "*$SearchString*") {
|
||||||
# Show the App and mark that this category has a match
|
# Show the App and mark that this category has a match
|
||||||
@@ -66,12 +65,15 @@ function Find-AppsByNameOrDescription {
|
|||||||
|
|
||||||
# If category has matches, show the WrapPanel and update the category label to expanded state
|
# If category has matches, show the WrapPanel and update the category label to expanded state
|
||||||
if ($categoryHasMatch) {
|
if ($categoryHasMatch) {
|
||||||
|
$wrapPanel.Visibility = [Windows.Visibility]::Visible
|
||||||
$_.Visibility = [Windows.Visibility]::Visible
|
$_.Visibility = [Windows.Visibility]::Visible
|
||||||
# Update category label to show expanded state (-)
|
# Update category label to show expanded state (-)
|
||||||
$categoryLabel = $_.Parent.Children[0]
|
|
||||||
if ($categoryLabel.Content -like "+*") {
|
if ($categoryLabel.Content -like "+*") {
|
||||||
$categoryLabel.Content = $categoryLabel.Content -replace "^\+ ", "- "
|
$categoryLabel.Content = $categoryLabel.Content -replace "^\+ ", "- "
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
# Hide the entire category container if no matches
|
||||||
|
$_.Visibility = [Windows.Visibility]::Collapsed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user