mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-24 06:51:30 -06:00
Replace Category Label with ToggleButton, Fix Search Bugs
This commit is contained in:
parent
2d0e68c90f
commit
7b273d5634
@ -3,7 +3,9 @@ function Toggle-CategoryVisibility {
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$Category,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[System.Windows.Controls.ItemsControl]$ItemsControl
|
||||
[System.Windows.Controls.ItemsControl]$ItemsControl,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[bool]$isChecked
|
||||
)
|
||||
|
||||
$appsInCategory = $ItemsControl.Items | Where-Object {
|
||||
@ -11,16 +13,14 @@ function Toggle-CategoryVisibility {
|
||||
$sync.configs.applicationsHashtable.$($_.Tag).Category -eq $Category
|
||||
}
|
||||
}
|
||||
$isCollapsed = $appsInCategory[0].Visibility -eq [Windows.Visibility]::Visible
|
||||
|
||||
foreach ($appEntry in $appsInCategory) {
|
||||
$appEntry.Visibility = if ($isCollapsed) {
|
||||
[Windows.Visibility]::Collapsed
|
||||
} else {
|
||||
$appEntry.Visibility = if ($isChecked) {
|
||||
[Windows.Visibility]::Visible
|
||||
} else {
|
||||
[Windows.Visibility]::Collapsed
|
||||
}
|
||||
}
|
||||
$categoryPanel = $ItemsControl.Items | Where-Object { $_ -is [System.Windows.Controls.StackPanel] -and $_.Children[1].Text -eq $Category } | Select-Object -First 1
|
||||
$categoryPanel.Children[0].Text = if ($isCollapsed) { "[+] " } else { "[-] " }
|
||||
}
|
||||
|
||||
function Search-AppsByNameOrDescription {
|
||||
@ -34,8 +34,12 @@ function Search-AppsByNameOrDescription {
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($SearchString)) {
|
||||
$Apps | ForEach-Object {
|
||||
$_.Visibility = 'Visible'
|
||||
}
|
||||
if ($null -ne $_.Tag) {
|
||||
$_.Visibility = 'Collapsed'
|
||||
} else {
|
||||
$_.Visibility = 'Visible'
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$Apps | ForEach-Object {
|
||||
if ($null -ne $_.Tag) {
|
||||
@ -188,36 +192,24 @@ function Invoke-WPFUIApps {
|
||||
return $itemsControl
|
||||
}
|
||||
|
||||
function Add-CategoryLabel {
|
||||
function Add-Category {
|
||||
param(
|
||||
[string]$Category,
|
||||
$ItemsControl
|
||||
)
|
||||
|
||||
$toggleButton = New-Object Windows.Controls.Primitives.ToggleButton
|
||||
$toggleButton.Content = "$Category"
|
||||
$toggleButton.Cursor = [System.Windows.Input.Cursors]::Hand
|
||||
$toggleButton.Style = $window.FindResource("CategoryToggleButtonStyle")
|
||||
|
||||
|
||||
$categoryPanel = New-Object Windows.Controls.StackPanel
|
||||
$categoryPanel.Orientation = [Windows.Controls.Orientation]::Horizontal
|
||||
|
||||
$expanderIcon = New-Object Windows.Controls.TextBlock
|
||||
$expanderIcon.Text = "[+] "
|
||||
$expanderIcon.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "FontSizeHeading")
|
||||
$expanderIcon.SetResourceReference([Windows.Controls.Control]::FontFamilyProperty, "HeaderFontFamily")
|
||||
$expanderIcon.VerticalAlignment = "Center"
|
||||
$null = $categoryPanel.Children.Add($expanderIcon)
|
||||
|
||||
$categoryLabel = New-Object Windows.Controls.TextBlock
|
||||
$categoryLabel.Text = $Category
|
||||
$categoryLabel.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "FontSizeHeading")
|
||||
$categoryLabel.SetResourceReference([Windows.Controls.Control]::FontFamilyProperty, "HeaderFontFamily")
|
||||
$categoryLabel.VerticalAlignment = "Center"
|
||||
$null = $categoryPanel.Children.Add($categoryLabel)
|
||||
$categoryPanel.Cursor = [System.Windows.Input.Cursors]::Hand
|
||||
|
||||
$categoryPanel.Add_MouseUp({
|
||||
$toggleButton.Add_Click({
|
||||
# Clear the search bar when a category is clicked
|
||||
$sync.SearchBar.Text = ""
|
||||
Toggle-CategoryVisibility -Category $this.Children[1].Text -ItemsControl $this.Parent
|
||||
Toggle-CategoryVisibility -Category $this.Content -ItemsControl $this.Parent -isChecked $this.IsChecked
|
||||
})
|
||||
$null = $ItemsControl.Items.Add($categoryPanel)
|
||||
$null = $ItemsControl.Items.Add($toggleButton)
|
||||
}
|
||||
|
||||
function New-CategoryAppList {
|
||||
@ -242,7 +234,7 @@ function Invoke-WPFUIApps {
|
||||
|
||||
$categories = $Apps.Values | Select-Object -ExpandProperty category -Unique | Sort-Object
|
||||
foreach ($category in $categories) {
|
||||
Add-CategoryLabel -Category $category -ItemsControl $itemsControl
|
||||
Add-Category -Category $category -ItemsControl $itemsControl
|
||||
$Apps.Keys | Where-Object { $Apps.$_.Category -eq $category } | Sort-Object | ForEach-Object {
|
||||
New-AppEntry -ItemsControl $itemsControl -AppKey $_ -Hidden $true
|
||||
}
|
||||
@ -266,6 +258,7 @@ function Invoke-WPFUIApps {
|
||||
$border.HorizontalAlignment = "Stretch"
|
||||
$border.VerticalAlignment = "Top"
|
||||
$border.Margin = New-Object Windows.Thickness(0, 10, 0, 0)
|
||||
$border.Cursor = [System.Windows.Input.Cursors]::Hand
|
||||
$border.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallUnselectedColor")
|
||||
$border.Tag = $Appkey
|
||||
$border.ToolTip = $App.description
|
||||
|
@ -197,6 +197,45 @@
|
||||
<Setter Property="Background" Value="{DynamicResource LabelBackgroundColor}"/>
|
||||
<Setter Property="FontFamily" Value="{DynamicResource FontFamily}"/>
|
||||
</Style>
|
||||
<!-- Category Toggle Button Style for the Apps Window-->
|
||||
<Style x:Key="CategoryToggleButtonStyle" TargetType="ToggleButton">
|
||||
<Setter Property="Foreground" Value="{DynamicResource LabelboxForegroundColor}"/>
|
||||
<Setter Property="Background" Value="{DynamicResource MainBackgroundColor}"/>
|
||||
<Setter Property="FontFamily" Value="{DynamicResource HeaderFontFamily}"/>
|
||||
<Setter Property="FontSize" Value="{DynamicResource FontSizeHeading}"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Left"/>
|
||||
<Setter Property="Padding" Value="10,2,10,2"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ToggleButton">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderBrush="{DynamicResource BorderColor}"
|
||||
BorderThickness="{DynamicResource ButtonBorderThickness}"
|
||||
CornerRadius="{DynamicResource ButtonCornerRadius}">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}">
|
||||
<TextBlock x:Name="PrefixTextBlock"/>
|
||||
<ContentPresenter Content="{TemplateBinding Content}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter TargetName="PrefixTextBlock" Property="Text" Value="[-] "/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="False">
|
||||
<Setter TargetName="PrefixTextBlock" Property="Text" Value="[+] "/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource ButtonBackgroundMouseoverColor}"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<!-- TextBlock template -->
|
||||
<Style TargetType="TextBlock">
|
||||
|
Loading…
Reference in New Issue
Block a user