aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableStructure.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-09-16 01:00:12 +0000
committerrowanbeentje <rowan@beent.je>2010-09-16 01:00:12 +0000
commite6497aafda5ecb92e1fe18f5e23999c2babec296 (patch)
tree12effaf3c01389084ba6ba25c2ec1480b662ef9f /Source/SPTableStructure.m
parentcbb150b07fcb3a96db460a22c4eb5280d8bf9e08 (diff)
downloadsequelpro-e6497aafda5ecb92e1fe18f5e23999c2babec296.tar.gz
sequelpro-e6497aafda5ecb92e1fe18f5e23999c2babec296.tar.bz2
sequelpro-e6497aafda5ecb92e1fe18f5e23999c2babec296.zip
- Consolidate structure and content row editing cancellation code into a single function in each class
- Tweak NSTableView subclasses to catch presses of the Escape key and ask the class to abort row editing. This makes Esc key behaviour much more consistent, and allows cancelling/reverting edits made via the mouse (eg checkboxes, dropdowns, enums), or after the cell editing has finished but the row is still selected. - Remove debug - Update localisable strings
Diffstat (limited to 'Source/SPTableStructure.m')
-rw-r--r--Source/SPTableStructure.m47
1 files changed, 23 insertions, 24 deletions
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m
index c6e4d7f7..4d9a496f 100644
--- a/Source/SPTableStructure.m
+++ b/Source/SPTableStructure.m
@@ -609,6 +609,27 @@
}
}
+/**
+ * Cancel active row editing, replacing the previous row if there was one
+ * and resetting state.
+ * Returns whether row editing was cancelled.
+ */
+- (BOOL)cancelRowEditing
+{
+ if (!isEditingRow) return NO;
+ if (isEditingNewRow) {
+ isEditingNewRow = NO;
+ [tableFields removeObjectAtIndex:currentlyEditingRow];
+ } else {
+ [tableFields replaceObjectAtIndex:currentlyEditingRow withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]];
+ }
+ isEditingRow = NO;
+ [tableSourceView reloadData];
+ currentlyEditingRow = -1;
+ [tableSourceView makeFirstResponder];
+ return YES;
+}
+
#pragma mark -
#pragma mark Index sheet methods
@@ -1065,18 +1086,7 @@ closes the keySheet
// Discard changes and cancel editing
else {
- if (!isEditingNewRow) {
- [tableFields replaceObjectAtIndex:currentlyEditingRow
- withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]];
- isEditingRow = NO;
- }
- else {
- [tableFields removeObjectAtIndex:currentlyEditingRow];
- isEditingRow = NO;
- isEditingNewRow = NO;
- }
-
- currentlyEditingRow = -1;
+ [self cancelRowEditing];
}
[tableSourceView reloadData];
@@ -1706,18 +1716,7 @@ would result in a position change.
else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(cancelOperation:)] )
{
[control abortEditing];
- if ( isEditingRow && !isEditingNewRow ) {
- isEditingRow = NO;
- [tableFields replaceObjectAtIndex:row withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]];
- } else if ( isEditingNewRow ) {
- isEditingRow = NO;
- isEditingNewRow = NO;
- [tableFields removeObjectAtIndex:row];
- [tableSourceView reloadData];
- }
- currentlyEditingRow = -1;
- [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
- [tableSourceView makeFirstResponder];
+ [self cancelRowEditing];
return YES;
} else {
return NO;