mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-21 14:09:22 +00:00
Improved KVC mutable indexed accessors
Refactored everything away into insertObjects:atIndexes: so all the logic is in the same place and made it so that the _insertManySEL is the preferred selector to use. If it doesn't exist it will fall back to the _insertSEL.
This commit is contained in:
1 parent
c9752195ac
commit
b21eab1bf1
1 file changed
+28
-14
+28
-14
@@ -120,7 +120,7 @@
|
||||
|
||||
_insertManySEL = sel_getName(@"insertObjects:in"+capitalizedKey+"AtIndexes:");
|
||||
if ([_proxyObject respondsToSelector:_insertManySEL])
|
||||
_insert = [_proxyObject methodForSelector:_insertManySEL];
|
||||
_insertMany = [_proxyObject methodForSelector:_insertManySEL];
|
||||
|
||||
_removeManySEL = sel_getName(@"removeObjectsFrom"+capitalizedKey+"AtIndexes:");
|
||||
if ([_proxyObject respondsToSelector:_removeManySEL])
|
||||
@@ -234,13 +234,7 @@
|
||||
|
||||
- (void)addObject:(id)anObject
|
||||
{
|
||||
if (_insert)
|
||||
return _insert(_proxyObject, _insertSEL, anObject, [self count]);
|
||||
|
||||
var target = [[self _representedObject] copy];
|
||||
|
||||
[target addObject:anObject];
|
||||
[self _setRepresentedObject:target];
|
||||
[self insertObject:anObject atIndex:[self count]];
|
||||
}
|
||||
|
||||
- (void)addObjectsFromArray:(CPArray)anArray
|
||||
@@ -249,18 +243,38 @@
|
||||
count = [anArray count];
|
||||
|
||||
for (; index < count; ++index)
|
||||
[self addObject:[anArray objectAtIndex:index]];
|
||||
[self insertObject:[anArray objectAtIndex:index] atIndex:index];
|
||||
}
|
||||
|
||||
- (void)insertObject:(id)anObject atIndex:(unsigned)anIndex
|
||||
{
|
||||
if (_insert)
|
||||
return _insert(_proxyObject, _insertSEL, anObject, anIndex);
|
||||
[self insertObjects:[anObject] atIndexes:[CPIndexSet indexSetWithIndex:anIndex]];
|
||||
}
|
||||
|
||||
var target = [[self _representedObject] copy];
|
||||
- (void)insertObjects:(CPArray)theObjects atIndexes:(CPIndexSet)theIndexes
|
||||
{
|
||||
if (_insertMany)
|
||||
_insertMany(_proxyObject, _insertManySEL, theObjects, theIndexes);
|
||||
else if (_insert)
|
||||
{
|
||||
var indexesArray = [];
|
||||
[theIndexes getIndexes:indexesArray maxCount:-1 inIndexRange:nil];
|
||||
|
||||
[target insertObject:anObject atIndex:anIndex];
|
||||
[self _setRepresentedObject:target];
|
||||
for (var index = 0; index < [indexesArray count]; index++)
|
||||
{
|
||||
var objectIndex = [indexesArray objectAtIndex:index],
|
||||
object = [theObjects objectAtIndex:index];
|
||||
|
||||
_insert(_proxyObject, _insertSEL, object, objectIndex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var target = [[self _representedObject] copy];
|
||||
|
||||
[target insertObjects:theObjects atIndexes:theIndexes];
|
||||
[self _setRepresentedObject:target];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeObject:(id)anObject
|
||||
|
||||
Reference in new issue
Block a user