Skip to content

Instantly share code, notes, and snippets.

@nickjs
Created March 13, 2009 23:29
Show Gist options
  • Save nickjs/78826 to your computer and use it in GitHub Desktop.
Save nickjs/78826 to your computer and use it in GitHub Desktop.
diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j
index c05deee..cabb056 100644
--- a/AppKit/CPCollectionView.j
+++ b/AppKit/CPCollectionView.j
@@ -110,6 +110,7 @@
_verticalMargin = 5.0;
_tileWidth = -1.0;
+ _isSelectable = YES;
_selectionIndexes = [CPIndexSet indexSet];
}
@@ -497,21 +498,24 @@
return _maxItemSize;
}
-- (void)mouseUp:(CPEvent)anEvent
-{
- if ([_selectionIndexes count] && [anEvent clickCount] == 2 && [_delegate respondsToSelector:@selector(collectionView:didDoubleClickOnItemAtIndex:)])
- [_delegate collectionView:self didDoubleClickOnItemAtIndex:[_selectionIndexes firstIndex]];
-}
-
- (void)mouseDown:(CPEvent)anEvent
{
+ [super mouseDown:anEvent];
+
var location = [self convertPoint:[anEvent locationInWindow] fromView:nil],
row = FLOOR(location.y / (_itemSize.height + _verticalMargin)),
column = FLOOR(location.x / (_itemSize.width + _horizontalMargin)),
index = row * _numberOfColumns + column;
if (index >= 0 && index < _items.length)
+ {
[self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]];
+
+ if ([anEvent clickCount] == 2 && [_delegate respondsToSelector:@selector(collectionView:didDoubleClickOnItemAtIndex:)])
+ [_delegate collectionView:self didDoubleClickOnItemAtIndex:[_selectionIndexes firstIndex]];
+ }
+ else
+ [self setSelectionIndexes:[CPIndexSet indexSet]];
}
- (void)mouseDragged:(CPEvent)anEvent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment