Re: Windows and Default Notification Center
Re: Windows and Default Notification Center
- Subject: Re: Windows and Default Notification Center
- From: Bruce Truax <email@hidden>
- Date: Fri, 23 Jul 2004 12:35:48 -0400
Thanks, I looked in the documentation of NSWindow for these functions but I
missed them.
I agree that the responder chain is the correct way to do this, but I am
having trouble making it work. At the end of my windowDidLoad function in
my NSWindowController I have the following command:
[[self window] makeFirstResponder:self];
And the window controller object contains the processCommandTest function.
In my dialog handler I pass the message to the first responder as follows:
NSApplication *thisApp = [NSApplication sharedApplication];
if ([thisApp respondsToSelector:(SEL)@"processCommandTest"]){
[thisApp tryToPerform:(SEL)@"processCommandTest" with:command];
}
But the respondsToSelector method always returns NO.
Bruce
On 7/23/04 11:57 AM, "Public Look" <email@hidden> eloquently
wrote:
>
From
>
http://developer.apple.com/documentation/Cocoa/Reference/
>
ApplicationKit/ObjC_classic/Classes/NSWindow.html
>
Working with window status
>
>
- windowDidBecomeKey:
>
>
- windowDidBecomeMain:
>
>
- windowDidResignKey:
>
>
- windowDidResignMain:
>
>
However, you problem description suggests you want to use the responder
>
chain (which handles you issue already) instead of notifications.
>
>
On Jul 23, 2004, at 11:08 AM, Bruce Truax wrote:
>
>
> In my Cocoa Document based app my window controller has a method which
>
> handles messages which are sent to the default notification center.
>
> These
>
> messages are typically commands for actions sent by various menu
>
> dialogs.
>
> This method works great when there is one window open but when I have
>
> multiple windows all windows receive the command. This is because each
>
> window controller registers itself as a receiver when it is created.
>
> Obviously I have to manage who receives these messages as windows are
>
> moved
>
> to the front. I was looking for a window or window controller method
>
> which
>
> is called as a window is made the key window but I cannot find one.
>
>
>
>
>
> I register the with the default notification center as follows:
>
>
>
> //register to recieve the ACCommandReady notification sent by the
>
> dialogs
>
>
>
> [[NSNotificationCenter defaultCenter]
>
> addObserver:self
>
> selector:@selector(processCommand:)
>
> name:@"ACCommandReady"
>
> object:nil];
>
>
>
>
>
> I then use the following statements to send a command to the window
>
> controller:
>
>
>
> NSNotificationCenter *defaultCenter;
>
> defaultCenter = [NSNotificationCenter defaultCenter];
>
> [defaultCenter postNotificationName:@"ACCommandReady"
>
> object:command];
>
>
>
>
>
> The processCommand method in the window controller extracts the
>
> command from
>
> the NSNotification object and passes it on to the appropriate handler.
>
>
>
> What is the best way to handle these messages? I assume that somehow I
>
> should be sending the messages to the first responder but I do not see
>
> a way
>
> to pass a message with an argument to the first responder.
>
>
>
> Thanks.
>
>
>
> --
>
> ____________________________________________________________
>
> Bruce E. Truax email: email@hidden
>
> Optical Engineering Consultant
>
>
>
> Diffraction Limited Design LLC
>
> 388 Wedgewood Road voice: 860-276-0450
>
> Southington, CT 06489 fax: 860-620-9026
>
> http://www.dld-llc.com
>
> _____________________________________________________________
>
>
>
> Bruce
>
> _______________________________________________
>
> cocoa-dev mailing list | email@hidden
>
> Help/Unsubscribe/Archives:
>
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
> Do not post admin requests to the list. They will be ignored.
>
>
>
--
____________________________________________________________
Bruce E. Truax email: email@hidden
Optical Engineering Consultant
Diffraction Limited Design LLC
388 Wedgewood Road voice: 860-276-0450
Southington, CT 06489 fax: 860-620-9026
http://www.dld-llc.com
_____________________________________________________________
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.