« Change of location for source code or welcome to the maccode repo | Main | More on the MacCode repo »
February 07, 2007
The weekly cocoa app challenge, week 4
This week, the challenge is, as requested, toolbars.
However, that howto on cocoadevcentral is not going to help you here. Go do that howto, and then come back here.
I'll wait..
waiting...
*launches the xbox 360*
*plays gears of war*
*plays ninety nine nights*
*plays tony hawk project 8*
*switches to the wii*
*plays raving rabids for an hour*
OK, done? Good.
Now it's time to learn the aged old trick of.. that's right. Not doing the hard work when someone has done it already. It's good to learn how to make a toolbar, but once you know how.. it sucks.
So, long story short, this challenge is 2 part:
1 - do the howto from cocoadevcentral. Learn how a toolbar is made programatically.
2 - do it the sane way after that, with generictoolbar
The app I am providing for this challenge is using generictoolbar. The url for the app is here: TwilightToolbar
Also. if you sign up on the Cocoaforge Forums, you will see the hidden Coding and Applescript forums, which can be used to discuss general cocoa, and these challenges.
Good luck!
Oh, and as always, #cocoa on irc.freenode.net can be used to discuss these challenges as well.
Comments
YESSSS!!! Thanks, Chris!
Posted by: John Doe at February 9, 2007 05:54 PM
http://angrymen.org/2007/02/10/weekly-cocoa-app-challenge-4/
I can't say that there's anything special in my solutions for this challenge, but they're there for the sake of completeness.
For anyone else participating, you may find the CocoaDevCentral tutorial linked to be a bit confusing. It heavily uses an NSDictionary named items, and does not explain what it holds. You can download the source at the end of the article to get a better idea, and there's also a very nice tutorial over at the CocoaDev Wiki: http://www.cocoadev.com/index.pl?NSToolbarTutorial
Chris, thanks for continuing this. It's just the sort of kick I need to learn something new about the Cocoa frameworks on a regular basis.
Posted by: Michael Buckley at February 9, 2007 08:01 PM
Here's my entry, it's only part one (for now) I'll do part two if I have time.
I'm a reasonably experienced cocoa developer, though I've been out of touch for a while. I learned NSToolbar the hard way with a fairly complex use of it in one of my apps (basically I used it to implement a tabbed-interface, which worked *really* well).
I love how cocoa implements toolbars. It's a lot of code to get it running (IB integration would be nice), but the end result is extremely flexible and can be *very* fast.
With all the tutorials I've seen, they create all the toolbar items as part of the application's launch process. This is just plain stupid if you ask me. The user will never have all the toolbars in use, and it might even be hidden. In my implementation toolbar items are created as late as possible (when the NSToolbar is about to draw an item to the screen), which reduces memory usage and results in slightly faster launch times (it's only a small improvement, but they add up quickly).
http://aadesign.ausdatahost.com/blog/2007/02/11/wcc-4-part-1/
Posted by: Abhi Beckert at February 11, 2007 01:55 AM
While I can't say the programmatic approach is all that horrible, it is indeed far, far easier to do a toolbar with the generictoolbar framework. Nice to know how to do both, though.
The cocoadevcentral tutorial misses how to use default toolbar items, so I threw a couple into my programmatic approach as well. A bit more useful than a sheet full of "Item ##".
http://myztik.katan.com/?page_id=149
Posted by: Myztik Jenz at February 12, 2007 10:50 AM
I've finally completed this one as well.
I've added a 'show toolbar/hide toolbar' and a 'customize toolbar…' menu item to the window menu (they can be made completely functional in IB, simply connect them to 1st responder's toggleToolbarShown: and runToolbarCustomizationPalette:, 1st responder takes care of the rest. it even swaps 'show toolbar' and 'hide toolbar')
It's great that everybody posts what they did -- I learned a lot by looking at all the solutions (only after I finished my own solution of course :-) ).
Posted by: nico at February 19, 2007 07:35 AM
My attempt:
http://www.blurimage.com/cocoa/TwilightToolbar.zip
Posted by: Carl Foss at February 27, 2007 06:24 AM