Browse Source

Merge pull request #557 from ionite34/backport/main/pr-556

[dev to main] backport: Really confirm package deletion (556)
pull/512/head
JT 8 months ago committed by GitHub
parent
commit
a09775a207
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 21
      StabilityMatrix.Avalonia/ViewModels/Dialogs/ConfirmPackageDeleteDialogViewModel.cs
  2. 16
      StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs
  3. 55
      StabilityMatrix.Avalonia/Views/Dialogs/ConfirmPackageDeleteDialog.axaml
  4. 13
      StabilityMatrix.Avalonia/Views/Dialogs/ConfirmPackageDeleteDialog.axaml.cs

21
StabilityMatrix.Avalonia/ViewModels/Dialogs/ConfirmPackageDeleteDialogViewModel.cs

@ -0,0 +1,21 @@
using System;
using CommunityToolkit.Mvvm.ComponentModel;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Avalonia.Views.Dialogs;
using StabilityMatrix.Core.Attributes;
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs;
[View(typeof(ConfirmPackageDeleteDialog))]
[ManagedService]
[Transient]
public partial class ConfirmPackageDeleteDialogViewModel : ContentDialogViewModelBase
{
public required string ExpectedPackageName { get; set; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsValid))]
private string packageName = string.Empty;
public bool IsValid => ExpectedPackageName.Equals(PackageName, StringComparison.Ordinal);
}

16
StabilityMatrix.Avalonia/ViewModels/PackageManager/PackageCardViewModel.cs

@ -181,13 +181,17 @@ public partial class PackageCardViewModel : ProgressViewModel
return; return;
} }
var dialog = new ContentDialog var dialogViewModel = vmFactory.Get<ConfirmPackageDeleteDialogViewModel>(vm =>
{ {
Title = Resources.Label_ConfirmDelete, vm.ExpectedPackageName = Package?.DisplayName;
Content = Resources.Text_PackageUninstall_Details, });
PrimaryButtonText = Resources.Action_OK,
CloseButtonText = Resources.Action_Cancel, var dialog = new BetterContentDialog
DefaultButton = ContentDialogButton.Primary {
Content = dialogViewModel,
IsPrimaryButtonEnabled = false,
IsSecondaryButtonEnabled = false,
IsFooterVisible = false,
}; };
var result = await dialog.ShowAsync(); var result = await dialog.ShowAsync();

55
StabilityMatrix.Avalonia/Views/Dialogs/ConfirmPackageDeleteDialog.axaml

@ -0,0 +1,55 @@
<controls:UserControlBase xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:StabilityMatrix.Avalonia.Controls"
xmlns:lang="clr-namespace:StabilityMatrix.Avalonia.Languages"
xmlns:dialogs="clr-namespace:StabilityMatrix.Avalonia.ViewModels.Dialogs"
xmlns:controls1="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:DataType="dialogs:ConfirmPackageDeleteDialogViewModel"
x:Class="StabilityMatrix.Avalonia.Views.Dialogs.ConfirmPackageDeleteDialog">
<Grid RowDefinitions="Auto, Auto, Auto, Auto, *"
Margin="8">
<TextBlock Text="{x:Static lang:Resources.Text_PackageUninstall_Details}"
FontWeight="Bold"
FontSize="20"
TextAlignment="Center"
TextWrapping="Wrap"/>
<TextBlock Grid.Row="1"
Margin="0,32,0,8"
TextAlignment="Center">
<Run Text="Please type"/>
<Run FontWeight="Bold" Text="{Binding ExpectedPackageName}"/>
<Run Text="to confirm the deletion of the package:"/>
</TextBlock>
<TextBox Grid.Row="2"
Text="{Binding PackageName, Mode=TwoWay}"
Margin="0,16,0,0"/>
<controls1:InfoBar Grid.Row="3"
Margin="0,16,0,0"
IsClosable="False"
IsOpen="True"
Title="{x:Static lang:Resources.Label_ActionCannotBeUndone}"
Severity="Warning"/>
<UniformGrid Grid.Row="4" HorizontalAlignment="Stretch"
VerticalAlignment="Bottom"
Margin="0,32,0,0">
<Button Content="{x:Static lang:Resources.Action_Delete}"
Classes="danger"
IsEnabled="{Binding IsValid}"
HorizontalAlignment="Stretch"
Margin="0,0,4,0"
Command="{Binding OnPrimaryButtonClick}"
FontSize="16"/>
<Button Content="{x:Static lang:Resources.Action_Cancel}"
Command="{Binding OnCloseButtonClick}"
Margin="4,0,0,0"
HorizontalAlignment="Stretch"
FontSize="16"/>
</UniformGrid>
</Grid>
</controls:UserControlBase>

13
StabilityMatrix.Avalonia/Views/Dialogs/ConfirmPackageDeleteDialog.axaml.cs

@ -0,0 +1,13 @@
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Core.Attributes;
namespace StabilityMatrix.Avalonia.Views.Dialogs;
[Transient]
public partial class ConfirmPackageDeleteDialog : UserControlBase
{
public ConfirmPackageDeleteDialog()
{
InitializeComponent();
}
}
Loading…
Cancel
Save