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:
@ -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
|
||||
|
@ -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