More Cleanup, and simplification. Also added support for screenreaders

This commit is contained in:
Marterich 2025-05-08 13:54:52 +02:00
parent 3859a59547
commit 00ea8f2a60
7 changed files with 54 additions and 79 deletions

View File

@ -1,10 +1,24 @@
{
"WPFGetInstalled": {
"Content": "Get Installed",
"WPFInstall": {
"Content": "Install/Upgrade Applications",
"Category": "____Actions",
"Type": "Button",
"Order": "4",
"Description": "Show installed applications"
"Order": "1",
"Description": "Install or upgrade the selected applications"
},
"WPFUninstall": {
"Content": "Uninstall Applications",
"Category": "____Actions",
"Type": "Button",
"Order": "2",
"Description": "Uninstall the selected applications"
},
"WPFInstallUpgrade": {
"Content": "Upgrade all Applications",
"Category": "____Actions",
"Type": "Button",
"Order": "3",
"Description": "Upgrade all applications to the latest version"
},
"WingetRadioButton": {
"Content": "Winget",
@ -24,39 +38,25 @@
"Order": "2",
"Description": "Use Chocolatey for package management"
},
"WPFInstall": {
"Content": "Install/Upgrade Applications",
"Category": "____Actions",
"Type": "Button",
"Order": "5",
"Description": "Install or upgrade the selected applications"
},
"WPFInstallUpgrade": {
"Content": "Upgrade all Applications",
"Category": "____Actions",
"Type": "Button",
"Order": "6",
"Description": "Upgrade all applications to the latest version"
},
"WPFUninstall": {
"Content": "Uninstall Applications",
"Category": "____Actions",
"Type": "Button",
"Order": "7",
"Description": "Uninstall the selected applications"
},
"WPFselectedAppsButton": {
"Content": "Selected Apps: 0",
"Category": "__Selection",
"Type": "Button",
"Order": "2",
"Description": "Show the selected applications"
},
"WPFClearInstallSelection": {
"Content": "Clear Selection",
"Category": "__Selection",
"Type": "Button",
"Order": "1",
"Description": "Clear the selection of applications"
},
"WPFGetInstalled": {
"Content": "Get Installed",
"Category": "__Selection",
"Type": "Button",
"Order": "2",
"Description": "Show installed applications"
},
"WPFselectedAppsButton": {
"Content": "Selected Apps: 0",
"Category": "__Selection",
"Type": "Button",
"Order": "3",
"Description": "Show the selected applications"
}
}

View File

@ -33,7 +33,6 @@ function Initialize-InstallAppEntry {
}
})
# Create the CheckBox, vertically centered
$checkBox = New-Object Windows.Controls.CheckBox
$checkBox.Name = $appKey
$checkbox.Style = $sync.Form.Resources.AppEntryCheckboxStyle
@ -57,6 +56,10 @@ function Initialize-InstallAppEntry {
# Add the name to the Checkbox
$checkBox.Content = $appName
# Add accessibility properties to make the elements screen reader friendly
$checkBox.SetValue([Windows.Automation.AutomationProperties]::NameProperty, $Apps.$appKey.content)
$border.SetValue([Windows.Automation.AutomationProperties]::NameProperty, $Apps.$appKey.content)
$border.Child = $checkBox
# Add the border to the corresponding Category
$TargetElement.Children.Add($border) | Out-Null

View File

@ -10,27 +10,36 @@
#>
param($TargetElement)
$targetGrid = $sync.Form.FindName($TargetElement)
$null = $targetGrid.Children.Clear()
# Create the outer Border for the aren where the apps will be placed
$Border = New-Object Windows.Controls.Border
$Border.VerticalAlignment = "Stretch"
$Border.SetResourceReference([Windows.Controls.Control]::StyleProperty, "BorderStyle")
# Add a ScrollViewer, because the ItemsControl does not support scrolling by itself
$scrollViewer = New-Object Windows.Controls.ScrollViewer
$scrollViewer.VerticalScrollBarVisibility = 'Auto'
$scrollViewer.HorizontalAlignment = 'Stretch'
$scrollViewer.VerticalAlignment = 'Stretch'
$scrollViewer.CanContentScroll = $true
## Create the ItemsControl, which will be the parent of all the app entries
$itemsControl = New-Object Windows.Controls.ItemsControl
$itemsControl.HorizontalAlignment = 'Stretch'
$itemsControl.VerticalAlignment = 'Stretch'
# Enable virtualization for the ItemsControl to improve performance (It's hard to test if this is actually working, so if you know what you're doing, please check this)
$itemsPanelTemplate = New-Object Windows.Controls.ItemsPanelTemplate
$factory = New-Object Windows.FrameworkElementFactory ([Windows.Controls.VirtualizingStackPanel])
$itemsPanelTemplate.VisualTree = $factory
$itemsControl.ItemsPanel = $itemsPanelTemplate
$itemsControl.SetValue([Windows.Controls.VirtualizingStackPanel]::IsVirtualizingProperty, $true)
$itemsControl.SetValue([Windows.Controls.VirtualizingStackPanel]::VirtualizationModeProperty, [Windows.Controls.VirtualizationMode]::Recycling)
$scrollViewer.Content = $itemsControl
[Windows.Controls.DockPanel]::SetDock($scrollViewer, [Windows.Controls.Dock]::Bottom)
$null = $TargetElement.Children.Add($scrollViewer)
$Border.Child = $scrollViewer
$null = $targetGrid.Children.Add($Border)
return $itemsControl
}

View File

@ -1,28 +0,0 @@
function Initialize-InstallAppsMainElement {
<#
.SYNOPSIS
Clears the given WPF Grid and creates a [Windows.Controls.Border] containing a [Windows.Controls.StackPanel]
Used to as part of the Install Tab UI generation
.PARAMETER TargetGridName
The WPF Grid name
.OUTPUTS
Returns the created [Windows.Controls.StackPanel] element
#>
param(
[Parameter(Mandatory)]
[string]$TargetGridName
)
$targetGrid = $sync.Form.FindName($TargetGridName)
$null = $targetGrid.Children.Clear()
$Border = New-Object Windows.Controls.Border
$Border.VerticalAlignment = "Stretch"
$Border.SetResourceReference([Windows.Controls.Control]::StyleProperty, "BorderStyle")
$dockPanel = New-Object Windows.Controls.DockPanel
$Border.Child = $dockPanel
$null = $targetGrid.Children.Add($Border)
return $dockPanel
}

View File

@ -61,5 +61,6 @@ function Invoke-WPFButton {
"WPFWinUtilInstallPSProfile" {Invoke-WinUtilInstallPSProfile}
"WPFWinUtilUninstallPSProfile" {Invoke-WinUtilUninstallPSProfile}
"WPFWinUtilSSHServer" {Invoke-WPFSSHServer}
"WPFselectedAppsButton" {$sync.selectedAppsPopup.IsOpen = -not $sync.selectedAppsPopup.IsOpen}
}
}

View File

@ -9,15 +9,14 @@ function Invoke-WPFUIApps {
switch ($TargetGridName) {
"appspanel" {
$dockPanel = Initialize-InstallAppsMainElement -TargetGridName $TargetGridName
# $null = Initialize-InstallHeader -TargetElement $dockPanel
# Create and configure a popup for displaying selected apps
$selectedAppsPopup = New-Object Windows.Controls.Primitives.Popup
$selectedAppsPopup.IsOpen = $false
$selectedAppsPopup.PlacementTarget = $sync.WPFselectedAppsButton
$selectedAppsPopup.Placement = [System.Windows.Controls.Primitives.PlacementMode]::Bottom
$selectedAppsPopup.AllowsTransparency = $true
# Style the popup with a border and background
$selectedAppsBorder = New-Object Windows.Controls.Border
$selectedAppsBorder.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "MainBackgroundColor")
$selectedAppsBorder.SetResourceReference([Windows.Controls.Control]::BorderBrushProperty, "MainForegroundColor")
@ -27,13 +26,10 @@ function Invoke-WPFUIApps {
$selectedAppsPopup.Child = $selectedAppsBorder
$sync.selectedAppsPopup = $selectedAppsPopup
# Add a stack panel inside the popup's border to organize its child elements
$sync.selectedAppsstackPanel = New-Object Windows.Controls.StackPanel
$selectedAppsBorder.Child = $sync.selectedAppsstackPanel
# Toggle selectedAppsPopup open/close with button
$sync.WPFselectedAppsButton.Add_Click({
$sync.selectedAppsPopup.IsOpen = -not $sync.selectedAppsPopup.IsOpen
})
# Close selectedAppsPopup when mouse leaves both button and selectedAppsPopup
$sync.WPFselectedAppsButton.Add_MouseLeave({
if (-not $sync.selectedAppsPopup.IsMouseOver) {
@ -45,7 +41,7 @@ function Invoke-WPFUIApps {
$sync.selectedAppsPopup.IsOpen = $false
}
})
$sync.ItemsControl = Initialize-InstallAppArea -TargetElement $dockPanel
$sync.ItemsControl = Initialize-InstallAppArea -TargetElement $TargetGridName
Initialize-InstallCategoryAppList -TargetElement $sync.ItemsControl -Apps $Apps
}
default {

View File

@ -93,12 +93,6 @@ function Invoke-WPFUIElements {
# Store application data in an array under the category
$organizedData[$entryObject.Panel][$entryObject.Category] += $entryObject
# Only apply the logic for distributing entries across columns if the targetGridName is "appspanel"
if ($targetGridName -eq "appspanel") {
$panelcount = 0
$entrycount = $configHashtable.Keys.Count + $organizedData["0"].Keys.Count
}
}
# Initialize panel count