aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-01-09 20:30:30 +0000
committerrowanbeentje <rowan@beent.je>2010-01-09 20:30:30 +0000
commitc2da83b99ca6db2e2d78b7cd79d4618e359c523a (patch)
tree6749904fe5a7b08cc6d90da8ef1637a9a7b39b93 /Source
parentcc560367f6f3c0e1a25d7762aae906772ad3ff28 (diff)
downloadsequelpro-c2da83b99ca6db2e2d78b7cd79d4618e359c523a.tar.gz
sequelpro-c2da83b99ca6db2e2d78b7cd79d4618e359c523a.tar.bz2
sequelpro-c2da83b99ca6db2e2d78b7cd79d4618e359c523a.zip
Improve row deselection and error handling in Table Source and Content views:
- Change the error dialog buttons to "Edit row" and "Discard changes" instead of "OK" and "Cancel" - Correctly refocus the deselected row - Edit the first cell in the row after errors. - Fix row deselection and error handling on the Table Source view
Diffstat (limited to 'Source')
-rw-r--r--Source/TableContent.m10
-rw-r--r--Source/TableSource.m34
2 files changed, 26 insertions, 18 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m
index 04f8fb2a..7a034c5f 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -1840,7 +1840,7 @@
// Report errors which have occurred
} else {
- NSBeginAlertSheet(NSLocalizedString(@"Couldn't write row", @"Couldn't write row error"), NSLocalizedString(@"OK", @"OK button"), NSLocalizedString(@"Cancel", @"cancel button"), nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addrow",
+ NSBeginAlertSheet(NSLocalizedString(@"Couldn't write row", @"Couldn't write row error"), NSLocalizedString(@"Edit row", @"Edit row button"), NSLocalizedString(@"Discard changes", @"discard changes button"), nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addrow",
[NSString stringWithFormat:NSLocalizedString(@"MySQL said:\n\n%@", @"message of panel when error while adding row to db"), [mySQLConnection getLastErrorMessage]]);
return NO;
}
@@ -1869,8 +1869,7 @@
return YES;
}
- // Saving failed - reselect the old row and return failure.
- [tableContentView selectRowIndexes:[NSIndexSet indexSetWithIndex:currentlyEditingRow] byExtendingSelection:NO];
+ // Saving failed - return failure.
isSavingRow = NO;
return NO;
}
@@ -2033,11 +2032,10 @@
[[sheet window] orderOut:self];
if ( [contextInfo isEqualToString:@"addrow"] ) {
- [sheet orderOut:self];
if ( returnCode == NSAlertDefaultReturn ) {
- //problem: reenter edit mode doesn't function
- [tableContentView editColumn:0 row:[tableContentView selectedRow] withEvent:nil select:YES];
+ [tableContentView selectRowIndexes:[NSIndexSet indexSetWithIndex:currentlyEditingRow] byExtendingSelection:NO];
+ [tableContentView performSelector:@selector(keyDown:) withObject:[NSEvent keyEventWithType:NSKeyDown location:NSMakePoint(0,0) modifierFlags:0 timestamp:0 windowNumber:[tableWindow windowNumber] context:[NSGraphicsContext currentContext] characters:nil charactersIgnoringModifiers:nil isARepeat:NO keyCode:0x24] afterDelay:0.0];
} else {
if ( !isEditingNewRow ) {
[tableValues replaceObjectAtIndex:[tableContentView selectedRow]
diff --git a/Source/TableSource.m b/Source/TableSource.m
index a183434e..4feadddb 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -570,8 +570,7 @@ fetches the result as an array with a dictionary for each row in it
return YES;
}
- // Saving failed - reselect the old row and return failure.
- [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:currentlyEditingRow] byExtendingSelection:NO];
+ // Saving failed - return failure.
isSavingRow = NO;
return NO;
}
@@ -779,15 +778,15 @@ fetches the result as an array with a dictionary for each row in it
// Problem: alert sheet doesn't respond to first click
if (isEditingNewRow) {
NSBeginAlertSheet(NSLocalizedString(@"Error adding field", @"error adding field message"),
- NSLocalizedString(@"OK", @"OK button"),
- NSLocalizedString(@"Cancel", @"cancel button"), nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addrow",
+ NSLocalizedString(@"Edit row", @"Edit row button"),
+ NSLocalizedString(@"Discard changes", @"discard changes button"), nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addrow",
[NSString stringWithFormat:NSLocalizedString(@"An error occurred when trying to add the field '%@'.\n\nMySQL said: %@", @"error adding field informative message"),
[theRow objectForKey:@"Field"], [mySQLConnection getLastErrorMessage]]);
}
else {
NSBeginAlertSheet(NSLocalizedString(@"Error changing field", @"error changing field message"),
- NSLocalizedString(@"OK", @"OK button"),
- NSLocalizedString(@"Cancel", @"cancel button"), nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addrow",
+ NSLocalizedString(@"Edit row", @"Edit row button"),
+ NSLocalizedString(@"Discard changes", @"discard changes button"), nil, tableWindow, self, @selector(sheetDidEnd:returnCode:contextInfo:), nil, @"addrow",
[NSString stringWithFormat:NSLocalizedString(@"An error occurred when trying to change the field '%@'.\n\nMySQL said: %@", @"error changing field informative message"),
[theRow objectForKey:@"Field"], [mySQLConnection getLastErrorMessage]]);
}
@@ -884,10 +883,11 @@ fetches the result as an array with a dictionary for each row in it
if ( returnCode == NSAlertDefaultReturn ) {
// Problem: reentering edit mode for first cell doesn't function
- [tableSourceView editColumn:0 row:[tableSourceView selectedRow] withEvent:nil select:YES];
+ [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:currentlyEditingRow] byExtendingSelection:NO];
+ [tableSourceView performSelector:@selector(keyDown:) withObject:[NSEvent keyEventWithType:NSKeyDown location:NSMakePoint(0,0) modifierFlags:0 timestamp:0 windowNumber:[tableWindow windowNumber] context:[NSGraphicsContext currentContext] characters:nil charactersIgnoringModifiers:nil isARepeat:NO keyCode:0x24] afterDelay:0.0];
} else {
if ( !isEditingNewRow ) {
- [tableFields replaceObjectAtIndex:[tableSourceView selectedRow]
+ [tableFields replaceObjectAtIndex:currentlyEditingRow
withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]];
isEditingRow = NO;
} else {
@@ -1079,6 +1079,19 @@ returns a dictionary containing enum/set field names as key and possible values
[[tableFields objectAtIndex:rowIndex] setObject:(anObject) ? anObject : @"" forKey:[aTableColumn identifier]];
}
+/**
+ * Confirm whether to allow editing of a row. Returns YES by default, but NO for views.
+ */
+- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
+{
+ if ([tableDocumentInstance isWorking]) return NO;
+
+ // Return NO for views
+ if ([tablesListInstance tableType] == SP_TABLETYPE_VIEW) return NO;
+
+ return YES;
+}
+
/*
Begin a drag and drop operation from the table - copy a single dragged row to the drag pasteboard.
*/
@@ -1248,10 +1261,7 @@ would result in a position change.
// Check for which table view the selection changed
if (object == tableSourceView) {
// If we are editing a row, attempt to save that row - if saving failed, reselect the edit row.
- if (isEditingRow && [tableSourceView selectedRow] != currentlyEditingRow) {
- [self saveRowOnDeselect];
- isEditingRow = NO;
- }
+ if (isEditingRow && [tableSourceView selectedRow] != currentlyEditingRow && ![self saveRowOnDeselect]) return;
[copyFieldButton setEnabled:YES];