mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-06-28 09:04:47 -05:00
Re-Redesign of the Install Tab (#3350)
* Initial Remove Expanded View * more cleanup * Add word wrapping for Tooltips * Update tooltip colors in themes and XAML styles * Rename Properties for consistency * More Cleanup, and simplification. Also added support for screenreaders * Remove unused variables and shorten window naming * Rename Invoke-WPFUIApps to Initialize-WPFUI and update function calls for consistency * Rename Invoke-WPFUIApps.ps1 to Initialize-WPFUI.ps1 * Add TODO comments for sidebar UI generation in Initialize-WPFUI function
This commit is contained in:
@ -15,14 +15,11 @@ function Initialize-InstallAppEntry {
|
||||
|
||||
# Create the outer Border for the application type
|
||||
$border = New-Object Windows.Controls.Border
|
||||
$border.Style = $sync.Form.Resources.AppTileBorderStyle
|
||||
$border.Style = $sync.Form.Resources.AppEntryBorderStyle
|
||||
$border.Tag = $appKey
|
||||
$border.ToolTip = $Apps.$appKey.description
|
||||
$border.Add_MouseUp({
|
||||
if ($_.ChangedButton -eq [System.Windows.Input.MouseButton]::Right) {
|
||||
Invoke-WPFPresets -imported $true -checkboxfilterpattern "WPFInstall*";
|
||||
}
|
||||
$childCheckbox = ($this.Child.Children | Where-Object {$_.Template.TargetType -eq [System.Windows.Controls.Checkbox]})[0]
|
||||
$childCheckbox = ($this.Child | Where-Object {$_.Template.TargetType -eq [System.Windows.Controls.Checkbox]})[0]
|
||||
$childCheckBox.isChecked = -not $childCheckbox.IsChecked
|
||||
})
|
||||
$border.Add_MouseEnter({
|
||||
@ -35,101 +32,35 @@ function Initialize-InstallAppEntry {
|
||||
$this.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallUnselectedColor")
|
||||
}
|
||||
})
|
||||
# Create a DockPanel inside the Border
|
||||
$dockPanel = New-Object Windows.Controls.DockPanel
|
||||
$dockPanel.LastChildFill = $true
|
||||
$border.Child = $dockPanel
|
||||
|
||||
# Create the CheckBox, vertically centered
|
||||
$checkBox = New-Object Windows.Controls.CheckBox
|
||||
$checkBox.Name = $appKey
|
||||
$checkbox.Style = $sync.Form.Resources.AppTileCheckboxStyle
|
||||
$checkbox.Style = $sync.Form.Resources.AppEntryCheckboxStyle
|
||||
$checkbox.Add_Checked({
|
||||
Invoke-WPFSelectedAppsUpdate -type "Add" -checkbox $this
|
||||
$borderElement = $this.Parent.Parent
|
||||
$borderElement = $this.Parent
|
||||
$borderElement.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallSelectedColor")
|
||||
})
|
||||
|
||||
$checkbox.Add_Unchecked({
|
||||
Invoke-WPFSelectedAppsUpdate -type "Remove" -checkbox $this
|
||||
$borderElement = $this.Parent.Parent
|
||||
$borderElement = $this.Parent
|
||||
$borderElement.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "AppInstallUnselectedColor")
|
||||
})
|
||||
|
||||
# Create a StackPanel for the image and name
|
||||
$imageAndNamePanel = New-Object Windows.Controls.StackPanel
|
||||
$imageAndNamePanel.Orientation = "Horizontal"
|
||||
$imageAndNamePanel.VerticalAlignment = "Center"
|
||||
|
||||
# Create the Image and set a placeholder
|
||||
$image = New-Object Windows.Controls.Image
|
||||
# $image.Name = "wpfapplogo" + $App.Name
|
||||
$image.Style = $sync.Form.Resources.AppTileImageStyle
|
||||
$image.Source = $noimage # Ensure $noimage is defined in your script
|
||||
|
||||
$imageAndNamePanel.Children.Add($image) | Out-Null
|
||||
|
||||
# Create the TextBlock for the application name
|
||||
$appName = New-Object Windows.Controls.TextBlock
|
||||
$appName.Style = $sync.Form.Resources.AppTileNameStyle
|
||||
$appName.Style = $sync.Form.Resources.AppEntryNameStyle
|
||||
$appName.Text = $Apps.$appKey.content
|
||||
$imageAndNamePanel.Children.Add($appName) | Out-Null
|
||||
|
||||
# Add the image and name panel to the Checkbox
|
||||
$checkBox.Content = $imageAndNamePanel
|
||||
# Add the name to the Checkbox
|
||||
$checkBox.Content = $appName
|
||||
|
||||
# Add the checkbox to the DockPanel
|
||||
[Windows.Controls.DockPanel]::SetDock($checkBox, [Windows.Controls.Dock]::Left)
|
||||
$dockPanel.Children.Add($checkBox) | Out-Null
|
||||
|
||||
# Create the StackPanel for the buttons and dock it to the right
|
||||
$buttonPanel = New-Object Windows.Controls.StackPanel
|
||||
$buttonPanel.Style = $sync.Form.Resources.AppTileButtonPanelStyle
|
||||
[Windows.Controls.DockPanel]::SetDock($buttonPanel, [Windows.Controls.Dock]::Right)
|
||||
|
||||
# Define the button properties
|
||||
$buttons = @(
|
||||
[PSCustomObject]@{ Name = "Install"; Description = "Install or Upgrade the application"; Tooltip = "Install or Upgrade the application"; Icon = [char]0xE118 },
|
||||
[PSCustomObject]@{ Name = "Uninstall"; Description = "Uninstall the application"; Tooltip = "Uninstall the application"; Icon = [char]0xE74D },
|
||||
[PSCustomObject]@{ Name = "Info"; Description = "Open the application's website in your default browser"; Tooltip = "Open the application's website in your default browser"; Icon = [char]0xE946 }
|
||||
)
|
||||
|
||||
# Iterate over each button and create it
|
||||
foreach ($button in $buttons) {
|
||||
$newButton = New-Object Windows.Controls.Button
|
||||
$newButton.Style = $sync.Form.Resources.AppTileButtonStyle
|
||||
$newButton.Content = $button.Icon
|
||||
$newButton.ToolTip = $button.Tooltip
|
||||
$buttonPanel.Children.Add($newButton) | Out-Null
|
||||
|
||||
switch ($button.Name) {
|
||||
"Install" {
|
||||
$newButton.Add_Click({
|
||||
$appKey = $this.Parent.Parent.Parent.Tag
|
||||
$appObject = $sync.configs.applicationsHashtable.$appKey
|
||||
Invoke-WPFInstall -PackagesToInstall $appObject
|
||||
})
|
||||
}
|
||||
"Uninstall" {
|
||||
$newButton.Add_Click({
|
||||
$appKey = $this.Parent.Parent.Parent.Tag
|
||||
$appObject = $sync.configs.applicationsHashtable.$appKey
|
||||
Invoke-WPFUnInstall -PackagesToUninstall $appObject
|
||||
})
|
||||
}
|
||||
"Info" {
|
||||
$newButton.Add_Click({
|
||||
$appKey = $this.Parent.Parent.Parent.Tag
|
||||
$appObject = $sync.configs.applicationsHashtable.$appKey
|
||||
Start-Process $appObject.link
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Add the button panel to the DockPanel
|
||||
$dockPanel.Children.Add($buttonPanel) | Out-Null
|
||||
# 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
|
||||
return $checkbox
|
||||
|
Reference in New Issue
Block a user