Re: What's wrong with having multiple windows per document in only one nib?
Re: What's wrong with having multiple windows per document in only one nib?
- Subject: Re: What's wrong with having multiple windows per document in only one nib?
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 14 Aug 2005 18:45:24 -0400
on 2005-08-14 11:35 AM, Stephane Sudre at email@hidden wrote:
> When you look at the different tutorials, documents on multiple windows
> per NSDocument, the recommended solution is to have multiple nibs (one
> per window) and one controller per window.
>
> When making tests, this just work but not as I wish to. When you create
> or open a document, all the windows (main and secondaries) are
> displayed. This is not what I would like.
>
> Basically, I'm trying to add a build window (as in Xcode or Project
> Builder) per document.
>
> When making tests, with one nib per document and 2 windows per document
> (one for the document window), I'm apparently getting the proper result:
>
> - the secondary window is not displayed by default.
> - the secondary window is closed when the main document window is
> closed.
> - there's one secondary window per document.
>
> Is there something wrong going this way instead of the recommended one?
If it works for you, do it. The only downside I see is that your window
controller will be more complicated than it needs to be.
All of the problems you cite with respect to multiple nibs are easily
overcome when using multiple nibs and multiple window controllers, and you
gain the benefit of a simpler window controller for each separate window.
Here's some of what I do, in an app where the main document window is a
button bar that opens two other windows. All three windows have separate
nibs and separate window controllers. Only the button bar is opened by
default when the document is opened, and the two secondary windows close
automatically when the button bar window is closed. Only one of each of the
three windows is allowed per document.
***** From my document subclass:
#pragma mark ACCESSOR METHODS
- (WRMainWindowController *)mainWindowController {
// Opens only one main window on a given document.
if (mainWindowController == nil) {
mainWindowController = [[WRMainWindowController alloc] init];
}
return mainWindowController;
}
- (WRPersonWindowController *)personWindowController {
// Opens only one persons window on a given document.
if (personWindowController == nil) {
personWindowController = [[WRPersonWindowController alloc] init];
}
[self addWindowController:personWindowController]; // sets persons
window controller's -document accessor, if not already set
return personWindowController;
}
- (WRCompanyWindowController *)companyWindowController {
// Opens only one companies window on a given document.
if (companyWindowController == nil) {
companyWindowController = [[WRCompanyWindowController alloc] init];
}
[self addWindowController:companyWindowController]; // sets companies
window controller's -document accessor, if not already set
return companyWindowController;
}
#pragma mark WINDOW MANAGEMENT
- (void)makeWindowControllers {
// NSDocument automatically shows the window.
[self addWindowController:[self mainWindowController]]; // sets main
window controller's -document accessor, if not already set
}
***** From my main window controller subsclass:
#pragma mark INITIALIZATION
- (id)init {
self = [super initWithWindowNibName:MAIN_WINDOW_NIB_NAME];
if (self != nil) {
[self setShouldCloseDocument:YES];
}
return self;
}
#pragma mark ACTION METHODS
// Actions to create window controllers, load their nibs, and open their
windows.
- (IBAction)showPersonWindow:(id)sender {
// Only one persons window can be open on a given document.
[[[self document] personWindowController] showWindow:sender];
}
- (IBAction)showCompanyWindow:(id)sender {
// Only one companies window can be open on a given document.
[[[self document] companyWindowController] showWindow:sender];
}
***** From one of my secondary window controller subclasses:
#pragma mark INITIALIZATION
- (id)init {
self = [super initWithWindowNibName:PERSON_NIB_NAME];
if (self != nil) {
// initialization
}
return self;
}
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
PreFab Software - http://www.prefab.com/scripting.html
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
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