Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Toolbar Questions

Toolbar Questions
Thread Tools
Syphor
Junior Member
Join Date: Jul 2002
Location: Australia
Status: Offline
Reply With Quote
Oct 11, 2002, 12:56 AM
 
How can I implement in a normal NSToolbar so when a user presses a button a new window will be attached on the toolbar and the old window will close...

like the System preferences
     
bewebste
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status: Offline
Reply With Quote
Oct 11, 2002, 01:18 PM
 
System Preferences doesn't create a new window when switching between preference panes. It just sets the content view of the window, using -[NSWindow setContentView:] and resizes the window to fit the new view.
     
Rickster
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Oct 11, 2002, 04:38 PM
 
See OAPreferencesController in our open-source OmniAppKit framework for an example of how to implement a System Preferences-style toolbar and window.

And actually, if your set of views isn't dynamic (that is, it'll always be the same handful of views), it's even easier: use a tabless NSTabView for the window content, and have your toolbar item actions switch which "tab" is displayed.
( Last edited by Rickster; Oct 11, 2002 at 04:45 PM. )
Rick Roe
icons.cx | weblog
     
Syphor  (op)
Junior Member
Join Date: Jul 2002
Location: Australia
Status: Offline
Reply With Quote
Oct 12, 2002, 06:52 AM
 
This is my ToolBar itmes action:

Code:
- (void)toolbaritemclicked:(NSToolbarItem*)item { [MainWindow setFrame:[CustomView frame] display:YES animate:YES]; [MainWindow setContentView:CustomView]; }
It works... sorta... though when it resizes it resizes to the CustomView size.. which I want... but it resizes with the Toolbar... to the toolbar covers about a 1/4 of the CustomView..

Is there another way of doing this?
     
Angus_D
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Oct 12, 2002, 08:13 AM
 
1) instances should start with a lowercase letter by convention: mainWindow is an instance, whereas MainWindow is a class...

2) You need to determine the height of the toolbar and include that in your rect. Sample code for doing it one way is in OmniAppKit, and Apple's recommended method is available at http://developer.apple.com/techpubs/...barHeight.html
     
Gametes
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status: Offline
Reply With Quote
Jun 5, 2003, 12:45 PM
 
How can I set it so that after a toolbar item is clicked it changes over into a new toolbar item, a la a "stop" button with it's own icon and action. I know how to create the two toolbar items in their entirety, it's just switching them out I'm not sure about.

Thanks
you are not your signature
     
Stevos
Junior Member
Join Date: Jan 2003
Status: Offline
Reply With Quote
Jun 5, 2003, 05:39 PM
 
NSToolbarItem has a few methods:
setImage:, setLabel:, setAction:

I would compare labels, and set things from there.

Just a thought though, instead of two actions, you might want to have just one, and when it's called, check the label of the sender.
Many ways to do this, hope this helped.
swont
     
Rickster
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Jun 5, 2003, 05:42 PM
 
It'd be better to change the icon and label of an existing ToolbarItem via validation than to switch out entire ToolbarItems -- if you do the latter, you'll likely run into problems with the toolbar saving its configuration. For example, in a hypothetical audio/video player app:

Code:
- (BOOL)validateToolbarItem:(NSToolbarItem *)item; { SEL action = [item action]; if (action == @selector(playPause:)) { if ([self isPlaying]) { [item setLabel:@"Pause"]; [item setImage:[NSImage imageNamed:@"PauseButton"]]; } else { [item setLabel:@"Play"]; [item setImage:[NSImage imageNamed:@"PlayButton"]]; } } return YES; // all items always enabled for this simple example }
Rick Roe
icons.cx | weblog
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:08 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,