Skip to content
Browse files

added allowNoSelection property

  • Loading branch information...
1 parent 09ebc2f commit a59321c70a14e2ee6f7df71707084132e832f9d6 @joshaber committed Mar 9, 2011
Showing with 23 additions and 10 deletions.
  1. +0 −1 JAEdgeInsets.h
  2. +1 −0 JAListView.h
  3. +22 −9 JAListView.m
View
1 JAEdgeInsets.h
@@ -1,6 +1,5 @@
/*
* JAEdgeInsets.h
- * GitHub
*
* Created by Josh Abernathy on 1/26/11.
* Copyright 2011 Josh Abernathy. All rights reserved.
View
1 JAListView.h
@@ -135,5 +135,6 @@ extern NSString * const JAListViewDraggingPasteboardType;
@property (nonatomic, readonly) CGFloat heightForAllContent;
@property (nonatomic, assign) BOOL conditionallyUseLayerBacking;
@property (nonatomic, readonly) NSArray *selectedViews;
+@property (nonatomic, assign) BOOL allowNoSelection;
@end
View
31 JAListView.m
@@ -202,14 +202,16 @@ - (void)mouseUp:(NSEvent *)event {
self.viewBeingSelected.highlighted = NO;
self.viewBeingSelected = nil;
} else {
- for(JAListViewItem *selectedView in [[self.currentlySelectedViews copy] autorelease]) {
- selectedView.selected = NO;
- [self.currentlySelectedViews removeObject:selectedView];
-
- if(respondsToUnSelect) {
- [self.delegate listView:self didDeselectView:selectedView];
- }
- }
+ if(self.allowNoSelection) {
+ for(JAListViewItem *selectedView in [[self.currentlySelectedViews copy] autorelease]) {
+ selectedView.selected = NO;
+ [self.currentlySelectedViews removeObject:selectedView];
+
+ if(respondsToUnSelect) {
+ [self.delegate listView:self didDeselectView:selectedView];
+ }
+ }
+ }
}
} else {
if([self.delegate respondsToSelector:@selector(listView:mouseUpOnView:withEvent:)]) {
@@ -229,6 +231,8 @@ - (void)mouseUp:(NSEvent *)event {
if([event modifierFlags] & NSCommandKeyMask) {
if([self.currentlySelectedViews containsObject:view]) {
+ if(!self.allowNoSelection && self.currentlySelectedViews.count < 2) return;
+
[[view retain] autorelease];
view.selected = NO;
[self.currentlySelectedViews removeObject:view];
@@ -427,6 +431,7 @@ - (void)mouseDragged:(NSEvent *)event {
- (void)keyDown:(NSEvent *)event {
JAListViewItem *newView = nil;
BOOL isShiftDown = ([event modifierFlags] & NSShiftKeyMask) != 0;
+ BOOL areUnhandledKeys = NO;
NSString *characters = [event characters];
for(NSUInteger characterIndex = 0; characterIndex < characters.length; characterIndex++) {
unichar character = [characters characterAtIndex:characterIndex];
@@ -458,7 +463,9 @@ - (void)keyDown:(NSEvent *)event {
}
}
}
- }
+ } else {
+ areUnhandledKeys = YES;
+ }
}
if(newView != nil) {
@@ -474,6 +481,10 @@ - (void)keyDown:(NSEvent *)event {
viewFrame.origin.y = self.cachedLocations[[self indexForView:newView]];
[(NSView *) self.scrollView.documentView scrollRectToVisible:viewFrame];
}
+
+ if(areUnhandledKeys) {
+ [super keyDown:event];
+ }
}
- (BOOL)acceptsFirstResponder {
@@ -561,6 +572,7 @@ - (void)setup {
[self registerForDraggedTypes:[NSArray arrayWithObject:JAListViewDraggingPasteboardType]];
self.currentlySelectedViews = [NSMutableArray array];
self.viewsBeingUsedForInertialScrolling = [NSMutableArray array];
+ self.allowNoSelection = YES;
}
- (void)viewBoundsDidChange:(NSNotification *)notification {
@@ -1082,5 +1094,6 @@ - (void)clearViewsBeingUsedForInertialScrolling {
@synthesize currentAnimationBlock;
@synthesize viewsBeingUsedForInertialScrolling;
@synthesize minIndexForReLayout;
+@synthesize allowNoSelection;
@end

0 comments on commit a59321c

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