Fix weird buggy behaviour in regards to switching the Display Mode and using Show-SelectedOnly

This commit is contained in:
Marterich 2024-10-21 22:35:00 +02:00
parent 4bfeacf80d
commit e048097c78

View File

@ -4,21 +4,28 @@ function Set-CategoryVisibility {
[string]$Category, [string]$Category,
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[System.Windows.Controls.ItemsControl]$ItemsControl, [System.Windows.Controls.ItemsControl]$ItemsControl,
[Parameter(Mandatory=$true)] [bool]$isChecked = $true,
[bool]$isChecked [switch]$automaticVisibility
) )
# Show or hide the category, based on if it was clicked or not if ($automaticVisibility) {
$isChecked = $sync.CompactView
}
# If all the Categories are affected, update the Checked state of the ToggleButtons.
# Otherwise, the state is not synced when toggling between the display modes
if ($category -eq "*"){ if ($category -eq "*"){
$items = $ItemsControl.Items | Where-Object {($_.Tag -like "CategoryWrapPanel_*")} $items = $ItemsControl.Items | Where-Object {($_.Tag -like "CategoryWrapPanel_*")}
$ItemsControl.Items | Where-Object {($_.Tag -eq "CategoryToggleButton")} | Foreach-Object { $_.Visibility = [Windows.Visibility]::Visible; $_.IsChecked = $isChecked }
} else { } else {
$items = $ItemsControl.Items | Where-Object {($_.Tag -eq "CategoryWrapPanel_$Category")} $items = $ItemsControl.Items | Where-Object {($_.Tag -eq "CategoryWrapPanel_$Category")}
} }
$elementVisibility = if ($isChecked -eq $true) {[Windows.Visibility]::Visible} else {[Windows.Visibility]::Collapsed}
$items | ForEach-Object { $items | ForEach-Object {
$_.Visibility = if ($isChecked -eq $true) { $_.Visibility = $elementVisibility
[Windows.Visibility]::Visible
} else {
[Windows.Visibility]::Collapsed
} }
$items.Children | ForEach-Object {
$_.Visibility = $elementVisibility
} }
} }
@ -31,11 +38,8 @@ function Find-AppsByNameOrDescription {
) )
if ([string]::IsNullOrWhiteSpace($SearchString)) { if ([string]::IsNullOrWhiteSpace($SearchString)) {
if ($sync.CompactView -eq $true) { Set-CategoryVisibility -Category "*" -ItemsControl $ItemsControl -automaticVisibility
Set-CategoryVisibility -Category "*" -ItemsControl $ItemsControl -isChecked $true
} else {
Set-CategoryVisibility -Category "*" -ItemsControl $ItemsControl -isChecked $false
}
$ItemsControl.Items | ForEach-Object { $ItemsControl.Items | ForEach-Object {
if ($_.Tag -like "CategoryWrapPanel_*") { if ($_.Tag -like "CategoryWrapPanel_*") {
@ -54,8 +58,7 @@ function Find-AppsByNameOrDescription {
$_.Visibility = [Windows.Visibility]::Visible $_.Visibility = [Windows.Visibility]::Visible
} }
} }
} } else {
else {
$ItemsControl.Items | ForEach-Object { $ItemsControl.Items | ForEach-Object {
# Hide all CategoryWrapPanel and ToggleButton # Hide all CategoryWrapPanel and ToggleButton
$_.Visibility = [Windows.Visibility]::Collapsed $_.Visibility = [Windows.Visibility]::Collapsed
@ -85,6 +88,7 @@ function Show-OnlyCheckedApps {
) )
# If no apps are selected, do not allow switching to show only selected # If no apps are selected, do not allow switching to show only selected
if (($false -eq $sync.ShowOnlySelected) -and ($appKeys.Count -eq 0)) { if (($false -eq $sync.ShowOnlySelected) -and ($appKeys.Count -eq 0)) {
Write-Host "No apps selected"
return return
} }
$sync.ShowOnlySelected = -not $sync.ShowOnlySelected $sync.ShowOnlySelected = -not $sync.ShowOnlySelected
@ -116,24 +120,10 @@ function Show-OnlyCheckedApps {
$sync.Buttons | Where-Object {$_.Name -like "ShowSelectedAppsButton"} | ForEach-Object { $sync.Buttons | Where-Object {$_.Name -like "ShowSelectedAppsButton"} | ForEach-Object {
$_.Content = "Show Selected" $_.Content = "Show Selected"
} }
# Reset all CategoryToggleButtons to unchecked Set-CategoryVisibility -Category "*" -ItemsControl $ItemsControl -automaticVisibility
$sync.Buttons | Where-Object {$_.Tag -like "CategoryToggleButton"} | ForEach-Object {
$_.IsChecked = $false
}
$ItemsControl.Items | Foreach-Object {
# Reset App Containers to visible
if ($_.Tag -like "CategoryWrapPanel_*") {
$_.Visibility = [Windows.Visibility]::Collapsed
# Reset Apps to visible
$_.Children | ForEach-Object {$_.Visibility = [Windows.Visibility]::Visible}
}
else {
# Reset all other items to visible
$_.Visibility = [Windows.Visibility]::Visible
}
}
}
} }
}
function Invoke-WPFUIApps { function Invoke-WPFUIApps {
[OutputType([void])] [OutputType([void])]
param( param(
@ -223,16 +213,12 @@ 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.SearchBar.Text -eq "") {
Set-CategoryVisibility -Category "*" -ItemsControl $sync.ItemsControl -automaticVisibility
}
if ($sync.CompactView -eq $true) { if ($sync.CompactView -eq $true) {
if ($sync.SearchBar.Text -eq "") {
Set-CategoryVisibility -Category "*" -ItemsControl $sync.ItemsControl -isChecked $true
}
$this.Content = "Expanded View" $this.Content = "Expanded View"
} } else {
else {
if ($sync.SearchBar.Text -eq "") {
Set-CategoryVisibility -Category "*" -ItemsControl $sync.ItemsControl -isChecked $false
}
$this.Content = "Compact View" $this.Content = "Compact View"
} }
}) })
@ -525,3 +511,4 @@ function Invoke-WPFUIApps {
} }
} }
} }