From f48160ef7798727007973e81fe33767fcb9c9c6c Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Thu, 12 Dec 2019 19:20:44 -0500 Subject: [PATCH 1/3] fix sample exception --- .../MacWindows/MasterWindowController.cs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/MacWindows/MacWindows/MasterWindowController.cs b/MacWindows/MacWindows/MasterWindowController.cs index a86e4d46..fdf41e71 100644 --- a/MacWindows/MacWindows/MasterWindowController.cs +++ b/MacWindows/MacWindows/MasterWindowController.cs @@ -7,8 +7,7 @@ namespace MacWindows { - public partial class MasterWindowController : NSWindowController - { + public partial class MasterWindowController : NSWindowController, INSWindowDelegate { public MasterWindowController (IntPtr handle) : base (handle) { } @@ -16,15 +15,19 @@ public MasterWindowController (IntPtr handle) : base (handle) public override void WindowDidLoad () { base.WindowDidLoad (); + Window.Delegate = this; + } - Window.DidResize += (sender, e) => { - // Do something as the window is being live resized - }; + [Export ("windowDidResize:")] + public void DidResize (NSNotification notification) + { + throw new System.NotImplementedException (); + } - Window.DidEndLiveResize += (sender, e) => { - // Do something after the user's finished resizing - // the window - }; + [Export ("windowDidEndLiveResize:")] + public void DidEndLiveResize (NSNotification notification) + { + throw new System.NotImplementedException (); } } } From a2abad035edd7e187e524a6c152842aa1eef532f Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Fri, 13 Dec 2019 11:19:14 -0500 Subject: [PATCH 2/3] remove NotImplementedExceptions --- MacWindows/MacWindows/MasterWindowController.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MacWindows/MacWindows/MasterWindowController.cs b/MacWindows/MacWindows/MasterWindowController.cs index fdf41e71..629a7acb 100644 --- a/MacWindows/MacWindows/MasterWindowController.cs +++ b/MacWindows/MacWindows/MasterWindowController.cs @@ -21,13 +21,14 @@ public override void WindowDidLoad () [Export ("windowDidResize:")] public void DidResize (NSNotification notification) { - throw new System.NotImplementedException (); + // Do something as the window is being live resized } [Export ("windowDidEndLiveResize:")] public void DidEndLiveResize (NSNotification notification) { - throw new System.NotImplementedException (); + // Do something after the user's finished resizing + // the window } } } From ec84bf898dd6a20e1c9bf1e13570e6c67acb6df7 Mon Sep 17 00:00:00 2001 From: Whitney Schmidt Date: Fri, 13 Dec 2019 11:38:46 -0500 Subject: [PATCH 3/3] 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 ()