diff --git a/ExampleProject/ConcordeExample/ExampleView.m b/ExampleProject/ConcordeExample/ExampleView.m index 4d43ab9b..ead754f9 100644 --- a/ExampleProject/ConcordeExample/ExampleView.m +++ b/ExampleProject/ConcordeExample/ExampleView.m @@ -162,11 +162,15 @@ - (void)tableView:(TUITableView *)tableView didClickRowAtIndexPath:(TUIFastIndex } if(event.type == NSRightMouseUp){ - NSLog(@"right mouse up"); + // show context menu } } +- (BOOL)tableView:(TUITableView *)tableView shouldSelectRowAtIndexPath:(TUIFastIndexPath *)indexPath forEvent:(NSEvent *)event{ + switch (event.type) { + case NSRightMouseDown: + return NO; + } -- (BOOL)tableViewShouldSelectRowOnRightClick:(TUITableView*)tableView{ return YES; } diff --git a/lib/UIKit/TUITableView.h b/lib/UIKit/TUITableView.h index 6a103c13..c052aa00 100644 --- a/lib/UIKit/TUITableView.h +++ b/lib/UIKit/TUITableView.h @@ -41,11 +41,11 @@ typedef enum { @optional - (void)tableView:(TUITableView *)tableView willDisplayCell:(TUITableViewCell *)cell forRowAtIndexPath:(TUIFastIndexPath *)indexPath; // not implemented yet -- (void)tableView:(TUITableView *)tableView didSelectRowAtIndexPath:(TUIFastIndexPath *)indexPath; // happens on mouse down +- (void)tableView:(TUITableView *)tableView didSelectRowAtIndexPath:(TUIFastIndexPath *)indexPath; // happens on left/right mouse down, key up/down - (void)tableView:(TUITableView *)tableView didDeselectRowAtIndexPath:(TUIFastIndexPath *)indexPath; -- (void)tableView:(TUITableView *)tableView didClickRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent *)event; // happens on mouse up (can look at clickCount) +- (void)tableView:(TUITableView *)tableView didClickRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent *)event; // happens on left/right mouse up (can look at clickCount) -- (BOOL)tableViewShouldSelectRowOnRightClick:(TUITableView*)tableView; // NO, if not implemented +- (BOOL)tableView:(TUITableView*)tableView shouldSelectRowAtIndexPath:(TUIFastIndexPath*)indexPath forEvent:(NSEvent*)event; // YES, if not implemented @end diff --git a/lib/UIKit/TUITableView.m b/lib/UIKit/TUITableView.m index 17841fc0..ae9e6586 100644 --- a/lib/UIKit/TUITableView.m +++ b/lib/UIKit/TUITableView.m @@ -873,9 +873,10 @@ - (BOOL)performKeyAction:(NSEvent *)event } newIndexPath = [TUIFastIndexPath indexPathForRow:row inSection:section]; } - - [self selectRowAtIndexPath:newIndexPath animated:self.animateSelectionChanges scrollPosition:TUITableViewScrollPositionToVisible]; - + if(![_delegate respondsToSelector:@selector(tableView:shouldSelectRowAtIndexPath:forEvent:)] || [_delegate tableView:self shouldSelectRowAtIndexPath:newIndexPath forEvent:event]){ + [self selectRowAtIndexPath:newIndexPath animated:self.animateSelectionChanges scrollPosition:TUITableViewScrollPositionToVisible]; + } + return YES; } @@ -903,7 +904,9 @@ - (BOOL)performKeyAction:(NSEvent *)event newIndexPath = [TUIFastIndexPath indexPathForRow:row inSection:section]; } - [self selectRowAtIndexPath:newIndexPath animated:self.animateSelectionChanges scrollPosition:TUITableViewScrollPositionToVisible]; + if(![_delegate respondsToSelector:@selector(tableView:shouldSelectRowAtIndexPath:forEvent:)] || [_delegate tableView:self shouldSelectRowAtIndexPath:newIndexPath forEvent:event]){ + [self selectRowAtIndexPath:newIndexPath animated:self.animateSelectionChanges scrollPosition:TUITableViewScrollPositionToVisible]; + } return YES; } diff --git a/lib/UIKit/TUITableViewCell.m b/lib/UIKit/TUITableViewCell.m index 5ac06fdf..4f70d8be 100644 --- a/lib/UIKit/TUITableViewCell.m +++ b/lib/UIKit/TUITableViewCell.m @@ -74,11 +74,14 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)event - (void)mouseDown:(NSEvent *)event { + [super mouseDown:event]; + TUITableView *tableView = self.tableView; - [tableView selectRowAtIndexPath:self.indexPath animated:tableView.animateSelectionChanges scrollPosition:TUITableViewScrollPositionNone]; - [super mouseDown:event]; // may make the text renderer first responder, so we want to do the selection before this - _tableViewCellFlags.highlighted = 1; - [self setNeedsDisplay]; + if(![tableView.delegate respondsToSelector:@selector(tableView:shouldSelectRowAtIndexPath:forEvent:)] || [tableView.delegate tableView:tableView shouldSelectRowAtIndexPath:self.indexPath forEvent:event]){ + [tableView selectRowAtIndexPath:self.indexPath animated:tableView.animateSelectionChanges scrollPosition:TUITableViewScrollPositionNone]; + _tableViewCellFlags.highlighted = 1; + [self setNeedsDisplay]; + } } - (void)mouseUp:(NSEvent *)event @@ -99,7 +102,7 @@ - (void)rightMouseDown:(NSEvent *)event{ [super rightMouseDown:event]; TUITableView *tableView = self.tableView; - if([tableView.delegate respondsToSelector:@selector(tableViewShouldSelectRowOnRightClick:)] && [tableView.delegate tableViewShouldSelectRowOnRightClick:tableView]){ + if(![tableView.delegate respondsToSelector:@selector(tableView:shouldSelectRowAtIndexPath:forEvent:)] || [tableView.delegate tableView:tableView shouldSelectRowAtIndexPath:self.indexPath forEvent:event]){ [tableView selectRowAtIndexPath:self.indexPath animated:tableView.animateSelectionChanges scrollPosition:TUITableViewScrollPositionNone]; _tableViewCellFlags.highlighted = 1; [self setNeedsDisplay]; @@ -108,6 +111,9 @@ - (void)rightMouseDown:(NSEvent *)event{ - (void)rightMouseUp:(NSEvent *)event{ [super rightMouseUp:event]; + _tableViewCellFlags.highlighted = 0; + [self setNeedsDisplay]; + if([self eventInside:event]) { TUITableView *tableView = self.tableView; if([tableView.delegate respondsToSelector:@selector(tableView:didClickRowAtIndexPath:withEvent:)]){