From ecee86cc6d66da5714db8babaa6b513f3de0e295 Mon Sep 17 00:00:00 2001 From: nciagra Date: Sun, 29 Mar 2009 00:42:14 -0400 Subject: [PATCH] Added allowsEmptySelection to CPCollectionView. --- AppKit/CPCollectionView.j | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index 343cfca55..43d95061c 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -79,6 +79,7 @@ BOOL _isSelectable; BOOL _allowsMultipleSelection; + BOOL _allowsEmptySelection; CPIndexSet _selectionIndexes; CGSize _itemSize; @@ -111,6 +112,7 @@ _tileWidth = -1.0; _selectionIndexes = [CPIndexSet indexSet]; + _allowsEmptySelection = YES; _isSelectable = YES; } @@ -236,6 +238,23 @@ return _isSelected; } +/*! + Sets whether the user may have no items selected. If YES, mouse clicks not on any item will empty the current selection. The first item will also start off as selected. + @param shouldAllowMultipleSelection YES allows the user to select multiple items +*/ +- (void)setAllowsEmptySelection:(BOOL)shouldAllowEmptySelection +{ + _allowsEmptySelection = shouldAllowEmptySelection; +} + +/*! + Returns YES if the user can select no items, NO otherwise. +*/ +- (BOOL)allowsEmptySelection +{ + return _allowsEmptySelection; +} + /*! Sets whether the user can select multiple items. @param shouldAllowMultipleSelection YES allows the user to select multiple items @@ -266,14 +285,14 @@ while ((index = [_selectionIndexes indexGreaterThanIndex:index]) != CPNotFound) [_items[index] setSelected:NO]; - + _selectionIndexes = anIndexSet; - + var index = CPNotFound; - + while ((index = [_selectionIndexes indexGreaterThanIndex:index]) != CPNotFound) [_items[index] setSelected:YES]; - + if ([_delegate respondsToSelector:@selector(collectionViewDidChangeSelection:)]) [_delegate collectionViewDidChangeSelection:self] } @@ -513,6 +532,8 @@ if (index >= 0 && index < _items.length) [self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]]; + else if (_allowsEmptySelection) + [self setSelectionIndexes:[CPIndexSet indexSet]]; } - (void)mouseDragged:(CPEvent)anEvent