Skip to content

Commit

Permalink
Mac: Fix some events not firing properly
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Jun 14, 2024
1 parent 827b245 commit ca04643
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/Eto.Mac/Forms/MacBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ObserverHelper : NSObject

public IntPtr ControlHandle { get; set; }

public NSObject Control => Runtime.TryGetNSObject(ControlHandle);
public NSObject Control => Runtime.GetNSObject(ControlHandle);

WeakReference handler;

Expand Down Expand Up @@ -72,20 +72,30 @@ void AddToNotificationCenter()
var c = Control;
if (!hasNotification && c != null)
{
// Console.WriteLine($"Adding notification center observer for {KeyPath}, Handler: {Handler?.GetType()}, Control: {c.GetType()}");
NSNotificationCenter.DefaultCenter.AddObserver(this, selPerformAction, KeyPath, c);
hasNotification = true;
}
else if (!hasNotification)
{
Debug.WriteLine($"WARNING: Could not add notification center observer for {KeyPath}, Handler: {Handler?.GetType()}. {ControlHandle} points to a null object");
}

}

void AddToControl()
{
var c = Control;
if (!hasControl && c != null)
{
//Console.WriteLine ("{0}: 3. Adding observer! {1}, {2}", ((IRef)this.Handler).WidgetID, this.GetType (), Control.GetHashCode ());
// Console.WriteLine($"Adding control observer for {KeyPath}, Handler: {Handler?.GetType()}, Control: {c.GetType()}");
c.AddObserver(this, KeyPath, NSKeyValueObservingOptions.New, IntPtr.Zero);
hasControl = true;
}
else if (!hasNotification)
{
Debug.WriteLine($"WARNING: Could not add control observer for {KeyPath}, Handler: {Handler?.GetType()}. {ControlHandle} points to a null object");
}
}

static readonly IntPtr selRemoveObserverForKeyPath_Handle = Selector.GetHandle("removeObserver:forKeyPath:");
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Mac/Forms/MacView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ public abstract partial class MacView<TControl, TWidget, TCallback> : MacObject<

public virtual IEnumerable<Control> VisualControls => Enumerable.Empty<Control>();

internal override bool DelayRegisterNotificationCenter => true;
internal override bool DelayRegisterNotificationCenter => Widget?.Loaded != true;

protected virtual Size DefaultMinimumSize => Size.Empty;

Expand Down

0 comments on commit ca04643

Please sign in to comment.