Skip to content

Instantly share code, notes, and snippets.

@antmd
Forked from mikeabdullah/gist:866907
Created April 1, 2014 20:06
Show Gist options
  • Save antmd/9922017 to your computer and use it in GitHub Desktop.
Save antmd/9922017 to your computer and use it in GitHub Desktop.
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5
- (void)didInsertNode:(NSTreeNode *)node;
{
// See if model matches tree state. Leopard gets them out of sync, adding to the model rather than inserting
id object = [node representedObject];
NSIndexPath *indexPath = [node indexPath];
NSUInteger index = [indexPath lastIndex];
NSTreeNode *parent = [node parentNode];
NSMutableArray *objects = [[parent representedObject] mutableArrayValueForKeyPath:
[self childrenKeyPathForNode:parent]];
if ([objects objectAtIndex:index] != object)
{
// Correct model object's index
[objects removeObjectIdenticalTo:object];
[objects insertObject:object atIndex:index];
}
}
- (void)insertObject:(id)object atArrangedObjectIndexPath:(NSIndexPath *)indexPath;
{
[super insertObject:object atArrangedObjectIndexPath:indexPath];
NSTreeNode *node = [[self arrangedObjects] descendantNodeAtIndexPath:indexPath];
OBASSERT([node representedObject] == object);
[self didInsertNode:node];
// Correcting the model may have lost selection
if ([self selectsInsertedObjects]) [self setSelectionIndexPath:indexPath];
}
- (void)moveNodes:(NSArray *)nodes toIndexPath:(NSIndexPath *)startingIndexPath;
{
[super moveNodes:nodes toIndexPath:startingIndexPath];
NSArray *selection = [self selectionIndexPaths];
for (NSTreeNode *aNode in nodes)
{
[self didInsertNode:aNode];
}
[self setSelectionIndexPaths:selection];
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment