mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-05-23 00:36:33 +03:00
add CloseConfirmationDialog
This commit is contained in:
@@ -1,12 +1,28 @@
|
|||||||
using System;
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
using System.Collections.Generic;
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
using System.Linq;
|
x:Class="KeyKeeper.Views.CloseConfirmationDialog"
|
||||||
using System.Text;
|
Width="420"
|
||||||
using System.Threading.Tasks;
|
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
|
<StackPanel Grid.Row="1"
|
||||||
{
|
Orientation="Horizontal"
|
||||||
class CloseConfirmationDialog
|
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>
|
||||||
@@ -1,12 +1,52 @@
|
|||||||
using System;
|
using Avalonia.Controls;
|
||||||
using System.Collections.Generic;
|
using Avalonia.Interactivity;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user