Cocoa: Sidebar with Badges
December 2, 2008 Matteo Bertozzi | Filed Under Cocoa | 8 CommentsYesterday, I’ve written a simple Sidebar controller that can saves you some time and trouble with Cocoa Source List. Nodes and Folders can be drag and dropped into other folders or near other items and you can easily set badges on nodes.
You can find the example Source Code Here.
And below you can see hot to add folders, nodes and set badges.
- (void)populateOutlineContents:(id)inObject {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[sidebar addRootFolder:@"1" name:@"DEVICES"];
[sidebar addChild:@"1.1" name:@"Machintosh HD"
icon:[NSImage imageNamed:NSImageNameComputer]
action:@selector(buttonPres:) target:self];
[sidebar addRootFolder:@"2" name:@"PLACES"];
[sidebar addChild:@"2.1"
url:NSHomeDirectory()
action:@selector(buttonPres:) target:self];
[sidebar addRootFolder:@"3" name:@"OTHER."];
[sidebar addChild:@"3.1" name:@"Bonjour"
icon:[NSImage imageNamed:NSImageNameBonjour]
action:@selector(buttonPres:) target:self];
[sidebar addChild:@"3.2" name:@"Users"
icon:[NSImage imageNamed:NSImageNameUserGroup]
action:@selector(buttonPres:) target:self];
[sidebar clearSelection];
// Add Badge to Node with Key
[sidebar setBadge:@"2.1" count:5];
[sidebar setBadge:@"3.2" count:7];
[pool release];
}
- (void)buttonPres:(id)sender {
NSLog(@"Button Press %@", [sender nodeTitle]);
}

thanks for your sidebar. It will be very usefull for my next app. Keep this way
Comment by Pierre — March 4, 2009 #
[...] Do you remember the Cocoa Sidebar? No, Take a Look at this post Cocoa Sidebar with Badges. [...]
Pingback by Cocoa: Sidebar with Badges, Take 2 | Th30z - Coding on the Fly — March 8, 2009 #
Really cool, thanks a lot.
Comment by Seb — March 16, 2009 #
How can you do this in Qt 4?
Comment by salvador — March 20, 2009 #
Take a look at this source code http://qt-apps.org/content/show.php/QfMacNavBar?content=78749
Comment by Matteo Bertozzi — March 20, 2009 #
Hello,
SideBar is very useful and really amazing.
I noticed a drawing problem during live-resize. Adding this method to the sideBar class seems to solve the problem.
- (void)drawRect:(NSRect)aRect {
[super drawRect:aRect];
}
Great Work !!
Comment by Lexxis — March 28, 2009 #
Any plans on make a framekwork plus a Interface Builder plugin?
Comment by johan — April 21, 2009 #
Hi, it’s very good job. But how to edit the “normal” item ?
Comment by wisky — August 27, 2009 #