Files
winutil/functions/private/Initialize-InstallAppEntry.ps1
T

84 lines
3.7 KiB
PowerShell
Raw Normal View History

2025-03-01 20:50:12 +01:00
function Initialize-InstallAppEntry {
<#
.SYNOPSIS
2025-10-14 19:51:53 +02:00
Creates the app entry to be placed on the install tab for a given app
2025-03-01 20:50:12 +01:00
Used to as part of the Install Tab UI generation
.PARAMETER TargetElement
The Element into which the Apps should be placed
2025-04-02 22:54:44 +02:00
.PARAMETER appKey
2025-03-01 20:50:12 +01:00
The Key of the app inside the $sync.configs.applicationsHashtable
#>
param(
[Windows.Controls.WrapPanel]$TargetElement,
2025-04-02 22:54:44 +02:00
$appKey
2025-03-01 20:50:12 +01:00
)
2025-04-02 22:54:44 +02:00
2025-03-01 20:50:12 +01:00
# Create the outer Border for the application type
$border = New-Object Windows.Controls.Border
2025-05-12 22:45:57 +02:00
$border.Style = $sync.Form.Resources.AppEntryBorderStyle
2025-04-02 22:54:44 +02:00
$border.Tag = $appKey
$border.ToolTip = $Apps.$appKey.description
$border.Add_MouseLeftButtonUp({
2025-05-12 22:45:57 +02:00
$childCheckbox = ($this.Child | Where-Object {$_.Template.TargetType -eq [System.Windows.Controls.Checkbox]})[0]
2025-03-01 20:50:12 +01:00
$childCheckBox.isChecked = -not $childCheckbox.IsChecked
})
$border.Add_MouseEnter({
if (($sync.$($this.Tag).IsChecked) -eq $false) {
$this.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallHighlightedColor")
}
})
$border.Add_MouseLeave({
if (($sync.$($this.Tag).IsChecked) -eq $false) {
$this.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallUnselectedColor")
}
})
$border.Add_MouseRightButtonUp({
# Store the selected app in a global variable so it can be used in the popup
$sync.appPopupSelectedApp = $this.Tag
# Set the popup position to the current mouse position
$sync.appPopup.PlacementTarget = $this
$sync.appPopup.IsOpen = $true
})
2025-03-01 20:50:12 +01:00
$checkBox = New-Object Windows.Controls.CheckBox
2026-02-17 22:35:26 +03:00
# Sanitize the name for WPF
$checkBox.Name = $appKey -replace '-', '_'
# Store the original appKey in Tag
$checkBox.Tag = $appKey
2025-05-12 22:45:57 +02:00
$checkbox.Style = $sync.Form.Resources.AppEntryCheckboxStyle
2025-03-01 20:50:12 +01:00
$checkbox.Add_Checked({
2026-02-17 12:39:44 -06:00
Invoke-WPFSelectedCheckboxesUpdate -type "Add" -checkboxName $this.Parent.Tag
2025-05-12 22:45:57 +02:00
$borderElement = $this.Parent
2025-03-01 20:50:12 +01:00
$borderElement.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallSelectedColor")
})
$checkbox.Add_Unchecked({
2026-02-17 12:39:44 -06:00
Invoke-WPFSelectedCheckboxesUpdate -type "Remove" -checkboxName $this.Parent.Tag
2025-05-12 22:45:57 +02:00
$borderElement = $this.Parent
2025-03-01 20:50:12 +01:00
$borderElement.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallUnselectedColor")
})
2025-04-02 22:54:44 +02:00
2025-03-01 20:50:12 +01:00
# Create the TextBlock for the application name
$appName = New-Object Windows.Controls.TextBlock
2025-05-12 22:45:57 +02:00
$appName.Style = $sync.Form.Resources.AppEntryNameStyle
2025-04-02 22:54:44 +02:00
$appName.Text = $Apps.$appKey.content
2025-03-01 20:50:12 +01:00
2026-02-17 22:35:26 +03:00
# Change color to Green if FOSS
if ($Apps.$appKey.foss -eq $true) {
$appName.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "FOSSColor")
$appName.FontWeight = "Bold"
}
2025-05-12 22:45:57 +02:00
# Add the name to the Checkbox
$checkBox.Content = $appName
2025-03-01 20:50:12 +01:00
2025-05-12 22:45:57 +02:00
# 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)
2025-03-01 20:50:12 +01:00
2025-05-12 22:45:57 +02:00
$border.Child = $checkBox
2025-03-01 20:50:12 +01:00
# Add the border to the corresponding Category
$TargetElement.Children.Add($border) | Out-Null
2025-04-02 22:54:44 +02:00
return $checkbox
2025-03-01 20:50:12 +01:00
}