From 41df9d3d883aab41bcb57a5fa06851fee9f75be9 Mon Sep 17 00:00:00 2001
From: Martin Wiethan <47688561+Marterich@users.noreply.github.com>
Date: Fri, 23 May 2025 17:52:57 +0200
Subject: [PATCH] Add Right-Click Action on App Install Page (#3367)
* Add right click context menu for app entries with install, uninstall, and info options
* Add hand cursor on mouse over for button in inputXML.xaml
---
.../private/Initalize-InstallAppEntry.ps1 | 9 ++-
functions/public/Initialize-WPFUI.ps1 | 65 ++++++++++++++++++-
xaml/inputXML.xaml | 47 ++++++++++++++
3 files changed, 119 insertions(+), 2 deletions(-)
diff --git a/functions/private/Initalize-InstallAppEntry.ps1 b/functions/private/Initalize-InstallAppEntry.ps1
index eef4f8ba..ccc8d892 100644
--- a/functions/private/Initalize-InstallAppEntry.ps1
+++ b/functions/private/Initalize-InstallAppEntry.ps1
@@ -18,7 +18,7 @@ function Initialize-InstallAppEntry {
$border.Style = $sync.Form.Resources.AppEntryBorderStyle
$border.Tag = $appKey
$border.ToolTip = $Apps.$appKey.description
- $border.Add_MouseUp({
+ $border.Add_MouseLeftButtonUp({
$childCheckbox = ($this.Child | Where-Object {$_.Template.TargetType -eq [System.Windows.Controls.Checkbox]})[0]
$childCheckBox.isChecked = -not $childCheckbox.IsChecked
})
@@ -32,6 +32,13 @@ function Initialize-InstallAppEntry {
$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
+ })
$checkBox = New-Object Windows.Controls.CheckBox
$checkBox.Name = $appKey
diff --git a/functions/public/Initialize-WPFUI.ps1 b/functions/public/Initialize-WPFUI.ps1
index 4786a8e9..46d8b9e8 100644
--- a/functions/public/Initialize-WPFUI.ps1
+++ b/functions/public/Initialize-WPFUI.ps1
@@ -7,7 +7,7 @@ function Initialize-WPFUI {
switch ($TargetGridName) {
"appscategory"{
- # TODO
+ # TODO
# Switch UI generation of the sidebar to this function
# $sync.ItemsControl = Initialize-InstallAppArea -TargetElement $TargetGridName
# ...
@@ -44,6 +44,69 @@ function Initialize-WPFUI {
$sync.selectedAppsPopup.IsOpen = $false
}
})
+
+ # Creates the popup that is displayed when the user right-clicks on an app entry
+ # This popup contains buttons for installing, uninstalling, and viewing app information
+
+ $appPopup = New-Object Windows.Controls.Primitives.Popup
+ $appPopup.StaysOpen = $false
+ $appPopup.Placement = [System.Windows.Controls.Primitives.PlacementMode]::Bottom
+ $appPopup.AllowsTransparency = $true
+ # Store the popup globally so the position can be set later
+ $sync.appPopup = $appPopup
+
+ $appPopupStackPanel = New-Object Windows.Controls.StackPanel
+ $appPopupStackPanel.Orientation = "Horizontal"
+ $appPopupStackPanel.Add_MouseLeave({
+ $sync.appPopup.IsOpen = $false
+ })
+ $appPopup.Child = $appPopupStackPanel
+
+ $appButtons = @(
+ [PSCustomObject]@{ Name = "Install"; Icon = [char]0xE118 },
+ [PSCustomObject]@{ Name = "Uninstall"; Icon = [char]0xE74D },
+ [PSCustomObject]@{ Name = "Info"; Icon = [char]0xE946 }
+ )
+ foreach ($button in $appButtons) {
+ $newButton = New-Object Windows.Controls.Button
+ $newButton.Style = $sync.Form.Resources.AppEntryButtonStyle
+ $newButton.Content = $button.Icon
+ $appPopupStackPanel.Children.Add($newButton) | Out-Null
+
+ # Dynamically load the selected app object so the buttons can be reused and do not need to be created for each app
+ switch ($button.Name) {
+ "Install" {
+ $newButton.Add_MouseEnter({
+ $appObject = $sync.configs.applicationsHashtable.$($sync.appPopupSelectedApp)
+ $this.ToolTip = "Install or Upgrade $($appObject.content)"
+ })
+ $newButton.Add_Click({
+ $appObject = $sync.configs.applicationsHashtable.$($sync.appPopupSelectedApp)
+ Invoke-WPFInstall -PackagesToInstall $appObject
+ })
+ }
+ "Uninstall" {
+ $newButton.Add_MouseEnter({
+ $appObject = $sync.configs.applicationsHashtable.$($sync.appPopupSelectedApp)
+ $this.ToolTip = "Uninstall $($appObject.content)"
+ })
+ $newButton.Add_Click({
+ $appObject = $sync.configs.applicationsHashtable.$($sync.appPopupSelectedApp)
+ Invoke-WPFUnInstall -PackagesToUninstall $appObject
+ })
+ }
+ "Info" {
+ $newButton.Add_MouseEnter({
+ $appObject = $sync.configs.applicationsHashtable.$($sync.appPopupSelectedApp)
+ $this.ToolTip = "Open the application's website in your default browser`n$($appObject.link)"
+ })
+ $newButton.Add_Click({
+ $appObject = $sync.configs.applicationsHashtable.$($sync.appPopupSelectedApp)
+ Start-Process $appObject.link
+ })
+ }
+ }
+ }
}
"appspanel" {
$sync.ItemsControl = Initialize-InstallAppArea -TargetElement $TargetGridName
diff --git a/xaml/inputXML.xaml b/xaml/inputXML.xaml
index d0cb9dbb..a319ee90 100644
--- a/xaml/inputXML.xaml
+++ b/xaml/inputXML.xaml
@@ -117,7 +117,54 @@
+