ConnectionKit Leopard Styled Source List Notes

Now that Flow has been announced as Leopard only, I saw it only fitting to style the ConnectionKit-registry backed NSOutlineView datasource with the Leopard standard (see Finder, iTunes, iPhoto, Mail, etc.)

Before and After

Making The Changes

Like the CK registry itself, implementing this is fairly easy, and requires only a few lines of code on your app’s part. Note: Because we are using the native Leopard data cells and delegate methods for the headers, your app must be running on 10.5 for this to work. You must also have at least CK revision 816 or later.

  1. Your NSOutlineView’s “outlineDataColumn” must be of the LeopardSourceListTableColumn class. This subclass is included in the CK framework, so you can just open up Interface Builder, and set it the column’s class from there.
  2. In the same place that you currently configure your OutlineView for CK (awakeFromNib, etc.), you must make the following call:

    [[ConnectionRegistry sharedRegistry] setUsesLeopardStyleSourceList:YES];

    For the sake of consistency, here are the other calls you must make to make full use of CK as your OutlineView backend:

    
    CKHostCell *cell = [[CKHostCell alloc] init];
    NSTableColumn *column = [[oBookmarksOutlineView tableColumns] objectAtIndex:0];
    [cell setFont:[[column dataCell] font]];
    [column setDataCell:cell];
    [cell release];
  3. The final step — the step which explains why this will only work on Leopard systems — is adding the NSOutlineView delegate methods. Here they are below:
    
    - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
    {
        if (outlineView == oBookmarksOutlineView)
        {
            return [[ConnectionRegistry sharedRegistry] itemIsLeopardSourceGroupHeader:item];
        }
        return NO;
    }
    - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item
    {
        if (outlineView == oBookmarksOutlineView && [[ConnectionRegistry sharedRegistry] itemIsLeopardSourceGroupHeader:item])
        {
            return NO;
        }
        return YES;
    }
    

And that’s all there is to it. CK will handle the rest.

Being Dynamic

As pointed out above, you will only be able to use the Leopard style on 10.5 systems. This does not, however, mean your application that supports both Tiger and Leopard cannot dynamically use this. Intrigued?

Simply perform a check of the operating system when calling -setUsesLeopardStyleSourceList:. Example code is below:


SInt32 MacVersion;
BOOL isRunningOnLeopard = NO;
if (Gestalt(gestaltSystemVersionMinor, &MacVersion) == noErr)
{
    isRunningOnLeopard = (MacVersion == 5);
}
[[ConnectionRegistry sharedRegistry] setUsesLeopardStyleSourceList:isRunningOnLeopard];

Feel free to contact me if you have any questions.


About this entry