Browse Source

Fixed crash when windows shutting down or rebooting

pablo 3 years ago
parent
commit
8f67a47251
2 changed files with 31 additions and 3 deletions
  1. 25 0
      PixiEditor/App.xaml.cs
  2. 6 3
      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.Cancel = (confirmation == ConfirmationType.Canceled || confirmation == ConfirmationType.No);
+            }
+        }
+    }
+}

+ 6 - 3
PixiEditor/Models/Dialogs/ConfirmationDialog.cs

@@ -1,6 +1,9 @@
 using PixiEditor.Models.Enums;
 using PixiEditor.Views;
-
+using System;
+using System.IO;
+using System.Windows;
+
 namespace PixiEditor.Models.Dialogs
 {
     public static class ConfirmationDialog
@@ -12,12 +15,12 @@ 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;
-        }
+        }
     }
 }