Hello,

To react to an event or a notification, there are many ways:

1) (Objective-C way) Add a notification observer to be notified when
the "NSApplicationDidFinishLaunchingNotification" is posted. For
example, in your application controller class, you typically add:

[ObjectiveCMessage("awakeFromNib")]
public void AwakeFromNib()
{
  ...
  NSNotificationCenter.DefaultCenter.AddObserverSelectorNameObject(this,
ObjectiveCRuntime.Selector("appDidFinish:"),
NSApplication.NSApplicationDidFinishLaunchingNotification, null);
  ...
}

[ObjectiveCMessage("applicationDidFinishLaunching:")]
public void ApplicationDidFinishLaunching(NSNotification notification)
{
  // Do whatever is needed
}


2) (Objective-C way) Acts as a delegate and implements the delegate
method "applicationDidFinishLaunching(NSNotification aNotification)".
In Interface Builder, wire your application controller as delegate for
the FileOwner (In the main NIB file, the FileOwner is the
NSApplication). In your application controller, define the delegate
method:

[ObjectiveCMessage("applicationDidFinishLaunching:")]
public void ApplicationDidFinishLaunching(NSNotification notification)
{
  // Do whatever is needed
}


3) (.NET way) Register an event handler for this event. The syntax is
not simple (compared to 1 and 2), but it offers more flexibility and
compile-time security.

[ObjectiveCMessage("awakeFromNib")]
public void AwakeFromNib()
{
  ...
  // The delegate assignment is done through a lambda expression
  // This way, all the events are wired before the delegate is
assigned to the instance
  NSApplication.NSApp.SetDelegate(d => { d.
ApplicationDidFinishLaunchingEvent += ApplicationDidFinishLaunching; }
);
  ...
}

private void ApplicationDidFinishLaunching(NSNotification notification)
{
  // Do whatever is needed
}


(Please note that the above examples are written from memory, so they
may contains some typos.)


Regards, Laurent Etiemble.

2009/9/25 Sebastian P.R. Gingter <[email protected]>:
> Hello,
>
> I have a question that I could not answer by reading the documentation
> or googling after it:
>
> How can I let my code react to a "NSApplicationDidFinishLaunching" event to
> display a sheet as the first action after the window became visible?
>
> There is only a eventhandler, but not event I could subscribe to.
>
> Thanks for your help,
>
>   Sebastian
>

Reply via email to