Permalink
Browse files

Bulk deselecting should now only trigger the collectionViewDidChangeS…

…election once
  • Loading branch information...
1 parent 0dc4e54 commit 801f865eded0dbb4445da5b08722fd7a6c121914 @pieteromvlee pieteromvlee committed Oct 23, 2011
Showing with 15 additions and 6 deletions.
  1. +4 −0 BCCollectionView+Mouse.m
  2. +1 −0 BCCollectionView.h
  3. +10 −6 BCCollectionView.m
View
@@ -41,6 +41,10 @@ - (void)mouseDown:(NSEvent *)theEvent
else if ([NSEvent modifierFlags] & NSShiftKeyMask) {
NSInteger one = [[self originalSelectionIndexes] lastIndex];
NSInteger two = index;
+
+ if (index == NSNotFound)
+ return;
+
if (two > one)
[self selectItemsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(MIN(one,two), 1+MAX(one,two)-MIN(one,two))]];
else
View
@@ -66,6 +66,7 @@
- (void)selectItemsAtIndexes:(NSIndexSet *)indexes;
- (void)deselectItemAtIndex:(NSUInteger)index;
+- (void)deselectItemAtIndex:(NSUInteger)index inBulk:(BOOL)bulk;
- (void)deselectItemsAtIndexes:(NSIndexSet *)indexes;
- (void)deselectAllItems;
- (NSIndexSet *)selectionIndexes;
View
@@ -164,8 +164,6 @@ - (void)delegateDidDeselectItemAtIndex:(NSUInteger)index
[delegate collectionView:self
didDeselectItem:[contentArray objectAtIndex:index]
withViewController:[self viewControllerForItemAtIndex:index]];
-
- [self delegateCollectionViewSelectionDidChange];
}
- (void)delegateViewControllerBecameInvisibleAtIndex:(NSUInteger)index
@@ -386,11 +384,18 @@ - (void)selectItemsAtIndexes:(NSIndexSet *)indexes
- (void)deselectItemAtIndex:(NSUInteger)index
{
+ [self deselectItemAtIndex:index inBulk:NO];
+}
+
+- (void)deselectItemAtIndex:(NSUInteger)index inBulk:(BOOL)bulkDeselecting
+{
if (index < [contentArray count]) {
[selectionIndexes removeIndex:index];
if ([self shoulDrawSelections])
[self setNeedsDisplayInRect:[layoutManager rectOfItemAtIndex:index]];
+ if (!bulkDeselecting)
+ [self delegateCollectionViewSelectionDidChange];
[self delegateDidDeselectItemAtIndex:index];
[self delegateUpdateDeselectionForItemAtIndex:index];
}
@@ -399,15 +404,14 @@ - (void)deselectItemAtIndex:(NSUInteger)index
- (void)deselectItemsAtIndexes:(NSIndexSet *)indexes
{
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
- [self deselectItemAtIndex:idx];
+ [self deselectItemAtIndex:idx inBulk:YES];
}];
+ [self delegateCollectionViewSelectionDidChange];
}
- (void)deselectAllItems
{
- [selectionIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
- [self deselectItemAtIndex:idx];
- }];
+ [self deselectItemsAtIndexes:selectionIndexes];
}
- (NSIndexSet *)selectionIndexes

0 comments on commit 801f865

Please sign in to comment.