From 8f5f361da4cc30a72641c8ae72db5cce03ce234f Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 14 Oct 2015 20:22:43 +0200 Subject: Change double click handling in the favorite list. So it only acts on double clicks that are actually made on an item. --- Source/SPFavoritesOutlineView.m | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'Source/SPFavoritesOutlineView.m') diff --git a/Source/SPFavoritesOutlineView.m b/Source/SPFavoritesOutlineView.m index 2e111925..8dbec5da 100644 --- a/Source/SPFavoritesOutlineView.m +++ b/Source/SPFavoritesOutlineView.m @@ -31,11 +31,18 @@ #import "SPFavoritesOutlineView.h" #import "SPConnectionControllerDelegate.h" +@interface SPFavoritesOutlineView () + +@property (nonatomic,readwrite,assign) id itemForDoubleAction; //make setter private + +@end + static NSUInteger SPFavoritesOutlineViewUnindent = 6; @implementation SPFavoritesOutlineView @synthesize justGainedFocus; +@synthesize itemForDoubleAction = _itemForDoubleAction; - (void)awakeFromNib { @@ -83,12 +90,13 @@ static NSUInteger SPFavoritesOutlineViewUnindent = 6; // Enter or Return initiates a connection to the selected favorite, which is the same as double-clicking // one, so call the same selector. if (([self numberOfSelectedRows] == 1) && (([event keyCode] == 36) || ([event keyCode] == 76))) { - [[self delegate] performSelector:[self doubleAction]]; - + [self setItemForDoubleAction:[self itemAtRow:[self selectedRow]]]; + [NSApp sendAction:[self doubleAction] to:[self delegate] from:self]; + [self setItemForDoubleAction:nil]; return; - + } // If the Tab key is used, change focus rather than entering edit mode. - } else if ([[event characters] length] && [[event characters] characterAtIndex:0] == NSTabCharacter) { + if ([[event characters] length] && [[event characters] characterAtIndex:0] == NSTabCharacter) { if (([event modifierFlags] & NSShiftKeyMask) != NSShiftKeyMask) { [[self window] selectKeyViewFollowingView:self]; } @@ -102,6 +110,22 @@ static NSUInteger SPFavoritesOutlineViewUnindent = 6; [super keyDown:event]; } +- (void)mouseDown:(NSEvent *)theEvent +{ + if([theEvent type] == NSLeftMouseDown && [theEvent clickCount] == 2) { + // The tricky thing is that [self clickedRow] is set from [NSTableView mouseDown], so right now it's not populated. + // We can't use [self selectedRow] either, as clicking on empty space does not update the selection. + NSPoint clickAt = [theEvent locationInWindow]; + NSPoint relClickAt = [self convertPoint:clickAt fromView:nil]; + NSInteger rowNum = [self rowAtPoint:relClickAt]; + if(rowNum > -1) [self setItemForDoubleAction:[self itemAtRow:rowNum]]; + } + + [super mouseDown:theEvent]; + + [self setItemForDoubleAction:nil]; // not much overhead, therefore unconditional +} + /** * To prevent right-clicking in a column's 'group' heading, ask the delegate if we support selecting it * as this normally doesn't apply to left-clicks. If we do support selecting this row, simply pass on the event. -- cgit v1.2.3