Re: NEWBIE: preferences - howto?
Re: NEWBIE: preferences - howto?
- Subject: Re: NEWBIE: preferences - howto?
- From: Andrew Zamler-Carhart <email@hidden>
- Date: Wed, 21 Aug 2002 16:31:46 -0700
Brian,
On Wednesday, August 21, 2002, at 03:33 PM, ber wrote:
I'd like to implement a preferences window a la Mail, iChat, etc. You
have a window at the top with icons/titles of the different preference
categories. When you select a category you get the window for that
category. First, is there a common method to implement this style.
Is it a combo box or sheet or drawer of some sort? Secondly is there
some straightforward sample code around. I tried to look at omni's
OAPreferences and although I appreciate the stuff being available I
was overwhelmed in looking at the source or trying to get it to build
(so I could step through it) with 6c115.
Programs like System Preferences, Mail, iChat, and OmniWeb use regular
NSToolbars to let you switch which panel you're looking at.
One approach, and I haven't done this myself, would be to have a
tabless NSTabView with each pane that you would like to show. Each
NSTabViewItem should have a unique identifier. Then, add an NSToolbar
to your window, and create NSToolbarItems with matching identifiers.
Then, set the action of each NSToolbarItem to point to one method in
your PreferencesController object like:
- (void) showPreferencePane: (id) sender {
[tabView selectTabViewItemWithIdentifier: [sender identifier]];
[self updateSize: [self sizeForIdentifier: identifier]]; // more on
this in a second
}
You may want to call [prefsToolbar setAllowsUserCustomization: NO] if
you don't want users to change the options for the toolbar. (OmniWeb
and System Preferences have customizable toolbars, while Mail and iChat
do not.) That's really up to you.
You'll probably want to add a line to resize the window based on the
selected tab view item. This method changes the size of the window's
frame, but keeps the window's upper left hand corner in the same place.
It also does the smooth animation that you want.
- (void) updateSize: (NSSize) newSize {
NSRect oldFrame = [[self window] frame];
int newY = oldFrame.origin.y + oldFrame.size.height -
newSize.height;
[[self window] setFrame: NSMakeRect(oldFrame.origin.x, newY,
newSize.width, newSize.height)
display: YES animate: YES];
}
As for how to implement sizeForIdentifier:, you could hard code the
correct sizes or do something more sophisticated. I don't have a really
elegant implementation for that.
An alternative implementation would be to skip the NSTabView and just
replace the window's content view:
- (void) showPreferencePane: (id) sender {
NSView *view = [self viewForIdentifier: identifier];
[self updateSize: [view frame].size];
[[self window] setContentView: view].
}
In this case, viewForIdentifier: could just return an object from an
NSDictionary of views that were loaded from the same nib file. You must
call updateSize: before calling setContentView:, because the latter
will resize the view to fit the existing frame.
Hope this helps. Email me if you have questions.
Does anybody know how the apps from Apple and OmniGroup mentioned above
implement this behavior?
Andrew
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.