Skip to content

Commit

Permalink
Fixed crash when windows shutting down or rebooting
Browse files Browse the repository at this point in the history
  • Loading branch information
marce1994 committed Oct 16, 2021
1 parent fafb0f4 commit 8f67a47
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
25 changes: 25 additions & 0 deletions PixiEditor/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
9 changes: 6 additions & 3 deletions PixiEditor/Models/Dialogs/ConfirmationDialog.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,12 +15,12 @@ public static ConfirmationType Show(string message)
Body = message,
Topmost = true
};
if ((bool)popup.ShowDialog())
if (popup.ShowDialog().GetValueOrDefault())
{
return popup.Result ? ConfirmationType.Yes : ConfirmationType.No;
}

return ConfirmationType.Canceled;
}
}
}
}

0 comments on commit 8f67a47

Please sign in to comment.