mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-01 10:52:03 +00:00
Fixed: CPArrayController's addObject and CPArray's insertObject:inArraySortedByDescriptors:.
CPArray insertObject:inArraySortedByDescriptors: now quickly inserts objects at the end of the array if no sort descriptors are specified. CPArrayController initialises its sort descriptors to an empty array. Fixed: array controller's addObject added objects to the arranged objects array in a different order than in the content array if no sort descriptor was set.
This commit is contained in:
1 parent
2af2fc31a1
commit
8ef7f07195
3 files changed
+42
-11
No files matched your search
@@ -108,6 +108,7 @@
|
||||
|
||||
if (self)
|
||||
{
|
||||
_sortDescriptors = [CPArray array];
|
||||
_selectionIndexes = [CPIndexSet indexSet];
|
||||
}
|
||||
|
||||
|
||||
+17
-11
@@ -1067,22 +1067,28 @@ CPEnumerationReverse = 1 << 1;
|
||||
|
||||
- (unsigned)insertObject:(id)anObject inArraySortedByDescriptors:(CPArray)descriptors
|
||||
{
|
||||
var count = [descriptors count];
|
||||
var count = [descriptors count],
|
||||
index;
|
||||
|
||||
var index = [self _indexOfObject:anObject sortedByFunction:function(lhs, rhs)
|
||||
if (count)
|
||||
{
|
||||
var i = 0,
|
||||
result = CPOrderedSame;
|
||||
index = [self _indexOfObject:anObject sortedByFunction:function(lhs, rhs)
|
||||
{
|
||||
var i = 0,
|
||||
result = CPOrderedSame;
|
||||
|
||||
while (i < count)
|
||||
if ((result = [descriptors[i++] compareObject:lhs withObject:rhs]) != CPOrderedSame)
|
||||
return result;
|
||||
while (i < count)
|
||||
if ((result = [descriptors[i++] compareObject:lhs withObject:rhs]) != CPOrderedSame)
|
||||
return result;
|
||||
|
||||
return result;
|
||||
} context:nil];
|
||||
return result;
|
||||
} context:nil];
|
||||
|
||||
if (index < 0)
|
||||
index = -index - 1;
|
||||
if (index < 0)
|
||||
index = -index - 1;
|
||||
}
|
||||
else
|
||||
index = self.length;
|
||||
|
||||
[self insertObject:anObject atIndex:index];
|
||||
return index;
|
||||
|
||||
@@ -92,6 +92,30 @@
|
||||
[self assert:[CPIndexSet indexSetWithIndex:count - 1] equals:[arrayController selectionIndexes]];
|
||||
}
|
||||
|
||||
/*
|
||||
Verify that the arranged objects ordering is correct versus the content array when objects are added with addObject and no sort descriptors are set.
|
||||
*/
|
||||
- (void)testAddObjects
|
||||
{
|
||||
_arrayController = [[CPArrayController alloc] init];
|
||||
var content = [];
|
||||
[_arrayController setContent:content];
|
||||
|
||||
[_arrayController addObject:[CPNumber numberWithInt:1]];
|
||||
[_arrayController addObject:[CPNumber numberWithInt:2]];
|
||||
|
||||
[self assert:[CPNumber numberWithInt:1] equals:content[0]];
|
||||
[self assert:[CPNumber numberWithInt:2] equals:content[1]];
|
||||
|
||||
[self assert:[CPNumber numberWithInt:1] equals:[_arrayController arrangedObjects][0] message:"arranged objects should be in the correct order"];
|
||||
[self assert:[CPNumber numberWithInt:2] equals:[_arrayController arrangedObjects][1] message:"arranged objects should be in the correct order"];
|
||||
|
||||
[_arrayController rearrangeObjects];
|
||||
|
||||
[self assert:[CPNumber numberWithInt:1] equals:[_arrayController arrangedObjects][0]];
|
||||
[self assert:[CPNumber numberWithInt:2] equals:[_arrayController arrangedObjects][1]];
|
||||
}
|
||||
|
||||
- (void)testRemoveObjects
|
||||
{
|
||||
var arrayController = [self arrayController];
|
||||
|
||||
Reference in new issue
Block a user