CPArrayController now pushes new selections to the bound model for selectionIndexes. Using this, support for selectsInsertedObjects was added.

This commit also fixes a performance problem where calling setSelectionIndexes with a selection equal to the one already active caused a selection update.
This commit is contained in:
Alexander Ljungberg committed 2010-05-26 19:39:42 -04:00
1 parent 6ea2b4e0e2
commit 2b287a85e5
1 file changed
+15 -4
+15 -4
View File
@@ -266,7 +266,7 @@
- (BOOL)setSelectionIndexes:(CPIndexSet)indexes
{
if ([_selectionIndexes isEqual:indexes])
if ([_selectionIndexes isEqualToIndexSet:indexes])
return NO;
if(![indexes count] && _avoidsEmptySelection && [[self arrangedObjects] count])
@@ -282,6 +282,10 @@
[self _selectionDidChange];
[self didChangeValueForKey:@"selectionIndexes"];
// Push back the new selection to the model for selectionIndexes if we have one.
// There won't be an infinite loop because of the equality check above.
[[CPKeyValueBinding getBinding:@"selectionIndexes" forObject:self] reverseSetValueFor:@"selectionIndexes"];
return YES;
}
@@ -356,9 +360,16 @@
{
var pos = [_arrangedObjects insertObject:object inArraySortedByDescriptors:_sortDescriptors];
[self willChangeValueForKey:@"selectionIndexes"];
[_selectionIndexes shiftIndexesStartingAtIndex:pos by:1];
[self didChangeValueForKey:@"selectionIndexes"];
if (_selectsInsertedObjects)
{
[self setSelectionIndex:pos];
}
else
{
[self willChangeValueForKey:@"selectionIndexes"];
[_selectionIndexes shiftIndexesStartingAtIndex:pos by:1];
[self didChangeValueForKey:@"selectionIndexes"];
}
}
else
[self rearrangeObjects];