From ec84bf898dd6a20e1c9bf1e13570e6c67acb6df7 Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Fri, 13 Dec 2019 11:38:46 -0500 Subject: [PATCH] fix WillClose event/delegate conflict --- MacWindows/MacWindows/ViewController.cs | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) 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 ()