Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/src/content/docs/guides/application.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Use the Applications tab to install, upgrade, uninstall, and review supported ap

![Collapse or expand all categories](../../../assets/screenshots/install-pics/Collapse&ExpandCat.png)
</TabItem>
<TabItem label="Category Filters">
* Click a category chip at the top of the tab to show only that category. The chip stays highlighted while its filter is active.
* Hold `Ctrl` and click to add more categories to the filter, or to remove one again.
* Click `All`, or click the highlighted category again while it is the only one selected, to clear the filter.
* Categories with matching results open while a filter is active. Ones that filtering opened for you go back to collapsed when you clear it, ones you opened yourself stay open.
</TabItem>
<TabItem label="Selected Apps Counter">
* The `Selected Apps` counter in the sidebar shows how many applications are currently selected.
* Use it to keep track of your selection as you browse categories.
Expand All @@ -57,7 +63,7 @@ Use the Applications tab to install, upgrade, uninstall, and review supported ap
</Tabs>

:::tip
If you have trouble finding an application, press `Ctrl + F` and search for its name. The list filters as you type.
If you have trouble finding an application, press `Ctrl + F` and search for its name. The list filters as you type. The search and the category chips work together, so you can search inside the categories you picked.
:::

:::note
Expand Down
66 changes: 39 additions & 27 deletions functions/private/Find-AppsByNameOrDescription.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
function Find-AppsByNameOrDescription {
<#
.SYNOPSIS
Searches through the Apps on the Install Tab and hides all entries that do not match the string
Filters the Install tab entries by search text and by category

.DESCRIPTION
Filters application entries by name or description using literal string matching.
Respects collapsed category state and handles null $sync gracefully.
Search text and categories are independent filters that both have to pass. An entry is
shown when its name or description matches the search text, and when its category is in
the selected set. An empty search matches everything, and an empty category set matches
every category.

While either filter is active the matching categories are expanded, since a collapsed
category would otherwise hide the very results that were asked for. With no filter at
all the collapsed state the user set is restored.

.PARAMETER SearchString
The string to be searched for. Wildcards are treated as literal characters.
The string to search for. Wildcards are treated as literal characters.

.PARAMETER Category
When provided, only applications in this exact category are shown.
.PARAMETER Categories
The categories to show. An empty or missing array shows all of them.

.NOTES
- Uses module-scope $sync (no parameter needed; inherits from caller's scope)
- Performs literal matching (no wildcard expansion)
- Safely handles missing hashtable keys and null UI elements
- Protected by try/catch to prevent UI thread crashes
#>
Expand All @@ -24,7 +29,7 @@ function Find-AppsByNameOrDescription {
[string]$SearchString = "",

[Parameter(Mandatory = $false)]
[string]$Category = ""
[string[]]$Categories = @()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
MyDrift-user marked this conversation as resolved.
)

# Validate that $sync exists and has required structure
Expand All @@ -43,29 +48,41 @@ function Find-AppsByNameOrDescription {
return
}

# Categories that filtering expanded on the user's behalf, so clearing the filter can undo it
if ($null -eq $sync.AppCategoryAutoExpanded) {
$sync.AppCategoryAutoExpanded = @{}
}

try {
# Reset the visibility if the search string is empty or the search is cleared
if ([string]::IsNullOrWhiteSpace($SearchString) -and [string]::IsNullOrWhiteSpace($Category)) {
$activeCategories = @($Categories | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
$hasSearch = -not [string]::IsNullOrWhiteSpace($SearchString)
$hasCategories = $activeCategories.Count -gt 0

# Nothing is filtered, so put every entry back and leave the collapsed categories collapsed
if (-not $hasSearch -and -not $hasCategories) {
$sync.ItemsControl.Items | ForEach-Object {
# Each item is a StackPanel container
$_.Visibility = [Windows.Visibility]::Visible

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)
# A category that filtering expanded goes back to how the user left it
$categoryName = $categoryLabel.Content -replace '^[+-] ', ''
if ($sync.AppCategoryAutoExpanded.ContainsKey($categoryName)) {
$categoryLabel.Content = $categoryLabel.Content -replace "^- ", "+ "
$sync.AppCategoryAutoExpanded.Remove($categoryName)
}

if ($categoryLabel.Content -like "+*") {
$wrapPanel.Visibility = [Windows.Visibility]::Collapsed
}
else {
$wrapPanel.Visibility = [Windows.Visibility]::Visible
}

# Show all apps within the category
$wrapPanel.Children | ForEach-Object {
$_.Visibility = [Windows.Visibility]::Visible
}
Expand All @@ -77,35 +94,30 @@ function Find-AppsByNameOrDescription {
# Escape wildcard characters for literal matching
$escapedSearchString = [System.Management.Automation.WildcardPattern]::Escape($SearchString)

# Perform search
$sync.ItemsControl.Items | ForEach-Object {
# 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
foreach ($appControl in $wrapPanel.Children) {
# Safely retrieve app entry from hashtable
$appTag = $appControl.Tag
$appEntry = $null

if (-not [string]::IsNullOrWhiteSpace($appTag) -and $sync.configs.applicationsHashtable.ContainsKey($appTag)) {
$appEntry = $sync.configs.applicationsHashtable[$appTag]
}

# Check if app matches search criteria
if ($null -ne $appEntry) {
$categoryMatch = -not [string]::IsNullOrWhiteSpace($Category) -and $appEntry.Category -eq $Category
$contentMatch = [string]::IsNullOrWhiteSpace($Category) -and $appEntry.Content -like "*$escapedSearchString*"
$descriptionMatch = [string]::IsNullOrWhiteSpace($Category) -and $appEntry.Description -like "*$escapedSearchString*"
$categoryMatch = -not $hasCategories -or $activeCategories -contains $appEntry.Category
$textMatch = -not $hasSearch -or
$appEntry.Content -like "*$escapedSearchString*" -or
$appEntry.Description -like "*$escapedSearchString*"

if ($categoryMatch -or $contentMatch -or $descriptionMatch) {
# Show the App and mark that this category has a match
if ($categoryMatch -and $textMatch) {
$appControl.Visibility = [Windows.Visibility]::Visible
$categoryHasMatch = $true
}
Expand All @@ -119,17 +131,17 @@ function Find-AppsByNameOrDescription {
}
}

# 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 (-)
# Expand it, otherwise the matches stay hidden behind a collapsed header.
# Remember that it was collapsed so clearing the filter can put it back.
if ($categoryLabel.Content -like "+*") {
$categoryLabel.Content = $categoryLabel.Content -replace "^\+ ", "- "
$sync.AppCategoryAutoExpanded[($categoryLabel.Content -replace '^- ', '')] = $true
}
}
else {
# Hide the entire category container if no matches
$_.Visibility = [Windows.Visibility]::Collapsed
}
}
Expand Down
5 changes: 5 additions & 0 deletions functions/private/Initialize-InstallCategoryAppList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ function Initialize-InstallCategoryAppList {
# The WrapPanel is the second child
$wrapPanel = $categoryContainer.Children[1]

# An explicit click wins over anything filtering expanded automatically
if ($sync.AppCategoryAutoExpanded) {
$sync.AppCategoryAutoExpanded.Remove(($categoryToggle.Content -replace '^[+-] ', ''))
}

# Toggle visibility
if ($wrapPanel.Visibility -eq [Windows.Visibility]::Visible) {
$wrapPanel.Visibility = [Windows.Visibility]::Collapsed
Expand Down
20 changes: 20 additions & 0 deletions functions/private/Invoke-WinUtilAppCategoryChip.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function Invoke-WinUtilAppCategoryChip {
<#
.SYNOPSIS
Handles a click on an Install tab category chip

.DESCRIPTION
The chip carries its category in Tag, so every chip shares this handler. Holding ctrl
adds the category to the current selection instead of replacing it.

.PARAMETER Chip
The chip that was clicked
#>
param(
[Parameter(Mandatory)]
$Chip
)

$ctrlDown = [bool]([System.Windows.Input.Keyboard]::Modifiers -band [System.Windows.Input.ModifierKeys]::Control)
Set-WinUtilAppCategoryFilter -Category $Chip.Tag -Additive:$ctrlDown
}
45 changes: 39 additions & 6 deletions functions/private/Set-WinUtilAppCategoryFilter.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
function Set-WinUtilAppCategoryFilter {
<#
.SYNOPSIS
Applies an exact application category filter from an Install tab search chip.
Applies the Install tab category filter and syncs the chip states to it

.DESCRIPTION
The selection lives in $sync.SelectedAppCategories. An empty selection means every
category is shown, which is what the All chip represents. The category filter and the
search box are independent: this only touches categories, and the current search text
is reapplied on top.

.PARAMETER Category
The application category to show. An empty value clears the filter.
The category to act on. An empty value clears the filter back to All.

.PARAMETER Additive
Toggles this category in or out of the current selection instead of replacing it.
Bound to ctrl click.
#>
param(
[Parameter(Mandatory = $false)]
[string]$Category = ""
[string]$Category = "",

[Parameter(Mandatory = $false)]
[switch]$Additive
)

$sync.SearchBar.Tag = $Category
$sync.SearchBar.Text = $Category
Find-AppsByNameOrDescription -SearchString $Category -Category $Category
if ($null -eq $sync.SelectedAppCategories) {
$sync.SelectedAppCategories = [System.Collections.Generic.List[string]]::new()
}
$selected = $sync.SelectedAppCategories

if ([string]::IsNullOrWhiteSpace($Category)) {
$selected.Clear()
} elseif ($Additive) {
if ($selected.Contains($Category)) {
[void]$selected.Remove($Category)
} else {
$selected.Add($Category)
}
} elseif ($selected.Count -eq 1 -and $selected.Contains($Category)) {
# Clicking the only active category again clears the filter
$selected.Clear()
} else {
$selected.Clear()
$selected.Add($Category)
}

Update-WinUtilAppCategoryChip
Find-AppsByNameOrDescription -SearchString $sync.SearchBar.Text -Categories $selected.ToArray()
}
10 changes: 8 additions & 2 deletions functions/private/Start-WinUtilInstallAppRendering.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ function Invoke-WinUtilInstallAppRenderBatch {
$sync.$appKey = Initialize-InstallAppEntry -TargetElement $CategoryBatch.TargetElement -AppKey $appKey
}

if ($sync.currentTab -eq "Install" -and $sync.SearchBar -and -not [string]::IsNullOrWhiteSpace($sync.SearchBar.Text)) {
Find-AppsByNameOrDescription -SearchString $sync.SearchBar.Text -Category $sync.SearchBar.Tag
# Entries render in batches, so a filter that is already active has to be applied to each new
# batch. Categories count as an active filter just like search text does.
if ($sync.currentTab -eq "Install" -and $sync.SearchBar) {
$selectedCategories = if ($sync.SelectedAppCategories) { $sync.SelectedAppCategories.ToArray() } else { @() }

if (-not [string]::IsNullOrWhiteSpace($sync.SearchBar.Text) -or $selectedCategories.Count -gt 0) {
Find-AppsByNameOrDescription -SearchString $sync.SearchBar.Text -Categories $selectedCategories
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions functions/private/Update-WinUtilAppCategoryChip.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function Update-WinUtilAppCategoryChip {
<#
.SYNOPSIS
Pushes the current category selection onto the Install tab filter chips

.DESCRIPTION
The chips are toggle buttons, so their checked state has to follow the selection
rather than whatever the last click did to them. The All chip is checked when no
category is selected.
#>
$selected = $sync.SelectedAppCategories
if ($null -eq $selected) { return }

foreach ($chip in $sync.AppCategoryChips) {
$control = $sync[$chip.Name]
if ($null -eq $control) { continue }
$control.IsChecked = if ($chip.Category) { $selected.Contains($chip.Category) } else { $selected.Count -eq 0 }
}
}
5 changes: 3 additions & 2 deletions functions/public/Invoke-WPFTab.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ function Invoke-WPFTab {

# Always reset the filter for the current tab
if ($sync.currentTab -eq "Install") {
# Reset Install tab filter
Find-AppsByNameOrDescription -SearchString ""
# Reset the search text, but keep the categories the chips are still showing as selected
$selectedCategories = if ($sync.SelectedAppCategories) { $sync.SelectedAppCategories.ToArray() } else { @() }
Find-AppsByNameOrDescription -SearchString "" -Categories $selectedCategories
Comment thread
coderabbitai[bot] marked this conversation as resolved.
} elseif ($sync.currentTab -eq "Tweaks") {
# Reset Tweaks tab filter
Find-TweaksByNameOrDescription -SearchString ""
Expand Down
4 changes: 3 additions & 1 deletion pester/install-rendering.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Describe "Install app rendering startup contract" {
$renderScript | Should -Match 'Dispatcher\.BeginInvoke'
$renderScript | Should -Match 'Invoke-WinUtilInstallAppRenderNextBatch'
$renderScript | Should -Match 'Initialize-InstallAppEntry'
$renderScript | Should -Match 'Find-AppsByNameOrDescription -SearchString \$sync\.SearchBar\.Text -Category \$sync\.SearchBar\.Tag'
$renderScript | Should -Match 'Find-AppsByNameOrDescription -SearchString \$sync\.SearchBar\.Text -Categories \$selectedCategories'
# A batch has to be filtered when either filter is on, not only when there is search text
$renderScript | Should -Match '\$selectedCategories\.Count -gt 0'
$renderScript | Should -Match '\$sync\.InstallAppEntriesRendered = \$true'
}

Expand Down
Loading
Loading