Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cappuccino/cappuccino
Browse files Browse the repository at this point in the history
  • Loading branch information
aparajita committed Apr 22, 2012
2 parents 9830b2b + 7efc823 commit 48ef639
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
7 changes: 7 additions & 0 deletions AppKit/CPCollectionView.j
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,13 @@
indexes = [CPIndexSet indexSetWithIndex:index];

[self setSelectionIndexes:indexes];

// TODO Is it allowable for collection view items to become the first responder? In that case they
// may have become that at this point by virtue of CPWindow's sendEvent: mouse down handling, and
// the following line will rudely snatch it away from them. For most cases though, clicking on an
// item should naturally make the collection view the first responder so that keyboard navigation
// is enabled.
[[self window] makeFirstResponder:self];
}
else if (_allowsEmptySelection)
[self setSelectionIndexes:[CPIndexSet indexSet]];
Expand Down
7 changes: 4 additions & 3 deletions AppKit/CPObjectController.j
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@ var CPObjectControllerContentKey = @"CPObjectControllerCo

- (void)removeObjectAtIndex:(unsigned)anIndex
{
var currentObject = [self objectAtIndex:anIndex];

for (var i = 0, count = [_observationProxies count]; i < count; i++)
{
var proxy = [_observationProxies objectAtIndex:i],
Expand All @@ -588,7 +590,7 @@ var CPObjectControllerContentKey = @"CPObjectControllerCo
if (operator)
[self willChangeValueForKey:keyPath];

[anObject removeObserver:proxy forKeyPath:keyPath];
[currentObject removeObserver:proxy forKeyPath:keyPath];

if (operator)
[self didChangeValueForKey:keyPath];
Expand Down Expand Up @@ -777,8 +779,7 @@ var CPObjectControllerContentKey = @"CPObjectControllerCo
[proxy setNotifyObject:YES];
[_observationProxies addObject:proxy];

// We keep are reference to the observed objects
// because the removeObserver: will be called after the selection changes
// We keep a reference to the observed objects because removeObserver: will be called after the selection changes.
var observedObjects = [_controller selectedObjects];
_observedObjectsByKeyPath[aKeyPath] = observedObjects;
[observedObjects addObserver:proxy forKeyPath:aKeyPath options:options context:context];
Expand Down
35 changes: 35 additions & 0 deletions Tests/AppKit/CPArrayControllerTest.j
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
CPArray _contentArray @accessors(property=contentArray);

CPArray observations;
int aCount @accessors;
}

- (CPArray)makeTestArray
Expand Down Expand Up @@ -289,6 +290,40 @@
[self assertFalse:[[arrayController arrangedObjects] containsObject:objectToRemove] message:@"removed objects should no longer appear in arrangedObjects"];
}

- (void)testRemove_
{
var arrayController = [self arrayController],
objectToRemove = [[arrayController arrangedObjects] objectAtIndex:0];

[arrayController setSelectedObjects:[objectToRemove]];
[arrayController remove:nil];

[self assertFalse:[[arrayController arrangedObjects] containsObject:objectToRemove] message:@"removed objects should no longer appear in arrangedObjects"];
}

- (void)testRemoveObjectsAtArrangedObjectIndexes_
{
var arrayController = [self arrayController];

[arrayController removeObjectsAtArrangedObjectIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(1, 2)]];

[self assert:1 equals:[[arrayController arrangedObjects] count] message:@"objects should be removed"];
}

- (void)testRemoveObjectsAtArrangedObjectIndexes_whenObservingCount
{
var arrayController = [self arrayController];

[arrayController addObserver:self forKeyPath:@"arrangedObjects.name" options:0 context:nil];
[self bind:@"aCount" toObject:arrayController withKeyPath:@"arrangedObjects.@count" options:nil];

// This crashed in a previous version of Cappuccino due to an error in _CPObservableArray's removeObjectAtIndex.
[arrayController removeObjectsAtArrangedObjectIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(1, 2)]];

[self assert:1 equals:[[arrayController arrangedObjects] count] message:@"objects should be removed"];
[self assert:aCount equals:[[arrayController arrangedObjects] count] message:@"count should be updated"];
}

- (void)testSelectionWhenObjectsDisappear
{
// If the selected object disappears during a rearrange, the selection
Expand Down

0 comments on commit 48ef639

Please sign in to comment.