diff options
-rw-r--r-- | SpriteEd/AppDelegate.cs | 67 |
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> |