• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to center pref window once before frame saved in defaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to center pref window once before frame saved in defaults


  • Subject: How to center pref window once before frame saved in defaults
  • From: David Hoerl <email@hidden>
  • Date: Thu, 6 Sep 2007 11:40:03 -0400

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


  • Follow-Ups:
    • Re: How to center pref window once before frame saved in defaults
      • From: Stephane Sudre <email@hidden>
  • Prev by Date: Re: Releasing objects allocated by the NIB
  • Next by Date: NSMutableArray sorting
  • Previous by thread: Re: Releasing objects allocated by the NIB
  • Next by thread: Re: How to center pref window once before frame saved in defaults
  • Index(es):
    • Date
    • Thread