mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-14 02:33:50 +00:00
Fixed: CPTreeController selection bug for asynchronously loaded nodes
This commit is contained in:
1 parent
e0e16eeca5
commit
79a9ae31d3
1 file changed
+65
@@ -285,6 +285,68 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void)_ensureTreeNodesExistForIndexPaths:(CPArray)indexPaths
|
||||
{
|
||||
if (!_childrenKeyPath)
|
||||
return;
|
||||
|
||||
var count = [indexPaths count];
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var path = [indexPaths objectAtIndex:i];
|
||||
var length = [path length];
|
||||
var currentNode = [self arrangedObjects];
|
||||
|
||||
for (var j = 0; j < length; j++)
|
||||
{
|
||||
var index = [path indexAtPosition:j];
|
||||
|
||||
var obj = [currentNode representedObject];
|
||||
var expectedChildObjects = nil;
|
||||
|
||||
if (!obj && currentNode === [self arrangedObjects])
|
||||
expectedChildObjects = [self contentArray];
|
||||
else if (obj)
|
||||
expectedChildObjects = [obj valueForKeyPath:_childrenKeyPath];
|
||||
|
||||
if (expectedChildObjects)
|
||||
{
|
||||
var childNodes = [currentNode mutableChildNodes];
|
||||
var needsRebuild = NO;
|
||||
|
||||
if (!childNodes || [childNodes count] !== [expectedChildObjects count])
|
||||
{
|
||||
needsRebuild = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var k = 0, kCount = [childNodes count]; k < kCount; k++)
|
||||
{
|
||||
if ([[childNodes objectAtIndex:k] representedObject] !== [expectedChildObjects objectAtIndex:k])
|
||||
{
|
||||
needsRebuild = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (needsRebuild)
|
||||
{
|
||||
[childNodes removeAllObjects];
|
||||
var newNodes = [self _buildTreeNodesForObjects:expectedChildObjects];[childNodes addObjectsFromArray:newNodes];
|
||||
}
|
||||
}
|
||||
|
||||
var children = [currentNode childNodes];
|
||||
if (children && index < [children count])
|
||||
currentNode = [children objectAtIndex:index];
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)__setSelectionIndexPaths:(CPArray)indexPaths avoidEmpty:(BOOL)avoidEmpty
|
||||
{
|
||||
var newPaths = indexPaths;
|
||||
@@ -292,6 +354,9 @@
|
||||
if (!newPaths)
|
||||
newPaths = [CPArray array];
|
||||
|
||||
if ([newPaths count] > 0)
|
||||
[self _ensureTreeNodesExistForIndexPaths:newPaths];
|
||||
|
||||
if (![newPaths count] && avoidEmpty)
|
||||
{
|
||||
if ([[[self arrangedObjects] childNodes] count] > 0)
|
||||
|
||||
Reference in new issue
Block a user