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:
Martin Wiethan 2025-05-23 17:52:57 +02:00 committed by GitHub
parent 63d56bcac9
commit 41df9d3d88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 119 additions and 2 deletions

View File

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

View File

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

View File

@ -117,7 +117,54 @@
<Setter Property="Margin" Value="{DynamicResource AppEntryMargin}"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style x:Key="AppEntryButtonStyle" TargetType="Button">
<Setter Property="Width" Value="{DynamicResource IconButtonSize}"/>
<Setter Property="Height" Value="{DynamicResource IconButtonSize}"/>
<Setter Property="Margin" Value="{DynamicResource AppEntryMargin}"/>
<Setter Property="Foreground" Value="{DynamicResource ButtonForegroundColor}"/>
<Setter Property="Background" Value="{DynamicResource ButtonBackgroundColor}"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}"
FontFamily="Segoe MDL2 Assets"
FontSize="{DynamicResource IconFontSize}"
Background="Transparent"/>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Border x:Name="BackgroundBorder"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{DynamicResource ButtonBorderThickness}"
CornerRadius="{DynamicResource ButtonCornerRadius}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="BackgroundBorder" Property="Background" Value="{DynamicResource ButtonBackgroundPressedColor}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand"/>
<Setter TargetName="BackgroundBorder" Property="Background" Value="{DynamicResource ButtonBackgroundMouseoverColor}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="BackgroundBorder" Property="Background" Value="{DynamicResource ButtonBackgroundSelectedColor}"/>
<Setter Property="Foreground" Value="DimGray"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="Button" x:Key="HoverButtonStyle">
<Setter Property="Foreground" Value="{DynamicResource MainForegroundColor}" />
<Setter Property="FontWeight" Value="Normal" />