diff options
author | Max <post@wickenrode.com> | 2015-10-14 20:22:43 +0200 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-10-14 20:22:43 +0200 |
commit | 8f5f361da4cc30a72641c8ae72db5cce03ce234f (patch) | |
tree | 635489240db3820ab810f57f3325c795400ef79f | |
parent | 71eaebae6b68c585809582823c9b3f7b8eae53c8 (diff) | |
download | sequelpro-8f5f361da4cc30a72641c8ae72db5cce03ce234f.tar.gz sequelpro-8f5f361da4cc30a72641c8ae72db5cce03ce234f.tar.bz2 sequelpro-8f5f361da4cc30a72641c8ae72db5cce03ce234f.zip |
Change double click handling in the favorite list.
So it only acts on double clicks that are actually made on an item.
-rw-r--r-- | Source/SPConnectionController.h | 2 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 5 | ||||
-rw-r--r-- | Source/SPFavoritesOutlineView.h | 9 | ||||
-rw-r--r-- | Source/SPFavoritesOutlineView.m | 32 |
4 files changed, 41 insertions, 7 deletions
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h index f154ef77..ffface82 100644 --- a/Source/SPConnectionController.h +++ b/Source/SPConnectionController.h @@ -228,7 +228,7 @@ #ifndef SP_CODA // Interface interaction -- (IBAction)nodeDoubleClicked:(id)sender; +- (void)nodeDoubleClicked:(id)sender; - (IBAction)chooseKeyLocation:(id)sender; - (IBAction)showHelp:(id)sender; - (IBAction)updateSSLInterface:(id)sender; diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 5168d2c6..dd677ee4 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -53,6 +53,7 @@ #import "SPFavoriteColorSupport.h" #import "SPNamedNode.h" #import "SPWindowController.h" +#import "SPFavoritesOutlineView.h" #import <SPMySQL/SPMySQL.h> @@ -343,10 +344,10 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, /** * Registered to be the double click action of the favorites outline view. */ -- (IBAction)nodeDoubleClicked:(id)sender +- (void)nodeDoubleClicked:(id)sender { #ifndef SP_CODA - SPTreeNode *node = [self selectedFavoriteNode]; + SPTreeNode *node = [favoritesOutlineView itemForDoubleAction]; if (node) { if (node == quickConnectItem) { diff --git a/Source/SPFavoritesOutlineView.h b/Source/SPFavoritesOutlineView.h index 2c3d475c..78222f38 100644 --- a/Source/SPFavoritesOutlineView.h +++ b/Source/SPFavoritesOutlineView.h @@ -34,8 +34,17 @@ { BOOL isOSVersionAtLeast10_7_0; BOOL justGainedFocus; + + id _itemForDoubleAction; } @property (assign) BOOL justGainedFocus; +/** + * The item on which the last doubleAction (double click or enter/return key) was performed. + * May be nil. + * This is only valid during the call to the doubleAction target! + */ +@property (nonatomic,readonly,assign) id itemForDoubleAction; + @end 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. |