In need of some shiny new Cocoa source code? Then allow me to recommend MGScopeBar (which is actually from a project I started months ago, but I’m only just releasing it now so it’s new to you).
MGScopeBar provides a scope/filter bar like you’ll find in Mail, the Finder (in the Find/Spotlight window), iTunes and elsewhere. It requires Mac OS X 10.5 (Leopard) or later, and it looks like this:
It uses a delegate system very much like NSTableView’s data-source, and supports all kinds of snazzy things like optional icons for buttons, an accessory-view at the right side of the bar, button-groups which support single or multiple selection, and more. It also has a very cool feature which I call Smart Resize – take a look at the demo movie to see how it works.
You can get MGScopeBar from my Cocoa Source Code Subversion repository (see below if you don’t know how to do that), and you can find out more about it by reading the ReadMe file.
Lastly, if you’re feeling particularly grateful, may I be so bold as to mention the donation link on my Cocoa source code page and/or my rather nifty iPhone application, Favorites? Yes, I think I may.
How to get code from the Subversion repository
Just launch the Terminal application (it’s in /Applications/Utilities), paste the following command into the window (all on one line) and then press Return:
svn checkout http://svn.cocoasourcecode.com/MGScopeBar ~/Desktop/MGScopeBar
That command will checkout the latest copy of the source into a folder on your Desktop called “MGScopeBar”. The actual name of the folder is up to you, and you can then move that folder anywhere you like.
Whenever you want to update to the latest version of the code thereafter, launch the Terminal application again and use the commands below. Note that there are
two commands, and that they should be pasted into Terminal one at a time, pressing Return after each. Also note that you should obviously change the first command to use the actual path to wherever you’re keeping the code.
cd ~/Desktop/MGScopeBar
svn update
If you want to find out more about Subversion, you can read the
free online Subversion book.
This entry was posted on Tuesday, October 28th, 2008 at 4:48 pm and is filed under Development, Source.
You can follow any comments to this entry through the RSS 2.0 feed.
You can leave a comment, or trackback from your own site.
Tags: bar, filter, finder, itunes, mail, scope
Awesome. I created a class stub for a filter bar in an app I’m working on literally a few days ago, and hopefully this will work well enough that I can drop it right in instead of working on mine. The smart resize feature looks great, far better than what I had planned.
I was planning on modeling mine more after the “flat” look without recessed buttons, similar to the Genius bar in iTunes… any chance MGScopeBar could support that in a future version? Or is there are there any UI rules of thumb that that would violate?
Very nice! I don’t have a use for it right now but I’ll definitely be checking out the code to see how it all fits together.
Delicious is the only possible word to describe this wonderful bit of code =). I’m going to try to do some work on it and see if I can’t control it within PyObjC, should be able to.
Cool!
It looks very amazing
Looks to me like a perfect candidate for Leopard to include into Snow Leopard. Wouldn’t that be swell? Well, not really, since then we wouldn’t have the source. Quick, hide it before Apple finds out!
How much of the code is Leopard only?
I want to use something like this, but I am developing for Tiger and Leopard. Would it be easy to change to work with both?
Hi Matt,
I actually already have a patch here (submitted by a fellow developer) for MGScopeBar which will make it compatible with Tiger. I’ll integrate it and update the code in the subversion repository soon.
Thanks for the info, Matt.
I will check back to see when it is updated.
1). I tried to use it, but it failed compiling at:
_firstCollapsedGroup = NSNotFound; in MGScopeBar.m, giving me overrun errors. I changed it to: _firstCollapsedGroup = nil; //NSNotFound; and it seems fine.
2) Also, the return type of delegate method is NOT int, and hence the compiler complains. I cast the return value to (MGScopeBarGroupSelectionMode), and now it works fine.
I actually tried to integrate it with my APPController, but it kept giving me error at scopeBar.delegate = self; in awakefromnib in MY AppController, saying MGScopeBar class is not found, using nil. I resorted to using your APPController, and its working fine. Now I have to somehow link it with my AppController.
Excellent piece of work. Love it and using it.
Chris
{
HOW HAVE U INTEGRATED DASHCODE and XCODE.
PLEASE COMMENT BCOZ i am finding it difficult to understand
the coding of all your frameworks
Dear Matt;
I have tried your MGScopeBar, but I can’t figure out how to deploy it have a bottom toolbar as in Finder. I noticed you have fixed the window vertical size, but if I change that and instance a MGScopeBar at the bottom margin, when I vertically increase the size of the window the bar will no longer be at the bottom, but stay where it is instead.
This behavior differs from Finder.
Any tip for fixing that.
Regards
Fauze
Fauze,
Read about the autoresizingMask for views in Cocoa; it’s designed to help you do things like that. You can also set that behaviour in the Size tab of the Inspector in Interface Builder. That’s not specific to MGScopeBar; it works for any control in Cocoa.