Skip to content

Commit

Permalink
Replace Category Label with ToggleButton, Fix Search Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Marterich committed Oct 14, 2024
1 parent 2d0e68c commit 7b273d5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 33 deletions.
59 changes: 26 additions & 33 deletions functions/public/Invoke-WPFUIApps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ 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 {
if ($null -ne $_.Tag) {
$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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -188,36 +192,24 @@ function Invoke-WPFUIApps {
return $itemsControl
}

function Add-CategoryLabel {
function Add-Category {
param(
[string]$Category,
$ItemsControl
)

$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 = New-Object Windows.Controls.Primitives.ToggleButton
$toggleButton.Content = "$Category"
$toggleButton.Cursor = [System.Windows.Input.Cursors]::Hand
$toggleButton.Style = $window.FindResource("CategoryToggleButtonStyle")


$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 {
Expand All @@ -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
}
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions xaml/inputXML.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit 7b273d5

Please sign in to comment.