Re: Re : Newbie Q: equipping an NSDocument subclass with a window controller (2)
Re: Re : Newbie Q: equipping an NSDocument subclass with a window controller (2)
- Subject: Re: Re : Newbie Q: equipping an NSDocument subclass with a window controller (2)
- From: Sherm Pendley <email@hidden>
- Date: Wed, 12 Oct 2005 14:24:44 -0400
On Oct 12, 2005, at 1:05 PM, email@hidden wrote:
Is BlueWindow a subclass of NSDocument? If so, that is *not* how you
create a new NSDocument.
er, how is it done then ? I used to have a connection between a "Blue
Window" button and this (void) (IBAction, actually) showBlueWindow
method. What
should I have connected that button to instead ?
Are you certain that what you need to do is create a new document? It
sounds to me like you want to create and display a new window, and
associate it with an already-open document.
You mentioned earlier, that you want to connect outlets in your Nib
to your document object - so I'm assuming there could be many of
these "Blue Windows", one for each document. Otherwise, such
connections wouldn't make sense.
If you want the window to be shown immediately when a new document is
created, just create and add it in -makeWindowControllers like I
mentioned earlier.
If you don't want this window to appear when a new document is
created, don't create it in -makeWindowControllers. Instead, move
your -showBlueWindow: method to your NSDocument subclass, and connect
that menu item to First Responder.
Your -showBlueWindow: method might look something like this:
- (void) showBlueWindow: (id)sender {
NSWindowController *c;
// First check for an existing controller for BlueWindow.nib
NSEnumerator *e = [[self windowControllers] objectEnumerator];
while (c = [e nextObject]) {
if ([[c windowNibName] isEqualToString:@"BlueWindow"]) break;
}
// If none was found, create one and add it
if (nil == c) {
c = [[[NSWindowController alloc]
initWithWindowNibName:@"BlueWindow" owner:self] autorelease];
[self addWindowController:c];
}
// Whether it was newly created or not, show it
[c showWindow:sender];
}
The general flow is, NSDocumentManager creates a new NSDocument, and
then the NSDocument creates and manages its own NSWindowControllers.
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden