Re: How a Controller in MainMenu.xib can send actions to a document object
Re: How a Controller in MainMenu.xib can send actions to a document object
- Subject: Re: How a Controller in MainMenu.xib can send actions to a document object
- From: "Michael Ash" <email@hidden>
- Date: Fri, 10 Oct 2008 10:48:46 -0400
On Thu, Oct 9, 2008 at 10:24 PM, Louis Demers <email@hidden> wrote:
> I'm working on a Document Based app
>
> My app has in its MainMenu.xib a controller that monitors a usb devices. I
> want this controller to send actions to the front most document. I tried
> many thing in the archives, including
>
> 1) in my controller in the MainMenu.xib
>
> [[NSApplication sharedApplication] sendAction:@selector(usbEvent:)
> to:(id)nil from:nil]; // From nil because this is just a c procedure
>
> but nothing happens.
>
> 2) in my controller in the MainMenu.xib
>
> [[NSDocumentController sharedDocumentController] currentDocument];
>
> but that always return null
Are you doing this when your application is inactive? For reasons I've
never understood, the key/main windows are only maintained when the
application is active. As such, currentDocument will return nil when
in the background (and is documented to do so) and sending to the
responder chain will, I think, give you greatly foreshortened chain
consisting only of NSApp and delegate.
To work around this, you'll probably want to either walk through the
-orderedWindows array looking for a document window (be sure to write
your code to check them and discard any which aren't document
windows), or listen for NSWindowDidBecomeMainNotification and update
an internal pointer to the main window when it changes.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden