Close confirmation is now working.
This commit is contained in:
@@ -5,8 +5,12 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Progrart.Dialogs.CloseConfirmationDialog">
|
x:Class="Progrart.Dialogs.CloseConfirmationDialog">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<TextBlock FontSize="18" Name="TitleBlock" TextWrapping="Wrap"/>
|
<TextBlock FontSize="18" Name="TitleBlock" TextWrapping="Wrap">
|
||||||
<TextBlock Name="MessageBlock" TextWrapping="Wrap"/>
|
Unsaved Changes
|
||||||
|
</TextBlock>
|
||||||
|
<TextBlock Name="MssageBlock" TextWrapping="Wrap">
|
||||||
|
Save all files or discard changes?
|
||||||
|
</TextBlock>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
@@ -14,7 +18,7 @@
|
|||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Classes="accent" Name="OKBtn" Content="Save All"/>
|
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Classes="accent" Name="OKBtn" Content="Save All"/>
|
||||||
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Classes="accent" Grid.Column="1" Name="DiscardBtn" Content="Discard And Close"/>
|
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Grid.Column="1" Name="DiscardBtn" Content="Discard And Close"/>
|
||||||
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Name="CancelBtn" Grid.Column="2" Content="Cancel"/>
|
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Name="CancelBtn" Grid.Column="2" Content="Cancel"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -1,13 +1,64 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using DialogHostAvalonia;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Progrart.Dialogs;
|
namespace Progrart.Dialogs;
|
||||||
|
|
||||||
public partial class CloseConfirmationDialog : UserControl
|
public partial class CloseConfirmationDialog : UserControl
|
||||||
{
|
{
|
||||||
public CloseConfirmationDialog()
|
public Func<Task<bool>>? onOK = null;
|
||||||
{
|
public Func<Task<bool>>? onDiscard = null;
|
||||||
InitializeComponent();
|
public Func<bool>? onCancel = null;
|
||||||
}
|
public CloseConfirmationDialog()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
OKBtn.Click += OKBtn_Click;
|
||||||
|
CancelBtn.Click += CancelBtn_Click;
|
||||||
|
DiscardBtn.Click += async (sender, e) => await Discard();
|
||||||
|
}
|
||||||
|
private void CancelBtn_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Cancel()
|
||||||
|
{
|
||||||
|
if (!(onCancel?.Invoke()) ?? true)
|
||||||
|
{
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OKBtn_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
await Confirmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Confirmed()
|
||||||
|
{
|
||||||
|
if (onOK is not null)
|
||||||
|
{
|
||||||
|
if (!await onOK())
|
||||||
|
{
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
|
private async Task Discard()
|
||||||
|
{
|
||||||
|
if (onDiscard is not null)
|
||||||
|
{
|
||||||
|
if (!await onDiscard())
|
||||||
|
{
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DialogHost.Close(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -222,12 +222,21 @@ public partial class MainView : UserControl
|
|||||||
|
|
||||||
private void MenuItem_SaveAll_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
private void MenuItem_SaveAll_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Task.Run(async () => await MainTabHost.Foreach(async (page) =>
|
SaveAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveAll(Action? OnDone = null)
|
||||||
|
{
|
||||||
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
if (page is IEditorPage editor)
|
await MainTabHost.Foreach(async (page) =>
|
||||||
await editor.Save();
|
{
|
||||||
return false;
|
if (page is IEditorPage editor)
|
||||||
}));
|
await editor.Save();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
OnDone?.Invoke();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void CreateProjectMenuItem_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
private async void CreateProjectMenuItem_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
@@ -310,17 +319,36 @@ public partial class MainView : UserControl
|
|||||||
});
|
});
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
private void ExitItem_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
public bool TryExit()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (CloseCheck())
|
if (CloseCheck())
|
||||||
{
|
{
|
||||||
CloseConfirmationDialog dialog = new CloseConfirmationDialog();
|
CloseConfirmationDialog dialog = new CloseConfirmationDialog();
|
||||||
|
dialog.onOK = async () =>
|
||||||
|
{
|
||||||
|
SaveAll(() =>
|
||||||
|
{
|
||||||
|
Environment.Exit(0);
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
dialog.onDiscard = async () =>
|
||||||
|
{
|
||||||
|
Environment.Exit(0);
|
||||||
|
return false;
|
||||||
|
};
|
||||||
DialogHost.Show(dialog);
|
DialogHost.Show(dialog);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void ExitItem_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
TryExit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,5 +8,5 @@
|
|||||||
x:Class="Progrart.Views.MainWindow"
|
x:Class="Progrart.Views.MainWindow"
|
||||||
Icon="/Assets/Background.png"
|
Icon="/Assets/Background.png"
|
||||||
Title="Progrart">
|
Title="Progrart">
|
||||||
<views:MainView />
|
<views:MainView Name="MainAppView"/>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -9,5 +9,12 @@ public partial class MainWindow : Window
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.ExtendClientAreaToDecorationsHint = true;
|
this.ExtendClientAreaToDecorationsHint = true;
|
||||||
this.ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.PreferSystemChrome;
|
this.ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.PreferSystemChrome;
|
||||||
|
this.Closing += MainWindow_Closing;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainWindow_Closing(object? sender, WindowClosingEventArgs e)
|
||||||
|
{
|
||||||
|
e.Cancel=!MainAppView.TryExit();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user