Skip to content
Browse files

merging in the master repo

  • Loading branch information...
2 parents d0faa1e + 8e999d2 commit f403417c49185620d85d050a20750125455699b8 @kgn committed
View
4 BCCollectionView+Mouse.m
@@ -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
4 BCCollectionView+Zoom.m
@@ -20,8 +20,8 @@ - (void)registerForZoomValueChangesInDefaultsForKey:(NSString *)key
- (void)zoomValueDidChange
{
[self softReloadDataWithCompletionBlock:^{
- if ([delegate respondsToSelector:@selector(colectionViewDidZoom:)])
- [delegate colectionViewDidZoom:self];
+ if ([delegate respondsToSelector:@selector(collectionViewDidZoom:)])
+ [delegate collectionViewDidZoom:self];
}];
}
View
1 BCCollectionView.h
@@ -65,6 +65,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
24 BCCollectionView.m
@@ -183,8 +183,6 @@ - (void)delegateDidDeselectItemAtIndex:(NSUInteger)index
[delegate collectionView:self
didDeselectItem:[contentArray objectAtIndex:index]
withViewController:[self viewControllerForItemAtIndex:index]];
-
- [self delegateCollectionViewSelectionDidChange];
}
- (void)delegateViewControllerBecameInvisibleAtIndex:(NSUInteger)index
@@ -405,11 +403,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];
}
@@ -418,15 +423,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
@@ -507,6 +511,10 @@ - (void)reloadDataWithItems:(NSArray *)newContent groups:(NSArray *)newGroups em
if (!delegate)
return;
+ NSSize cellSize = [delegate cellSizeForCollectionView:self];
+ if (NSWidth([self frame]) < cellSize.width || NSHeight([self frame]) < cellSize.height)
+ return;
+
for (BCCollectionViewGroup *group in groups)
[group removeObserver:self forKeyPath:@"isCollapsed"];
for (BCCollectionViewGroup *group in newGroups)
@@ -572,6 +580,10 @@ - (void)viewDidResize
- (void)softReloadDataWithCompletionBlock:(dispatch_block_t)block
{
+ NSSize cellSize = [delegate cellSizeForCollectionView:self];
+ if (NSWidth([self visibleRect]) < cellSize.width || NSHeight([self visibleRect]) < cellSize.height)
+ return;
+
NSRange range = [self rangeOfVisibleItemsWithOverflow];
[layoutManager enumerateItems:^(BCCollectionViewLayoutItem *layoutItem) {
if (NSLocationInRange([layoutItem itemIndex], range)) {
View
2 BCCollectionViewDelegate.h
@@ -69,7 +69,7 @@ enum {
//magnifiy events. This method is required BCCollectionView+Zoom is included
- (NSRange)validScalingRangeForCollectionView:(BCCollectionView *)collectionView;
-- (void)colectionViewDidZoom:(BCCollectionView *)collectionView;
+- (void)collectionViewDidZoom:(BCCollectionView *)collectionView;
//contextual menu
- (NSMenu *)collectionView:(BCCollectionView *)collectionView menuForItemsAtIndexes:(NSIndexSet *)indexSet;
View
9 BCCollectionViewLayoutManager.m
@@ -62,14 +62,17 @@ - (NSSize)cellSize
- (NSPoint)rowAndColumnPositionOfItemAtIndex:(NSUInteger)anIndex
{
- BCCollectionViewLayoutItem *itemLayout = [itemLayouts objectAtIndex:anIndex];
- return NSMakePoint(itemLayout.columnIndex, itemLayout.rowIndex);
+ if ([itemLayouts count] > anIndex) {
+ BCCollectionViewLayoutItem *itemLayout = [itemLayouts objectAtIndex:anIndex];
+ return NSMakePoint(itemLayout.columnIndex, itemLayout.rowIndex);
+ } else
+ return NSZeroPoint;
}
- (NSUInteger)indexOfItemAtRow:(NSUInteger)rowIndex column:(NSUInteger)colIndex
{
__block NSUInteger index = NSNotFound;
- [itemLayouts enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id item, NSUInteger idx, BOOL *stop) {
+ [itemLayouts enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(BCCollectionViewLayoutItem *item, NSUInteger idx, BOOL *stop) {
if ([item rowIndex] == rowIndex && [item columnIndex] == colIndex) {
index = [item itemIndex];
*stop = YES;
View
9 BCCollectionViewLayoutOperation.m
@@ -22,9 +22,12 @@ - (void)main
NSSize cellSize = [collectionView cellSize];
NSSize inset = NSZeroSize;
NSInteger maxColumns = [[collectionView layoutManager] maximumNumberOfItemsPerRow];
- NSUInteger gap = (NSWidth([collectionView frame]) - maxColumns*cellSize.width)/(maxColumns+1);
- NSInteger startingX = gap;
- NSInteger x = gap;
+ NSUInteger gap = (NSWidth([collectionView frame]) - maxColumns*cellSize.width)/(maxColumns-1);
+ if (maxColumns < 4 && maxColumns > 1) {
+ gap = (NSWidth([collectionView frame]) - maxColumns*cellSize.width)/(maxColumns+1);
+ startingX = gap;
+ x = gap;
+ }
if ([[collectionView delegate] respondsToSelector:@selector(insetMarginForSelectingItemsInCollectionView:)])
inset = [[collectionView delegate] insetMarginForSelectingItemsInCollectionView:collectionView];

0 comments on commit f403417

Please sign in to comment.
Something went wrong with that request. Please try again.