mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-04-17 18:16:28 +03:00
add CloseConfirmationDialog
This commit is contained in:
@@ -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>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user