diff options
author | rowanbeentje <rowan@beent.je> | 2011-04-10 15:35:43 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2011-04-10 15:35:43 +0000 |
commit | 0930c6b49fa7988cb14bdd5fe81c71d5d27f1936 (patch) | |
tree | 53815f39cfd69070e908c148f9f48b76ff512645 /Source | |
parent | 15d0b8bac7736e249e121492ea119e43b61d6bca (diff) | |
download | sequelpro-0930c6b49fa7988cb14bdd5fe81c71d5d27f1936.tar.gz sequelpro-0930c6b49fa7988cb14bdd5fe81c71d5d27f1936.tar.bz2 sequelpro-0930c6b49fa7988cb14bdd5fe81c71d5d27f1936.zip |
- Add support in SPTableView to disable edit-on-tab behaviour
- Use this new support in SPTablesList to prevent the tab key entering rename mode when focus is on the table list - this addresses Issue #1028
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:) |