Created
January 17, 2010 05:24
-
-
Save bkyle/279215 to your computer and use it in GitHub Desktop.
Wil Shipley's NSOutlineView (DMExtensions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NSOutlineView-DMExtensions.h | |
// Library | |
// | |
// Created by William Shipley on 3/10/06. | |
// Copyright 2006 Delicious Monster Software, LLC. Some rights reserved, | |
// see Creative Commons license on wilshipley.com | |
#import <Cocoa/Cocoa.h> | |
@interface NSOutlineView (DMExtensions) | |
- (id)realItemForOpaqueItem:(id)opaqueItem; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NSOutlineView-DMExtensions.m | |
// Library | |
// | |
// Created by William Shipley on 3/10/06. | |
// Copyright 2006 Delicious Monster Software, LLC. Some rights reserved, | |
// see Creative Commons license on wilshipley.com | |
#import "NSOutlineView-DMExtensions.h" | |
@interface NSOutlineView (DMExtensions_Private) | |
- (NSTreeController *)_treeController; | |
- (id)_realItemForOpaqueItem:(id)findOpaqueItem outlineRowIndex:(int *)outlineRowIndex | |
items:(NSArray *)items; | |
@end | |
@implementation NSOutlineView (DMExtensions) | |
- (id)realItemForOpaqueItem:(id)opaqueItem | |
{ | |
int outlineRowIndex = 0; | |
return [self _realItemForOpaqueItem:opaqueItem outlineRowIndex:&outlineRowIndex | |
items:[[self _treeController] content]]; | |
} | |
@end | |
@implementation NSOutlineView (DMExtensions_Private) | |
- (NSTreeController *)_treeController; | |
{ | |
return (NSTreeController *)[[self infoForBinding: @"content"] | |
objectForKey:@"NSObservedObject"]; | |
} | |
- (id)_realItemForOpaqueItem:(id)findOpaqueItem outlineRowIndex:(int *)outlineRowIndex | |
items:(NSArray *)items; | |
{ | |
unsigned int itemIndex; | |
for (itemIndex = 0; itemIndex < [items count] && *outlineRowIndex < [self numberOfRows]; itemIndex++) { | |
id realItem = [items objectAtIndex:itemIndex]; | |
id opaqueItem = [self itemAtRow:*outlineRowIndex]; | |
(*outlineRowIndex)++; | |
if (opaqueItem == findOpaqueItem) { | |
ZNExit; | |
return realItem; | |
} | |
if ([self isItemExpanded:opaqueItem]) { | |
realItem = [self _realItemForOpaqueItem:findOpaqueItem outlineRowIndex: outlineRowIndex | |
items:[realItem valueForKeyPath:[[self _treeController] childrenKeyPath]]]; | |
if (realItem) { | |
return realItem; | |
} | |
} | |
} | |
return nil; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment