diff --git a/AppKit/CPTreeNode.j b/AppKit/CPTreeNode.j index 8d679da20..c54959376 100644 --- a/AppKit/CPTreeNode.j +++ b/AppKit/CPTreeNode.j @@ -87,6 +87,18 @@ [_childNodes[count] sortWithSortDescriptors:sortDescriptors recursively:YES]; } +- (CPTreeNode)descendantNodeAtIndexPath:(CPIndexPath)indexPath +{ + var count = [indexPath length], + node = self; + + for(var i = 0; i < count; i++) { + node = [node objectInChildNodesAtIndex:[indexPath indexAtPosition:i]]; + } + + return node; +} + @end var CPTreeNodeRepresentedObjectKey = @"CPTreeNodeRepresentedObjectKey", diff --git a/Tests/AppKit/CPTreeNodeTest.j b/Tests/AppKit/CPTreeNodeTest.j new file mode 100644 index 000000000..27990d37d --- /dev/null +++ b/Tests/AppKit/CPTreeNodeTest.j @@ -0,0 +1,28 @@ + +@import + + +@implementation CPTreeNodeTest : OJTestCase +{ + CPTreeNode treeNode; + CPTreeNode childNode; +} + +- (void)setUp +{ + treeNode = [CPTreeNode treeNodeWithRepresentedObject:nil]; + + childNode = [CPTreeNode treeNodeWithRepresentedObject:nil]; + [treeNode insertObject:childNode inChildNodesAtIndex:0]; +} + +- (void)testDescendantNodeAtIndexPath +{ + var indexPath = [CPIndexPath indexPathWithIndex:0]; + [self assert:childNode equals:[treeNode descendantNodeAtIndexPath:indexPath]]; + + indexPath = [CPIndexPath indexPathWithIndex:1]; + [self assert:nil equals:[treeNode descendantNodeAtIndexPath:indexPath]]; +} + +@end