mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-05-24 00:07:24 -05:00
parent
14943e3c55
commit
b8b16be24b
104
functions/private/Find-TweaksByNameOrDescription.ps1
Normal file
104
functions/private/Find-TweaksByNameOrDescription.ps1
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
function Find-TweaksByNameOrDescription {
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Searches through the Tweaks on the Tweaks Tab and hides all entries that do not match the search 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)) {
|
||||||
|
# Show all categories
|
||||||
|
$tweakspanel = $sync.Form.FindName("tweakspanel")
|
||||||
|
$tweakspanel.Children | ForEach-Object {
|
||||||
|
$_.Visibility = [Windows.Visibility]::Visible
|
||||||
|
|
||||||
|
# Foreach category section, show all items
|
||||||
|
if ($_ -is [Windows.Controls.Border]) {
|
||||||
|
$_.Visibility = [Windows.Visibility]::Visible
|
||||||
|
|
||||||
|
# Find ItemsControl
|
||||||
|
$dockPanel = $_.Child
|
||||||
|
if ($dockPanel -is [Windows.Controls.DockPanel]) {
|
||||||
|
$itemsControl = $dockPanel.Children | Where-Object { $_ -is [Windows.Controls.ItemsControl] }
|
||||||
|
if ($itemsControl) {
|
||||||
|
# Show items in the category
|
||||||
|
foreach ($item in $itemsControl.Items) {
|
||||||
|
if ($item -is [Windows.Controls.Label]) {
|
||||||
|
$item.Visibility = [Windows.Visibility]::Visible
|
||||||
|
} elseif ($item -is [Windows.Controls.DockPanel] -or
|
||||||
|
$item -is [Windows.Controls.StackPanel]) {
|
||||||
|
$item.Visibility = [Windows.Visibility]::Visible
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# Search for matching tweaks when search string is not null
|
||||||
|
$tweakspanel = $sync.Form.FindName("tweakspanel")
|
||||||
|
$matchFound = $false
|
||||||
|
|
||||||
|
$tweakspanel.Children | ForEach-Object {
|
||||||
|
$categoryBorder = $_
|
||||||
|
$categoryVisible = $false
|
||||||
|
|
||||||
|
if ($_ -is [Windows.Controls.Border]) {
|
||||||
|
# Find the ItemsControl
|
||||||
|
$dockPanel = $_.Child
|
||||||
|
if ($dockPanel -is [Windows.Controls.DockPanel]) {
|
||||||
|
$itemsControl = $dockPanel.Children | Where-Object { $_ -is [Windows.Controls.ItemsControl] }
|
||||||
|
if ($itemsControl) {
|
||||||
|
$categoryLabel = $null
|
||||||
|
|
||||||
|
# Process all items in the ItemsControl
|
||||||
|
for ($i = 0; $i -lt $itemsControl.Items.Count; $i++) {
|
||||||
|
$item = $itemsControl.Items[$i]
|
||||||
|
|
||||||
|
if ($item -is [Windows.Controls.Label]) {
|
||||||
|
$categoryLabel = $item
|
||||||
|
$item.Visibility = [Windows.Visibility]::Collapsed
|
||||||
|
} elseif ($item -is [Windows.Controls.DockPanel]) {
|
||||||
|
$checkbox = $item.Children | Where-Object { $_ -is [Windows.Controls.CheckBox] } | Select-Object -First 1
|
||||||
|
$label = $item.Children | Where-Object { $_ -is [Windows.Controls.Label] } | Select-Object -First 1
|
||||||
|
|
||||||
|
if ($label -and ($label.Content -like "*$SearchString*" -or $label.ToolTip -like "*$SearchString*")) {
|
||||||
|
$item.Visibility = [Windows.Visibility]::Visible
|
||||||
|
if ($categoryLabel) { $categoryLabel.Visibility = [Windows.Visibility]::Visible }
|
||||||
|
$categoryVisible = $true
|
||||||
|
} else {
|
||||||
|
$item.Visibility = [Windows.Visibility]::Collapsed
|
||||||
|
}
|
||||||
|
} elseif ($item -is [Windows.Controls.StackPanel]) {
|
||||||
|
# StackPanel which contain checkboxes or other elements
|
||||||
|
$checkbox = $item.Children | Where-Object { $_ -is [Windows.Controls.CheckBox] } | Select-Object -First 1
|
||||||
|
|
||||||
|
if ($checkbox -and ($checkbox.Content -like "*$SearchString*" -or $checkbox.ToolTip -like "*$SearchString*")) {
|
||||||
|
$item.Visibility = [Windows.Visibility]::Visible
|
||||||
|
if ($categoryLabel) { $categoryLabel.Visibility = [Windows.Visibility]::Visible }
|
||||||
|
$categoryVisible = $true
|
||||||
|
} else {
|
||||||
|
$item.Visibility = [Windows.Visibility]::Collapsed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set the visibility based on if any item matched
|
||||||
|
$categoryBorder.Visibility = if ($categoryVisible) { [Windows.Visibility]::Visible } else { [Windows.Visibility]::Collapsed }
|
||||||
|
|
||||||
|
if ($categoryVisible) {
|
||||||
|
$matchFound = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -29,4 +29,30 @@ function Invoke-WPFTab {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sync.currentTab = $sync.$tabNav.Items[$tabNumber].Header
|
$sync.currentTab = $sync.$tabNav.Items[$tabNumber].Header
|
||||||
|
|
||||||
|
# Always reset the filter for the current tab
|
||||||
|
if ($sync.currentTab -eq "Install") {
|
||||||
|
# Reset Install tab filter
|
||||||
|
Find-AppsByNameOrDescription -SearchString ""
|
||||||
|
} elseif ($sync.currentTab -eq "Tweaks") {
|
||||||
|
# Reset Tweaks tab filter
|
||||||
|
Find-TweaksByNameOrDescription -SearchString ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# Show search bar in Install and Tweaks tabs
|
||||||
|
if ($tabNumber -eq 0 -or $tabNumber -eq 1) {
|
||||||
|
$sync.SearchBar.Visibility = "Visible"
|
||||||
|
$searchIcon = ($sync.Form.FindName("SearchBar").Parent.Children | Where-Object { $_ -is [System.Windows.Controls.TextBlock] -and $_.Text -eq [char]0xE721 })[0]
|
||||||
|
if ($searchIcon) {
|
||||||
|
$searchIcon.Visibility = "Visible"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$sync.SearchBar.Visibility = "Collapsed"
|
||||||
|
$searchIcon = ($sync.Form.FindName("SearchBar").Parent.Children | Where-Object { $_ -is [System.Windows.Controls.TextBlock] -and $_.Text -eq [char]0xE721 })[0]
|
||||||
|
if ($searchIcon) {
|
||||||
|
$searchIcon.Visibility = "Collapsed"
|
||||||
|
}
|
||||||
|
# Hide the clear button if it's visible
|
||||||
|
$sync.SearchBarClearButton.Visibility = "Collapsed"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,6 +267,10 @@ $sync["Form"].Add_Closing({
|
|||||||
$sync.SearchBarClearButton.Add_Click({
|
$sync.SearchBarClearButton.Add_Click({
|
||||||
$sync.SearchBar.Text = ""
|
$sync.SearchBar.Text = ""
|
||||||
$sync.SearchBarClearButton.Visibility = "Collapsed"
|
$sync.SearchBarClearButton.Visibility = "Collapsed"
|
||||||
|
|
||||||
|
# Focus the search bar after clearing the text
|
||||||
|
$sync.SearchBar.Focus()
|
||||||
|
$sync.SearchBar.SelectAll()
|
||||||
})
|
})
|
||||||
|
|
||||||
# add some shortcuts for people that don't like clicking
|
# add some shortcuts for people that don't like clicking
|
||||||
@ -427,6 +431,9 @@ $sync["SearchBar"].Add_TextChanged({
|
|||||||
"Install" {
|
"Install" {
|
||||||
Find-AppsByNameOrDescription -SearchString $sync.SearchBar.Text
|
Find-AppsByNameOrDescription -SearchString $sync.SearchBar.Text
|
||||||
}
|
}
|
||||||
|
"Tweaks" {
|
||||||
|
Find-TweaksByNameOrDescription -SearchString $sync.SearchBar.Text
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user