Previous Entry Add to Memories Share Next Entry
New in Leopard: Source lists!
latest
chanson
One of the great new features in Leopard is a standard way of supporting source lists — those blue outline views with a gradient highlight, like in iTunes, that provide an interface to some collections of objects.

These have become quite common in a lot of applications since their introduction in iTunes, and everybody does them slightly differently. Now, though, there's a simple way for applications running on Leopard to get the source list look and feel almost for free!

There's a new property added to NSTableView called selection highlight style. There are currently two possible values for the highlight style: Normal, the default, which gets you the regular look and feel and selection highlight behavior, and source list, which gets you not just source list-style selection highlighting, but also gets you the proper background color — whether you're in the foreground or the background — and for outline views, will also get you the proper indentation per level, the row height, and inter-cell spacing.

You can even set this property directly on your table or outline view in Interface Builder 3!

Of course, the obvious next question is "How do I get the small-caps look for section headers like in iTunes, Mail, and the Finder?" It's pretty simple! There are just a couple of methods you'll need to implement in your NSOutlineView delegate as described by Jim Puls in this message to the cocoa-dev list on October 26; conceptually, all you need to do is tell the outline view that your header items are group items — another new feature in Leopard — and then, when the cell containing them is displayed, adjust their string to be all-caps.

Not as simple as you make it sound.

schwatoo

2007-10-30 10:48 am (UTC)

*grumble grumble*

As someone who is implementing a Source List using Leopard only I'd like to point out it isn't quite as simple as I'd like it to be.

You miss the issue of not allowing selection of root (capitalized) rows:

- (NSIndexSet *)outlineView:(NSOutlineView *)inOutlineView selectionIndexesForProposedSelection:(NSIndexSet *)inProposedSelectionIndexes
{
NSMutableIndexSet *theIndexSet = [NSMutableIndexSet indexSet];

const NSUInteger kBufferSize = 1024;
NSUInteger theIndexBuffer[kBufferSize];
NSRange theRange = NSMakeRange(0, [inProposedSelectionIndexes lastIndex] + 1);
NSUInteger theCount;

while ((theCount = [inProposedSelectionIndexes getIndexes:theIndexBuffer maxCount:kBufferSize inIndexRange:&theRange]) > 0)
{
for (NSUInteger N = 0; N != theCount; ++N)
{
id theItem = [[outlineView itemAtRow:theIndexBuffer[N]] representedObject];
if (theItem.depth != 1)
[theIndexSet addIndex:theIndexBuffer[N]];
}
}

if ([theIndexSet count] == 0)
{
return([outlineView selectedRowIndexes]);
}

return(theIndexSet);
}

(hope the code pastes ok).

And then the whole selection highlight style only works if your main column is a NSTextCell - if you need anything fancier you're left to rolling your own highlight style.

I'm going to have post the source for a generic (but feature full) 10.5 only Source List class on my blog: http://toxisoftware.com/ in a few days.

Re: Not as simple as you make it sound.

(Anonymous)

2007-10-30 07:20 pm (UTC)

schwatoo! no no no no. You are adding in code that disallows the user from selecting the section titles. Don't do that! It isn't done in the Open and Save Panel. It is done in Finder and Mail, however, it *should* be allowed there. The reasons: for type selection and keyboard access to collapse/expand items. >>>And then the whole selection highlight style only works if your main column is a NSTextCell - if you need anything fancier you're left to rolling your own highlight style. Again, no! It works great if your cells don't draw a background. Exactly what are you having trouble with? -corbin (the implementor).

Re: Not as simple as you make it sound.

(Anonymous)

2007-10-30 07:22 pm (UTC)

I should also mention, should you *really* want to disallow selecting the section titles, you can use:

- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item {
return [outlineView parentForItem:item] == nil;
}

Don't use the method you specified. It is faster for multiple selection items, but source lists shouldn't allow multiple selection (in general), and isn't the same issue.

corbin

Re: Not as simple as you make it sound.

schwatoo

2007-10-30 07:49 pm (UTC)

Hmmm.

Well lacking an updated HIG (*cough*) I'm not really sure which L&F to follow now. It would be really nice if this issue was made consistent. I'll probably provide a flag to make it optional anyway.

I have a custom NSTextCell that I'm using in my source list that overrides the drawInterior, this must be why I have to handle the drawing myself. I'll try and find a why to get rid of the custom NSTextCell .

Re: Not as simple as you make it sound.

(Anonymous)

2007-10-30 09:40 pm (UTC)

Yes; we do need an updated HIG. Please do take the time to log bugs requesting this!

Your custom NSTextCell - be sure to not draw a background and it should work. The DragNDropOutineView example can have the source list style applied to it, and it works great (and has a custom cell!). Check it out.


You say "It isn't done in the Open and Save Panel," but I am unable to select section titles in a Safari save panel or Finder. What did you mean?

new proper is their architectural textile. coach outlet, on the mismatched of shopping centers, are ofttimes physique maturation due to small towns, blot out streets, seats, alleys, and burberry outlets shops along the roads and streets. Their invent is powerfully contrasting than banal malls, which are closed spaces, salt away garish rap reaching apparent of the louis vuitton outlets speakers and neon dazzling that could busted up somebody’s perceiving. Lately populous outlet stores accredit been developed according to coach outlets specific regional architectural themes, through unfolding some of them adopted a neoclassical burberry outlet fairness monopoly Veneto, the accommodate where the esteemed neoclassical sculptor Canova was born, or they conceive been realized inventive by the Renaissance style guidance Tuscany. These solutions impel the environment immensely additional louis vuitton outlet pleasant, accordingly is immeasurably more easy to march uncherished its alleys, mastery comparison to gain spaces keep from no windows of homely shopping centers.