add CloseConfirmationDialog

This commit is contained in:
InspectorIT
2026-03-01 23:50:18 +03:00
parent 13139ed297
commit 63194d37d6
2 changed files with 76 additions and 20 deletions

View File

@@ -1,12 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="KeyKeeper.Views.CloseConfirmationDialog"
Width="420"
Height="170"
CanResize="False"
WindowStartupLocation="CenterOwner"
Title="Confirm close"
Background="White">
<Grid Margin="16" RowDefinitions="*,Auto">
<TextBlock Text="Save changes before closing the storage?"
TextWrapping="Wrap"
FontSize="16"/>
namespace KeyKeeper.Views
{
class CloseConfirmationDialog
{
}
}
<StackPanel Grid.Row="1"
Orientation="Horizontal"
HorizontalAlignment="Right"
Spacing="8"
Margin="0,16,0,0">
<Button Content="Save"
Click="Save_Click" />
<Button Content="Do not save"
Click="Discard_Click" />
<Button Content="Cancel"
Click="Cancel_Click" />
</StackPanel>
</Grid>
</Window>

View File

@@ -1,12 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace KeyKeeper.Views
namespace KeyKeeper.Views;
public enum CloseConfirmationResult
{
internal class CloseConfirmationDialog
{
}
Save,
Discard,
Cancel,
}
public partial class CloseConfirmationDialog : Window
{
private bool closingWithResult;
public CloseConfirmationDialog()
{
InitializeComponent();
}
protected override void OnClosing(WindowClosingEventArgs e)
{
if (!closingWithResult)
{
e.Cancel = true;
closingWithResult = true;
Close(CloseConfirmationResult.Cancel);
return;
}
base.OnClosing(e);
}
private void Save_Click(object? sender, RoutedEventArgs e)
{
closingWithResult = true;
Close(CloseConfirmationResult.Save);
}
private void Discard_Click(object? sender, RoutedEventArgs e)
{
closingWithResult = true;
Close(CloseConfirmationResult.Discard);
}
private void Cancel_Click(object? sender, RoutedEventArgs e)
{
closingWithResult = true;
Close(CloseConfirmationResult.Cancel);
}
}