Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
fix WillClose event/delegate conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
whitneyschmidt committed Dec 13, 2019
1 parent a2abad0 commit ec84bf8
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions MacWindows/MacWindows/ViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MacWindows
{
public partial class ViewController : NSViewController
public partial class ViewController : NSViewController, INSWindowDelegate
{
#region Computed Properties
public override NSObject RepresentedObject {
Expand Down Expand Up @@ -45,24 +45,28 @@ 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 ();

// 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 ()
Expand Down

0 comments on commit ec84bf8

Please sign in to comment.