mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-06-28 00:54:47 -05:00
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
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user