Re: How to center pref window once before frame saved in defaults
Re: How to center pref window once before frame saved in defaults
- Subject: Re: How to center pref window once before frame saved in defaults
- From: Stephane Sudre <email@hidden>
- Date: Thu, 6 Sep 2007 18:00:44 +0200
On 6 sept. 07, at 17:40, David Hoerl wrote:
I am using a preferences window that is created in code (thanks to
Dave Batton's DBPrefsWindowController package!)
What I would like to do is have the window come up centered the first
time, and from then on save the frame using the saved frame capability
of NSWindow.
My thought was to probe the defaults to see if the frame was set
already, and if not, center the window. However, when you use a saved
frame names of @"foo", it is actually stored in the user preferences
as @"NSWindow Frame foo".
So, my first idea was to create a new string using my frame name, and
probe the defaults with it:
if(![[NSUserDefaults standardUserDefaults] objectForKey: @"NSWindow
Frame foo"]) ...
However, this seems like a real hack. So I had another idea, I'll look
and see if the frame changes after I create the window:
NSString *pos1 = [window stringWithSavedFrame];
[self setWindowFrameAutosaveName:@foo"];
NSString *pos2 = [window stringWithSavedFrame];
if pos1 == pos2 then there was no saved frame so center window
I have a better solution to suggest:
"Don't save the frame of the Preferences window".
This way you will just have to call center on the window after you
created it and then you will have a behavior that's close to Apple's
application. Of course, Apple's applications are not working the same
way as in some applications, if you close the Prefs window and then
display it again, it will be centered on the main screen and with other
applications, it will be shown at the location it was before it got
closed. But at least, in their vast majority, they all center the
window the first time you display it after the application has been
launched.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden