diff --git a/Progrart/Dialogs/CloseConfirmationDialog.axaml b/Progrart/Dialogs/CloseConfirmationDialog.axaml
index 1420ebf..520824e 100644
--- a/Progrart/Dialogs/CloseConfirmationDialog.axaml
+++ b/Progrart/Dialogs/CloseConfirmationDialog.axaml
@@ -5,8 +5,12 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Progrart.Dialogs.CloseConfirmationDialog">
-
-
+
+ Unsaved Changes
+
+
+ Save all files or discard changes?
+
@@ -14,7 +18,7 @@
-
+
diff --git a/Progrart/Dialogs/CloseConfirmationDialog.axaml.cs b/Progrart/Dialogs/CloseConfirmationDialog.axaml.cs
index 4e52ad4..eb58667 100644
--- a/Progrart/Dialogs/CloseConfirmationDialog.axaml.cs
+++ b/Progrart/Dialogs/CloseConfirmationDialog.axaml.cs
@@ -1,13 +1,64 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
+using DialogHostAvalonia;
+using System;
+using System.Threading.Tasks;
namespace Progrart.Dialogs;
public partial class CloseConfirmationDialog : UserControl
{
- public CloseConfirmationDialog()
- {
- InitializeComponent();
- }
+ public Func>? onOK = null;
+ public Func>? onDiscard = null;
+ public Func? 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);
+ }
}
\ No newline at end of file
diff --git a/Progrart/Views/MainView.axaml.cs b/Progrart/Views/MainView.axaml.cs
index e8c2f07..046d80f 100644
--- a/Progrart/Views/MainView.axaml.cs
+++ b/Progrart/Views/MainView.axaml.cs
@@ -222,12 +222,21 @@ public partial class MainView : UserControl
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 editor.Save();
- return false;
- }));
+ await MainTabHost.Foreach(async (page) =>
+ {
+ if (page is IEditorPage editor)
+ await editor.Save();
+ return false;
+ });
+ OnDone?.Invoke();
+ });
}
private async void CreateProjectMenuItem_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
@@ -310,17 +319,36 @@ public partial class MainView : UserControl
});
return v;
}
- private void ExitItem_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
+ public bool TryExit()
{
+
if (CloseCheck())
{
CloseConfirmationDialog dialog = new CloseConfirmationDialog();
-
+ dialog.onOK = async () =>
+ {
+ SaveAll(() =>
+ {
+ Environment.Exit(0);
+ });
+ return false;
+ };
+ dialog.onDiscard = async () =>
+ {
+ Environment.Exit(0);
+ return false;
+ };
DialogHost.Show(dialog);
+ return false;
}
else
{
Environment.Exit(0);
+ return true;
}
}
+ private void ExitItem_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
+ {
+ TryExit();
+ }
}
\ No newline at end of file
diff --git a/Progrart/Views/MainWindow.axaml b/Progrart/Views/MainWindow.axaml
index 266f440..48292f6 100644
--- a/Progrart/Views/MainWindow.axaml
+++ b/Progrart/Views/MainWindow.axaml
@@ -8,5 +8,5 @@
x:Class="Progrart.Views.MainWindow"
Icon="/Assets/Background.png"
Title="Progrart">
-
+
diff --git a/Progrart/Views/MainWindow.axaml.cs b/Progrart/Views/MainWindow.axaml.cs
index 494d9d7..d562dd6 100644
--- a/Progrart/Views/MainWindow.axaml.cs
+++ b/Progrart/Views/MainWindow.axaml.cs
@@ -9,5 +9,12 @@ public partial class MainWindow : Window
InitializeComponent();
this.ExtendClientAreaToDecorationsHint = true;
this.ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.PreferSystemChrome;
+ this.Closing += MainWindow_Closing;
+ }
+
+ private void MainWindow_Closing(object? sender, WindowClosingEventArgs e)
+ {
+ e.Cancel=!MainAppView.TryExit();
+
}
}
\ No newline at end of file