Re: Retaining state of windows and panels
Re: Retaining state of windows and panels
- Subject: Re: Retaining state of windows and panels
- From: "Adam R. Maxwell" <email@hidden>
- Date: Sun, 16 Jan 2005 15:05:04 -0800
On Jan 16, 2005, at 14:41, Stéphane Sudre wrote:
On dimanche, janvier 16, 2005, at 10:51 PM, Chad Armstrong wrote:
I would like to be able to retain information of an NSPanel (a
floating palette), such as where the panel is, its size, whether it
is open or not, and have those settings be restored when the
application is opened again. Is there a simple way about doing this,
or is this a more involved procedure on saving the window's (or
panel's) information before the application is closed?
Open or not is to be managed by you and you can do this via
NSUserDefaults.
Position and size can be handled automatically via the Window's name
in InterfaceBuilder or code. I think there's an old (Mac OS X 10.0 or
10.1 era) of Interface Builder which had troubles saving Window's name
but it's been fixed since.
I've had problems with this in a couple of applications under Panther,
but only with floating panels; even if an autosave name was specified
in IB, it didn't seem to work. The following worked for me, though, in
an NSWindowController subclass:
- (void)awakeFromNib{
// register for notifications so we can save the window size and
location
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(saveWindowFrame)
name:NSWindowDidResizeNotification
object:[self window]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(saveWindowFrame)
name:NSWindowDidMoveNotification
object:[self window]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(setWindowFrame)
name:NSWindowDidBecomeKeyNotification
object:[self window]];
}
- (void)saveWindowFrame{
[[self window] saveFrameUsingName:@"MyPanel"];
}
- (void)setWindowFrame{
[[self window] setFrameUsingName:@"MyPanel"];
}
_______________________________________________
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
_______________________________________________
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