summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2020-07-12 21:39:46 +0000
committerIan C <ianc@noddybox.co.uk>2020-07-12 21:39:46 +0000
commit40a9e8e70ff908ffd59b643d0d399d74d0eda8b8 (patch)
tree2729209d0ec12c8ddde73e3de75290a1622520f2
parent953e5de5bf59c1a453d059fc813cbaf50d8c0f77 (diff)
Added code to check if app should quit.
-rw-r--r--SpriteEd/AppDelegate.cs67
1 files changed, 67 insertions, 0 deletions
diff --git a/SpriteEd/AppDelegate.cs b/SpriteEd/AppDelegate.cs
index 1969e7e..073bfc9 100644
--- a/SpriteEd/AppDelegate.cs
+++ b/SpriteEd/AppDelegate.cs
@@ -49,6 +49,73 @@ namespace SpriteEd
{
}
+ public override NSApplicationTerminateReply ApplicationShouldTerminate(NSApplication sender)
+ {
+ NSApplicationTerminateReply reply = NSApplicationTerminateReply.Cancel;
+ bool changed = false;
+
+ foreach (NSWindow window in NSApplication.SharedApplication.DangerousWindows)
+ {
+ changed = changed || window.DocumentEdited;
+ }
+
+ if (changed)
+ {
+ NSAlert alert = new NSAlert ()
+ {
+ AlertStyle = NSAlertStyle.Critical,
+ InformativeText = "Save changes to document(s) before closing window?",
+ MessageText = "Save Document",
+ };
+
+ alert.AddButton ("Save");
+ alert.AddButton ("Delete");
+ alert.AddButton ("Cancel");
+
+ switch (alert.RunModal())
+ {
+ case 1000:
+ bool saved = true;
+
+ foreach (NSWindow window in NSApplication.SharedApplication.DangerousWindows)
+ {
+ if (window.DocumentEdited)
+ {
+ ViewController view = window.ContentViewController as ViewController;
+
+ if (view.Untitled)
+ {
+ saved = saved && view.SaveAs();
+ }
+ else
+ {
+ saved = saved && view.Save();
+ }
+ }
+ }
+
+ if (saved)
+ {
+ reply = NSApplicationTerminateReply.Now;
+ }
+ break;
+
+ case 1001:
+ reply = NSApplicationTerminateReply.Now;
+ break;
+
+ default:
+ break;
+ }
+ }
+ else
+ {
+ reply = NSApplicationTerminateReply.Now;
+ }
+
+ return reply;
+ }
+
/// <summary>
/// Get the current view controller.
/// </summary>