diff options
author | jakob <jakob@eggerapps.at> | 2010-04-13 17:50:32 +0000 |
---|---|---|
committer | jakob <jakob@eggerapps.at> | 2010-04-13 17:50:32 +0000 |
commit | 52c04d944a0364ba043f9fe82f4c5c85928f99f6 (patch) | |
tree | 6a39d9525719cdb49e7168c4de376f49c1464b17 | |
parent | 688345df80bb228e9c26b13ccec0710850223123 (diff) | |
download | sequelpro-52c04d944a0364ba043f9fe82f4c5c85928f99f6.tar.gz sequelpro-52c04d944a0364ba043f9fe82f4c5c85928f99f6.tar.bz2 sequelpro-52c04d944a0364ba043f9fe82f4c5c85928f99f6.zip |
- enabled up/down arrow key navigation (see #633)
- enter key ends editing and saves row now rather than going to the next cell
- fixed a bug that occured when clicking the delete/duplicate button while editing a cell
-rw-r--r-- | Source/TableContent.m | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m index 82f2c39c..38636326 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -761,9 +761,13 @@ pthread_mutex_unlock(&tableValuesLock); } - // Ensure the table is aware of changes, especially for non-threaded loads - [tableContentView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:YES]; - [tableContentView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; + // Ensure the table is aware of changes + if ([NSThread isMainThread]) { + [tableContentView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES]; + } else { + [tableContentView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:YES]; + [tableContentView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; + } // Clean up the autorelease pool and reset the progress indicator [dataLoadingPool drain]; @@ -1963,14 +1967,13 @@ */ - (BOOL)saveRowOnDeselect { + // Save any edits which have been made but not saved to the table yet. + [tableWindow endEditingFor:nil]; // If no rows are currently being edited, or a save is in progress, return success at once. if (!isEditingRow || isSavingRow) return YES; isSavingRow = YES; - // Save any edits which have been made but not saved to the table yet. - [tableWindow endEditingFor:nil]; - // Attempt to save the row, and return YES if the save succeeded. if ([self addRowToDB]) { isSavingRow = NO; @@ -3128,7 +3131,7 @@ #pragma mark Other methods /* - * Trap the enter and escape keys, overriding default behaviour and continuing/ending editing, + * Trap the enter, escape, tab and arrow keys, overriding default behaviour and continuing/ending editing, * only within the current row. */ - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command @@ -3139,9 +3142,8 @@ row = [tableContentView editedRow]; column = [tableContentView editedColumn]; - // Trap enter and tab keys - if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] || - [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) + // Trap tab key + if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertTab:)] ) { [[control window] makeFirstResponder:control]; @@ -3170,7 +3172,39 @@ } return TRUE; } - + + // Trap enter key + else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] ) + { + [[control window] makeFirstResponder:control]; + [self addRowToDB]; + return TRUE; + } + + // Trap down arrow key + else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(moveDown:)] ) + { + if (row==tableRowsCount) return TRUE; //already at the end of the list + + [[control window] makeFirstResponder:control]; + [self addRowToDB]; + [tableContentView selectRow:row+1 byExtendingSelection:NO]; + [tableContentView editColumn:column row:row+1 withEvent:nil select:YES]; + return TRUE; + } + + // Trap up arrow key + else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(moveUp:)] ) + { + if (row==0) return TRUE; //already at the beginning of the list + + [[control window] makeFirstResponder:control]; + [self addRowToDB]; + [tableContentView selectRow:row-1 byExtendingSelection:NO]; + [tableContentView editColumn:column row:row-1 withEvent:nil select:YES]; + return TRUE; + } + // Trap the escape key else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(_cancelKey:)] || [textView methodForSelector:command] == [textView methodForSelector:@selector(complete:)] ) |