From d9c094f64441bc01d6822be1da06ff6f8db5e522 Mon Sep 17 00:00:00 2001 From: klaaspieter Date: Mon, 31 May 2010 19:14:54 -0500 Subject: [PATCH 1/2] call tableview doubleclick action even if target is nil (action will travel down the responder chain) Conflicts: AppKit/CPTableView.j --- AppKit/CPTableView.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index c6651ae87..c8bac1aae 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -2972,7 +2972,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; } //end of editing conditional //double click actions - if([[CPApp currentEvent] clickCount] === 2 && _doubleAction && _target) + if([[CPApp currentEvent] clickCount] === 2 && _doubleAction) { _clickedRow = [self rowAtPoint:aPoint]; [self sendAction:_doubleAction to:_target]; From bb651d0c70862ceffe26ec0cbf668ce7caac54bf Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Tue, 1 Jun 2010 01:53:26 -0500 Subject: [PATCH 2/2] Added multiple selection support to the collectionview. --- AppKit/CPCollectionView.j | 46 +++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index 77c4ca4d6..339df6b54 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -591,8 +591,21 @@ index = row * _numberOfColumns + column; if (index >= 0 && index < _items.length) - [self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]]; + { + if (_allowsMultipleSelection && ([anEvent modifierFlags] & CPCommandKeyMask || [anEvent modifierFlags] & CPShiftKeyMask)) + { + var indexes = [_selectionIndexes copy]; + if ([indexes containsIndex:index]) + [indexes removeIndex:index]; + else + [indexes addIndex:index]; + } + else + indexes = [CPIndexSet indexSetWithIndex:index]; + + [self setSelectionIndexes:indexes]; + } else if (_allowsEmptySelection) [self setSelectionIndexes:[CPIndexSet indexSet]]; } @@ -726,6 +739,25 @@ @end @implementation CPCollectionView (KeyboardInteraction) +- (CPIndexSet)_selectionForEvent:(CPEvent)anEvent withNewIndex:(int)anIndex direction:(int)aDirection +{ + if (_allowsMultipleSelection && [anEvent modifierFlags] & CPShiftKeyMask) + { + var indexes = [_selectionIndexes copy], + bottomAnchor = [indexes firstIndex], + topAnchor = [indexes lastIndex]; + + // if the direction is backward (-1) check with the bottom anchor + if (aDirection === -1) + [indexes addIndexesInRange:CPMakeRange(anIndex, bottomAnchor - anIndex + 1)]; + else + [indexes addIndexesInRange:CPMakeRange(topAnchor, anIndex - topAnchor + 1)]; + } + else + indexes = [CPIndexSet indexSetWithIndex:anIndex]; + + return indexes; +} - (void)_scrollToSelection { @@ -743,23 +775,23 @@ index = MAX(index - 1, 0); - [self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]]; + [self setSelectionIndexes:[self _selectionForEvent:[CPApp currentEvent] withNewIndex:index direction:-1]]; [self _scrollToSelection]; } - (void)moveRight:(id)sender { - var index = MIN([[self selectionIndexes] firstIndex] + 1, [[self items] count]-1); + var index = MIN([[self selectionIndexes] lastIndex] + 1, [[self items] count]-1); - [self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]]; + [self setSelectionIndexes:[self _selectionForEvent:[CPApp currentEvent] withNewIndex:index direction:1]]; [self _scrollToSelection]; } - (void)moveDown:(id)sender { - var index = MIN([[self selectionIndexes] firstIndex] + [self numberOfColumns], [[self items] count]-1); + var index = MIN([[self selectionIndexes] lastIndex] + [self numberOfColumns], [[self items] count]-1); - [self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]]; + [self setSelectionIndexes:[self _selectionForEvent:[CPApp currentEvent] withNewIndex:index direction:1]]; [self _scrollToSelection]; } @@ -771,7 +803,7 @@ index = MAX(0, index - [self numberOfColumns]); - [self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]]; + [self setSelectionIndexes:[self _selectionForEvent:[CPApp currentEvent] withNewIndex:index direction:-1]]; [self _scrollToSelection]; }