From 60c5717869cdd6f68355f720b63a6df1bb7c87c6 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Fri, 15 Oct 2010 13:30:37 +0000 Subject: Change the connection view's table view to be of type SPTableView so right-clicking a row results in it being selected first. Also, update SPTableView to prevent right-clicking of table view group headings. Fixes issue #867. --- Interfaces/English.lproj/ConnectionView.xib | 55 ++++++++++--------- Source/SPTableView.m | 82 ++++++++++++++++------------- sequel-pro.xcodeproj/project.pbxproj | 6 +-- 3 files changed, 78 insertions(+), 65 deletions(-) diff --git a/Interfaces/English.lproj/ConnectionView.xib b/Interfaces/English.lproj/ConnectionView.xib index 77bd9719..978d87a3 100644 --- a/Interfaces/English.lproj/ConnectionView.xib +++ b/Interfaces/English.lproj/ConnectionView.xib @@ -3,7 +3,7 @@ 1050 10F569 - 788 + 804 1038.29 461.00 @@ -15,27 +15,22 @@ YES - 788 + 804 1.2.5 YES - + YES - com.apple.InterfaceBuilder.CocoaPlugin com.brandonwalkin.BWToolkit + com.apple.InterfaceBuilder.CocoaPlugin - YES - - YES - - - YES - + PluginDependencyRecalculationVersion + YES @@ -187,7 +182,7 @@ _doScroller: - 0.99812382739212002 + 0.99812382459640503 @@ -502,7 +497,7 @@ controlColor 3 - MC42NjY2NjY2NjY3AA + MC42NjY2NjY2ODY1AA @@ -840,7 +835,7 @@ 3 - MC41MDQwMzIyNTgxAA + MC41MDQwMzIyNTQyAA @@ -1240,7 +1235,7 @@ 3 - MC41MDQwMzIyNTgxAA + MC41MDQwMzIyNTQyAA @@ -1676,7 +1671,7 @@ 3 - MC40OTU5Njc3NDE5AA + MC40OTU5Njc3NDU4AA @@ -1816,7 +1811,7 @@ _doScroller: 1 - 0.99775280898876406 + 0.99775278568267822 @@ -1826,7 +1821,7 @@ 1 _doScroller: - 0.97838616714697402 + 0.97838616371154785 {679, 443} @@ -1880,7 +1875,7 @@ Error Detail NSPanel - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} {100, 100} @@ -1920,9 +1915,9 @@ YES - + 1 - MC45MDE5NjA3OSAwLjkwMTk2MDc5IDAuOTAxOTYwNzkAA + MC45MDE5NjA3OTAyIDAuOTAxOTYwNzkwMiAwLjkwMTk2MDc5MDIAA LucidaGrande @@ -2043,7 +2038,7 @@ YES - + LucidaGrande-Bold 10 @@ -2206,7 +2201,7 @@ {{0, 0}, {1440, 878}} {100, 119} - {1.79769e+308, 1.79769e+308} + {3.40282e+38, 3.40282e+38} @@ -4313,7 +4308,9 @@ YES 0 - + + YES + @@ -5902,6 +5899,7 @@ 4910.IBPluginDependency 4911.IBPluginDependency 4912.IBPluginDependency + 4913.CustomClassName 4913.IBPluginDependency 4915.IBPluginDependency 4918.CustomClassName @@ -6164,6 +6162,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + SPTableView com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin ImageAndTextCell @@ -7259,6 +7258,14 @@ NSView + + SPTableView + NSTableView + + IBProjectSource + Source/SPTableView.h + + YES diff --git a/Source/SPTableView.m b/Source/SPTableView.m index aa0b5067..b8590a9a 100644 --- a/Source/SPTableView.m +++ b/Source/SPTableView.m @@ -30,46 +30,46 @@ @implementation SPTableView -/* +/** * Right-click at row will select that row before ordering out the contextual menu - * if not more than one row is selected + * if not more than one row is selected. */ - (NSMenu *)menuForEvent:(NSEvent *)event { - // Try to retrieve a reference to the table document (assuming this is frontmost tab) SPDatabaseDocument *parentTableDocument = nil; + if ([[[[[self window] delegate] class] description] isEqualToString:@"SPWindowController"]) { parentTableDocument = [[[self window] delegate] selectedTableDocument]; } // If SPDatabaseDocument is performing a task suppress any context menu - if (parentTableDocument && [parentTableDocument isWorking]) - return nil; + if (parentTableDocument && [parentTableDocument isWorking]) return nil; // Check to see whether any edits-in-progress need to be saved before changing selections - if (parentTableDocument && ![parentTableDocument couldCommitCurrentViewActions]) - return nil; + if (parentTableDocument && ![parentTableDocument couldCommitCurrentViewActions]) return nil; // If more than one row is selected only returns the default contextual menu - if([self numberOfSelectedRows] > 1) - return [self menu]; + if ([self numberOfSelectedRows] > 1) return [self menu]; // Right-click at a row will select that row before ordering out the context menu NSInteger row = [self rowAtPoint:[self convertPoint:[event locationInWindow] fromView:nil]]; - if(row >= 0 && row < [self numberOfRows]) { + + if (row >= 0 && row < [self numberOfRows]) { // Check for SPTablesList if right-click on header, then suppress context menu - if([[[[self delegate] class] description] isEqualToString:@"SPTablesList"]) { - if([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:@"tableTypes"], row) integerValue] == -1) + if ([[[[self delegate] class] description] isEqualToString:@"SPTablesList"]) { + if ([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:@"tableTypes"], row) integerValue] == -1) return nil; } - if([[[[self delegate] class] description] isEqualToString:@"SPQueryFavoriteManager"]) { - if([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:SPFavorites], row) objectForKey:@"headerOfFileURL"]) + + if ([[[[self delegate] class] description] isEqualToString:@"SPQueryFavoriteManager"]) { + if ([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:SPFavorites], row) objectForKey:@"headerOfFileURL"]) return nil; } - if([[[[self delegate] class] description] isEqualToString:@"SPContentFilterManager"]) { - if([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:@"contentFilters"], row) objectForKey:@"headerOfFileURL"]) + + if ([[[[self delegate] class] description] isEqualToString:@"SPContentFilterManager"]) { + if ([NSArrayObjectAtIndex([[self delegate] valueForKeyPath:@"contentFilters"], row) objectForKey:@"headerOfFileURL"]) return nil; } @@ -80,33 +80,32 @@ return [self menu]; } --(BOOL)acceptsFirstResponder +- (BOOL)acceptsFirstResponder { return YES; } - (void)keyDown:(NSEvent *)theEvent { - // Check if ENTER or RETURN is hit and edit the column. - if ([self numberOfSelectedRows] == 1 && ([theEvent keyCode] == 36 || [theEvent keyCode] == 76)) - { - - if([[[[self delegate] class] description] isEqualToString:@"SPFieldMapperController"]) { + if ([self numberOfSelectedRows] == 1 && ([theEvent keyCode] == 36 || [theEvent keyCode] == 76)) { - if([[self delegate] isGlobalValueSheetOpen]) { + if ([[[[self delegate] class] description] isEqualToString:@"SPFieldMapperController"]) { + if ([[self delegate] isGlobalValueSheetOpen]) { [[self delegate] closeGlobalValuesSheet:nil]; return; } // ENTER or RETURN closes the SPFieldMapperController sheet // by sending an object with the tag 1 if no table cell is edited - if([[self delegate] canBeClosed]) { + if ([[self delegate] canBeClosed]) { NSButton *b = [[[NSButton alloc] init] autorelease]; [b setTag:1]; [[self delegate] closeSheet:b]; + return; - } else { + } + else { [super keyDown:theEvent]; return; } @@ -114,38 +113,45 @@ } if (![[[[self delegate] class] description] isEqualToString:@"SPCustomQuery"] && - ![[[[self delegate] class] description] isEqualToString:@"SPQueryFavoriteManager"]){ + ![[[[self delegate] class] description] isEqualToString:@"SPQueryFavoriteManager"]) { // Ensure that editing is permitted - if (![[self delegate] tableView:self shouldEditTableColumn:[[self tableColumns] objectAtIndex:0] row:[self selectedRow]]) - return; + if (![[self delegate] tableView:self shouldEditTableColumn:[[self tableColumns] objectAtIndex:0] row:[self selectedRow]]) return; // Trigger a cell edit [self editColumn:0 row:[self selectedRow] withEvent:nil select:YES]; + return; } - } - // Check if ESCAPE is hit and use it to cancel row editing if supported - else if ([theEvent keyCode] == 53 && [[self delegate] respondsToSelector:@selector(cancelRowEditing)]) - { + else if ([theEvent keyCode] == 53 && [[self delegate] respondsToSelector:@selector(cancelRowEditing)]) { if ([[self delegate] cancelRowEditing]) return; } [super keyDown:theEvent]; +} +/** + * 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. + */ +- (void)rightMouseDown:(NSEvent *)event +{ + if ([[self delegate] tableView:self shouldSelectRow:[self rowAtPoint:[self convertPoint:[event locationInWindow] fromView:nil]]]) { + [super rightMouseDown:event]; + } } - (void)setFont:(NSFont *)font; { - NSArray *tableColumns; - NSUInteger columnIndex; - - tableColumns = [self tableColumns]; - columnIndex = [tableColumns count]; - while (columnIndex--) + NSArray *tableColumns = [self tableColumns]; + NSUInteger columnIndex = [tableColumns count]; + + while (columnIndex--) + { [[(NSTableColumn *)[tableColumns objectAtIndex:columnIndex] dataCell] setFont:font]; + } } @end diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index e4364456..538543e3 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -416,21 +416,21 @@ isa = PBXContainerItemProxy; containerPortal = 2A37F4A9FDCFA73011CA2CEA /* Project object */; proxyType = 1; - remoteGlobalIDString = 8D15AC270486D014006FF6A4 /* Sequel Pro */; + remoteGlobalIDString = 8D15AC270486D014006FF6A4; remoteInfo = "Sequel Pro"; }; 1798AB2712676F14000D946A /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 2A37F4A9FDCFA73011CA2CEA /* Project object */; proxyType = 1; - remoteGlobalIDString = 8D15AC270486D014006FF6A4 /* Sequel Pro */; + remoteGlobalIDString = 8D15AC270486D014006FF6A4; remoteInfo = "Sequel Pro"; }; 1798AB401267731F000D946A /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 2A37F4A9FDCFA73011CA2CEA /* Project object */; proxyType = 1; - remoteGlobalIDString = 58B9096011C3A42B000826E5 /* xibLocalizationPostprocessor */; + remoteGlobalIDString = 58B9096011C3A42B000826E5; remoteInfo = xibLocalizationPostprocessor; }; 17B7B59A1016039200F057DE /* PBXContainerItemProxy */ = { -- cgit v1.2.3