浏览代码

Merge pull request #237 from marce1994/fix/WindowsRebookCrashingApp

Fixed crash when windows shutting down or rebooting
Krzysztof Krysiński 3 年之前
父节点
当前提交
b8984cf183
共有 2 个文件被更改,包括 45 次插入2 次删除
  1. 25 0
      PixiEditor/App.xaml.cs
  2. 20 2
      PixiEditor/Models/Dialogs/ConfirmationDialog.cs

+ 25 - 0
PixiEditor/App.xaml.cs

@@ -0,0 +1,25 @@
+using PixiEditor.Models.Dialogs;
+using PixiEditor.Models.Enums;
+using PixiEditor.ViewModels;
+using System.Linq;
+using System.Windows;
+
+namespace PixiEditor
+{
+    /// <summary>
+    ///     Interaction logic for App.xaml.
+    /// </summary>
+    public partial class App : Application
+    {
+        protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
+        {
+            base.OnSessionEnding(e);
+
+            if (ViewModelMain.Current.BitmapManager.Documents.Any(x => !x.ChangesSaved))
+            {
+                ConfirmationType confirmation = ConfirmationDialog.Show($"{e.ReasonSessionEnding} with unsaved data. Are you sure?", $"{e.ReasonSessionEnding}");
+                e.Cancel = confirmation != ConfirmationType.Yes;
+            }
+        }
+    }
+}

+ 20 - 2
PixiEditor/Models/Dialogs/ConfirmationDialog.cs

@@ -1,10 +1,12 @@
 using PixiEditor.Models.Enums;
 using PixiEditor.Views;
-
+using System;
+
 namespace PixiEditor.Models.Dialogs
 {
     public static class ConfirmationDialog
     {
+        [Obsolete(message: "Use Show(message, title) instead.")]
         public static ConfirmationType Show(string message)
         {
             ConfirmationPopup popup = new ConfirmationPopup
@@ -12,7 +14,23 @@ namespace PixiEditor.Models.Dialogs
                 Body = message,
                 Topmost = true
             };
-            if ((bool)popup.ShowDialog())
+            if (popup.ShowDialog().GetValueOrDefault())
+            {
+                return popup.Result ? ConfirmationType.Yes : ConfirmationType.No;
+            }
+
+            return ConfirmationType.Canceled;
+        }
+
+        public static ConfirmationType Show(string message, string title)
+        {
+            ConfirmationPopup popup = new ConfirmationPopup
+            {
+                Title = title,
+                Body = message,
+                ShowInTaskbar = false
+            };
+            if (popup.ShowDialog().GetValueOrDefault())
             {
                 return popup.Result ? ConfirmationType.Yes : ConfirmationType.No;
             }