diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPTableView.h | 5 | ||||
-rw-r--r-- | Source/SPTableView.m | 26 | ||||
-rw-r--r-- | Source/SPTablesList.h | 4 | ||||
-rw-r--r-- | Source/SPTablesList.m | 9 |
4 files changed, 40 insertions, 4 deletions
diff --git a/Source/SPTableView.h b/Source/SPTableView.h index 6914723d..e39df82f 100644 --- a/Source/SPTableView.h +++ b/Source/SPTableView.h @@ -23,5 +23,10 @@ // More info at <http://code.google.com/p/sequel-pro/> @interface SPTableView : NSTableView +{ + BOOL tabEditingDisabled; +} + +@property (readwrite, assign) BOOL tabEditingDisabled; @end diff --git a/Source/SPTableView.m b/Source/SPTableView.m index 65536b6d..5e279dbc 100644 --- a/Source/SPTableView.m +++ b/Source/SPTableView.m @@ -36,6 +36,8 @@ @implementation SPTableView +@synthesize tabEditingDisabled; + /** * Right-click at row will select that row before ordering out the contextual menu * if not more than one row is selected. @@ -91,6 +93,19 @@ return YES; } +/** + * On becomeFirstResponder, if editing is disabled, override the super and just + * display instead; this prevents the selected cell from automatically editing + * if the table is backtabbed to. + */ +- (BOOL)becomeFirstResponder { + if (tabEditingDisabled) { + [self display]; + return YES; + } + return [super becomeFirstResponder]; +} + - (void)keyDown:(NSEvent *)theEvent { // Check if ENTER or RETURN is hit and edit the column. @@ -131,11 +146,22 @@ 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)]) { if ([[self delegate] cancelRowEditing]) return; } + // If the Tab key is used, but tab editing is disabled, change focus rather than entering edit mode. + else if (tabEditingDisabled && [[theEvent characters] length] && [[theEvent characters] characterAtIndex:0] == NSTabCharacter) { + if (([theEvent modifierFlags] & NSShiftKeyMask) != NSShiftKeyMask) { + [[self window] selectKeyViewFollowingView:self]; + } else { + [[self window] selectKeyViewPrecedingView:self]; + } + return; + } + [super keyDown:theEvent]; } diff --git a/Source/SPTablesList.h b/Source/SPTablesList.h index d4623f40..42f49f60 100644 --- a/Source/SPTablesList.h +++ b/Source/SPTablesList.h @@ -25,7 +25,7 @@ #import <MCPKit/MCPKit.h> -@class SPHistoryController; +@class SPHistoryController, SPTableView; @interface NSObject (NSSplitView) @@ -51,7 +51,7 @@ IBOutlet SPHistoryController *spHistoryControllerInstance; IBOutlet id copyTableSheet; - IBOutlet id tablesListView; + IBOutlet SPTableView *tablesListView; IBOutlet id copyTableButton; IBOutlet id copyTableNameField; IBOutlet id copyTableMessageField; diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m index 9c1a1d0c..67ab3069 100644 --- a/Source/SPTablesList.m +++ b/Source/SPTablesList.m @@ -31,6 +31,7 @@ #import "SPTableData.h" #import "SPTableInfo.h" #import "SPDataImport.h" +#import "SPTableView.h" #import "ImageAndTextCell.h" #import "RegexKitLite.h" #import "SPDatabaseData.h" @@ -1428,15 +1429,16 @@ */ - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { + + // When enter/return is used, save the row. if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] ) { - //save current line [[control window] makeFirstResponder:control]; return TRUE; + // When the escape key is used, abort the rename. } else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(cancelOperation:)] || [textView methodForSelector:command] == [textView methodForSelector:@selector(complete:)] ) { - //abort editing [control abortEditing]; [[NSApp mainWindow] makeFirstResponder:tablesListView]; @@ -1903,6 +1905,9 @@ [tableListFilterSplitView setCollapsibleSubviewCollapsed:YES]; } + // Disable tab edit behaviour in the tables list + [tablesListView setTabEditingDisabled:YES]; + // Add observers for document task activity [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startDocumentTaskForTab:) |