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: Chad Seldomridge <email@hidden>
- Date: Thu, 6 Sep 2007 17:22:43 -0600
I believe the solution is simple (but I have been known to believe a
great many bizarre things).
First, don't set any auto save name in interface builder.
Second, in awakeFromNib, do this
// Set/Restore window position
[_mainWindow center];
[_mainWindow setFrameAutosaveName:@"MainWindow"];
That should do the trick.
Chad
On Sep 6, 2007, at 12:21 PM, email@hidden wrote:
Message: 4
Date: Thu, 6 Sep 2007 11:40:03 -0400
From: David Hoerl <email@hidden>
Subject: How to center pref window once before frame saved in defaults
To: Cocoa <email@hidden>
Message-ID: <p06240805c305cc8a85c0@[192.168.2.5]>
Content-Type: text/plain; charset="us-ascii" ; format="flowed"
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
This also seems like a hack, but maybe a better hack.
If someone has a better more elegant way of achieving my objective,
I'd love to hear it.
David
_______________________________________________
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