Re: Single instance of properties window
Re: Single instance of properties window
- Subject: Re: Single instance of properties window
- From: Sherm Pendley <email@hidden>
- Date: Mon, 3 Oct 2005 13:49:21 -0400
On Oct 3, 2005, at 9:10 AM, Derrick Bass wrote:
I have a document based program and I implemented a properties
window (it is supposed to work much like the properties window in
QuickTime player).
When the user chooses "Show Info" the "showInfo:" action of my
document class does the following:
NSWindowController* controller;
controller = [[NSWindowController alloc]
initWithWindowNibName:@"Properties" owner:self];
[controller setShouldCloseDocument:NO];
[self addWindowController: controller];
[controller showWindow:self];
[controller release];
The trouble comes if the user chooses "Show Info" again… I get
another instance of the properties window! What I want, of course,
is for the currently open info window to pop forward. Is there some
easy way to do that?
Create an NSWindowController subclass that has a class method to
return a shared instance:
+ (id) sharedPropertiesController {
static MyPropertiesController *controller;
if (nil == controller) {
controller = [[MyPropertiesController alloc]
initWithWindowNibName:@"Properties" owner:self];
}
return controller;
}
Note that this controller, since it's shared instead of being
associated with a single document, should *not* be owned by an
NSDocument instance. In your document class, you'd do something like
this to show it:
[[MyPropertiesController sharedPropertiesController]
showWindow:self];
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