diff --git a/MacWindows/MacWindows/ViewController.cs b/MacWindows/MacWindows/ViewController.cs index 82b68ce3..8cf60d91 100644 --- a/MacWindows/MacWindows/ViewController.cs +++ b/MacWindows/MacWindows/ViewController.cs @@ -5,7 +5,7 @@ namespace MacWindows { - public partial class ViewController : NSViewController + public partial class ViewController : NSViewController, INSWindowDelegate { #region Computed Properties public override NSObject RepresentedObject { @@ -45,6 +45,20 @@ public override void ViewDidLoad () } + [Export ("windowWillClose:")] + public void WillClose (NSNotification notification) + { + // is the window dirty? + if (DocumentEdited) { + var alert = new NSAlert () { + AlertStyle = NSAlertStyle.Critical, + InformativeText = "We need to give the user the ability to save the document here...", + MessageText = "Save Document", + }; + alert.RunModal (); + } + } + public override void ViewWillAppear () { base.ViewWillAppear (); @@ -52,17 +66,7 @@ public override void ViewWillAppear () // Set Window Title this.View.Window.Title = "untitled"; - View.Window.WillClose += (sender, e) => { - // is the window dirty? - if (DocumentEdited) { - var alert = new NSAlert () { - AlertStyle = NSAlertStyle.Critical, - InformativeText = "We need to give the user the ability to save the document here...", - MessageText = "Save Document", - }; - alert.RunModal (); - } - }; + View.Window.Delegate = this; } public override void AwakeFromNib ()