mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 22:55:52 -06:00
Keep the search status when switching between compact and full view
This commit is contained in:
parent
80a933db8e
commit
4bfeacf80d
@ -1,23 +1,4 @@
|
|||||||
function Collapse-AllCategories {
|
function Set-CategoryVisibility {
|
||||||
param(
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[System.Windows.Controls.ItemsControl]$ItemsControl
|
|
||||||
)
|
|
||||||
$sync.Buttons | Where-Object {$_.Tag -like "CategoryToggleButton"} | ForEach-Object {
|
|
||||||
$_.IsChecked = $false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function Expand-AllCategories {
|
|
||||||
param(
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[System.Windows.Controls.ItemsControl]$ItemsControl
|
|
||||||
)
|
|
||||||
$sync.Buttons | Where-Object {$_.Tag -like "CategoryToggleButton"} | ForEach-Object {
|
|
||||||
$_.IsChecked = $true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function Toggle-CategoryVisibility {
|
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$Category,
|
[string]$Category,
|
||||||
@ -26,9 +7,14 @@ function Toggle-CategoryVisibility {
|
|||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[bool]$isChecked
|
[bool]$isChecked
|
||||||
)
|
)
|
||||||
# Show or hide the category, based on if it was clicked or not
|
# Show or hide the category, based on if it was clicked or not
|
||||||
$ItemsControl.Items | Where-Object {($_.Tag -eq "CategoryWrapPanel_$Category")} | ForEach-Object {
|
if ($category -eq "*"){
|
||||||
$_.Visibility = if ($isChecked) {
|
$items = $ItemsControl.Items | Where-Object {($_.Tag -like "CategoryWrapPanel_*")}
|
||||||
|
} else {
|
||||||
|
$items = $ItemsControl.Items | Where-Object {($_.Tag -eq "CategoryWrapPanel_$Category")}
|
||||||
|
}
|
||||||
|
$items | ForEach-Object {
|
||||||
|
$_.Visibility = if ($isChecked -eq $true) {
|
||||||
[Windows.Visibility]::Visible
|
[Windows.Visibility]::Visible
|
||||||
} else {
|
} else {
|
||||||
[Windows.Visibility]::Collapsed
|
[Windows.Visibility]::Collapsed
|
||||||
@ -36,7 +22,7 @@ function Toggle-CategoryVisibility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Search-AppsByNameOrDescription {
|
function Find-AppsByNameOrDescription {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
[string]$SearchString = "",
|
[string]$SearchString = "",
|
||||||
@ -45,15 +31,21 @@ function Search-AppsByNameOrDescription {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if ([string]::IsNullOrWhiteSpace($SearchString)) {
|
if ([string]::IsNullOrWhiteSpace($SearchString)) {
|
||||||
# Reset all categories when a search is cleared
|
if ($sync.CompactView -eq $true) {
|
||||||
$sync.Buttons | Where-Object {$_.Tag -like "CategoryToggleButton"} | ForEach-Object {
|
Set-CategoryVisibility -Category "*" -ItemsControl $ItemsControl -isChecked $true
|
||||||
$_.IsChecked = $false
|
} else {
|
||||||
|
Set-CategoryVisibility -Category "*" -ItemsControl $ItemsControl -isChecked $false
|
||||||
}
|
}
|
||||||
|
|
||||||
$ItemsControl.Items | ForEach-Object {
|
$ItemsControl.Items | ForEach-Object {
|
||||||
if ($_.Tag -like "CategoryWrapPanel_*") {
|
if ($_.Tag -like "CategoryWrapPanel_*") {
|
||||||
# Reset CategoryWrapPanel visibility
|
# If CompactView is enabled, show all Apps when the search bar is empty
|
||||||
$_.Visibility = [Windows.Visibility]::Collapsed
|
# otherwise, hide all Apps
|
||||||
|
if ($sync.CompactView -eq $true) {
|
||||||
|
$_.Visibility = [Windows.Visibility]::Visible
|
||||||
|
} else {
|
||||||
|
$_.Visibility = [Windows.Visibility]::Collapsed
|
||||||
|
}
|
||||||
# Reset Items visibility
|
# Reset Items visibility
|
||||||
$_.Children | ForEach-Object {$_.Visibility = [Windows.Visibility]::Visible}
|
$_.Children | ForEach-Object {$_.Visibility = [Windows.Visibility]::Visible}
|
||||||
}
|
}
|
||||||
@ -231,14 +223,18 @@ function Invoke-WPFUIApps {
|
|||||||
$compactViewButton.Add_Click({
|
$compactViewButton.Add_Click({
|
||||||
$sync.CompactView = -not $sync.CompactView
|
$sync.CompactView = -not $sync.CompactView
|
||||||
Update-AppTileProperties
|
Update-AppTileProperties
|
||||||
if ($sync.CompactView) {
|
if ($sync.CompactView -eq $true) {
|
||||||
Expand-AllCategories -ItemsControl $sync.ItemsControl
|
if ($sync.SearchBar.Text -eq "") {
|
||||||
|
Set-CategoryVisibility -Category "*" -ItemsControl $sync.ItemsControl -isChecked $true
|
||||||
|
}
|
||||||
$this.Content = "Expanded View"
|
$this.Content = "Expanded View"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Collapse-AllCategories -ItemsControl $sync.ItemsControl
|
if ($sync.SearchBar.Text -eq "") {
|
||||||
|
Set-CategoryVisibility -Category "*" -ItemsControl $sync.ItemsControl -isChecked $false
|
||||||
|
}
|
||||||
$this.Content = "Compact View"
|
$this.Content = "Compact View"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
$null = $wrapPanelTop.Children.Add($compactViewButton)
|
$null = $wrapPanelTop.Children.Add($compactViewButton)
|
||||||
[Windows.Controls.DockPanel]::SetDock($wrapPanelTop, [Windows.Controls.Dock]::Top)
|
[Windows.Controls.DockPanel]::SetDock($wrapPanelTop, [Windows.Controls.Dock]::Top)
|
||||||
@ -288,10 +284,10 @@ function Invoke-WPFUIApps {
|
|||||||
$toggleButton.Add_Checked({
|
$toggleButton.Add_Checked({
|
||||||
# Clear the search bar when a category is clicked
|
# Clear the search bar when a category is clicked
|
||||||
$sync.SearchBar.Text = ""
|
$sync.SearchBar.Text = ""
|
||||||
Toggle-CategoryVisibility -Category $this.Content -ItemsControl $this.Parent -isChecked $this.IsChecked
|
Set-CategoryVisibility -Category $this.Content -ItemsControl $this.Parent -isChecked $true
|
||||||
})
|
})
|
||||||
$toggleButton.Add_Unchecked({
|
$toggleButton.Add_Unchecked({
|
||||||
Toggle-CategoryVisibility -Category $this.Content -ItemsControl $this.Parent -isChecked $this.IsChecked
|
Set-CategoryVisibility -Category $this.Content -ItemsControl $this.Parent -isChecked $false
|
||||||
})
|
})
|
||||||
$null = $ItemsControl.Items.Add($toggleButton)
|
$null = $ItemsControl.Items.Add($toggleButton)
|
||||||
}
|
}
|
||||||
|
@ -470,7 +470,7 @@ $sync["SearchBar"].Add_TextChanged({
|
|||||||
}
|
}
|
||||||
switch ($sync.currentTab) {
|
switch ($sync.currentTab) {
|
||||||
"Install" {
|
"Install" {
|
||||||
Search-AppsByNameOrDescription -SearchString $sync.SearchBar.Text
|
Find-AppsByNameOrDescription -SearchString $sync.SearchBar.Text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user