aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableStructure.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2013-10-27 16:15:12 +0000
committerstuconnolly <stuart02@gmail.com>2013-10-27 16:15:12 +0000
commit0c4901239d3c0e0235e746103879f6278b3bc64f (patch)
tree8a38d24c94d9f24f25044dbc2befcf1473e3f4b7 /Source/SPTableStructure.m
parent9c240bfce5e73b3a28e58c0fa0aba76a6778e8c8 (diff)
downloadsequelpro-0c4901239d3c0e0235e746103879f6278b3bc64f.tar.gz
sequelpro-0c4901239d3c0e0235e746103879f6278b3bc64f.tar.bz2
sequelpro-0c4901239d3c0e0235e746103879f6278b3bc64f.zip
Ensure the relations table view is refreshed after field changes result in a dropped relationship. Fixes issue #1591.
Diffstat (limited to 'Source/SPTableStructure.m')
-rw-r--r--Source/SPTableStructure.m42
1 files changed, 31 insertions, 11 deletions
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m
index cd034a6d..883e21c8 100644
--- a/Source/SPTableStructure.m
+++ b/Source/SPTableStructure.m
@@ -51,6 +51,9 @@
#import <SPMySQL/SPMySQL.h>
+static NSString *SPRemoveField = @"SPRemoveField";
+static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey";
+
@interface SPTableStructure (PrivateAPI)
- (void)_removeFieldAndForeignKey:(NSNumber *)removeForeignKey;
@@ -436,7 +439,7 @@
defaultButton:NSLocalizedString(@"Delete", @"delete button")
alternateButton:NSLocalizedString(@"Cancel", @"cancel button")
otherButton:nil
- informativeTextWithFormat:(hasForeignKey) ? [NSString stringWithFormat:NSLocalizedString(@"This field is part of a foreign key relationship with the table '%@'. This relationship must be removed before the field can be deleted.\n\nAre you sure you want to continue to delete the relationship and the field? This action cannot be undone.", @"delete field and foreign key informative message"), referencedTable] : [NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to delete the field '%@'? This action cannot be undone.", @"delete field informative message"), field]];
+ informativeTextWithFormat:hasForeignKey ? [NSString stringWithFormat:NSLocalizedString(@"This field is part of a foreign key relationship with the table '%@'. This relationship must be removed before the field can be deleted.\n\nAre you sure you want to continue to delete the relationship and the field? This action cannot be undone.", @"delete field and foreign key informative message"), referencedTable] : [NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to delete the field '%@'? This action cannot be undone.", @"delete field informative message"), field]];
[alert setAlertStyle:NSCriticalAlertStyle];
@@ -452,7 +455,10 @@
[[buttons objectAtIndex:1] setKeyEquivalent:@"\e"];
#endif
- [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow] modalDelegate:self didEndSelector:@selector(removeFieldSheetDidEnd:returnCode:contextInfo:) contextInfo:(hasForeignKey) ? @"removeFieldAndForeignKey" : @"removeField"];
+ [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow]
+ modalDelegate:self
+ didEndSelector:@selector(removeFieldSheetDidEnd:returnCode:contextInfo:)
+ contextInfo:hasForeignKey ? SPRemoveFieldAndForeignKey : SPRemoveField];
}
/**
@@ -510,12 +516,17 @@
if (returnCode == NSAlertDefaultReturn) {
[tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Removing field...", @"removing field task status message")];
- NSNumber *removeKey = [NSNumber numberWithBool:[(NSString *)contextInfo hasSuffix:@"AndForeignKey"]];
+ NSNumber *removeKey = [NSNumber numberWithBool:[(NSString *)contextInfo isEqualToString:SPRemoveFieldAndForeignKey]];
if ([NSThread isMainThread]) {
- [NSThread detachNewThreadWithName:@"SPTableStructure field and key removal task" target:self selector:@selector(_removeFieldAndForeignKey:) object:removeKey];
-
- [tableDocumentInstance enableTaskCancellationWithTitle:NSLocalizedString(@"Cancel", @"cancel button") callbackObject:self callbackFunction:NULL];
+ [NSThread detachNewThreadWithName:@"SPTableStructure field and key removal task"
+ target:self
+ selector:@selector(_removeFieldAndForeignKey:)
+ object:removeKey];
+
+ [tableDocumentInstance enableTaskCancellationWithTitle:NSLocalizedString(@"Cancel", @"cancel button")
+ callbackObject:self
+ callbackFunction:NULL];
}
else {
[self _removeFieldAndForeignKey:removeKey];
@@ -531,18 +542,25 @@
- (BOOL)cancelRowEditing
{
if (!isEditingRow) return NO;
+
if (isEditingNewRow) {
isEditingNewRow = NO;
[tableFields removeObjectAtIndex:currentlyEditingRow];
- } else {
+ }
+ else {
[tableFields replaceObjectAtIndex:currentlyEditingRow withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]];
}
+
isEditingRow = NO;
isCurrentExtraAutoIncrement = [tableDataInstance tableHasAutoIncrementField];
autoIncrementIndex = nil;
+
[tableSourceView reloadData];
+
currentlyEditingRow = -1;
+
[[tableDocumentInstance parentWindow] makeFirstResponder:tableSourceView];
+
return YES;
}
@@ -556,7 +574,6 @@
#endif
}
-
#pragma mark -
#pragma mark Index sheet methods
@@ -1418,15 +1435,18 @@
[errorDictionary setObject:[NSString stringWithFormat:NSLocalizedString(@"Couldn't delete field %@.\nMySQL said: %@", @"message of panel when field cannot be deleted"),
[[tableFields objectAtIndex:[tableSourceView selectedRow]] objectForKey:@"name"],
[mySQLConnection lastErrorMessage]] forKey:@"message"];
+
[[self onMainThread] showErrorSheetWith:errorDictionary];
}
else {
[tableDataInstance resetAllData];
+
+ // Refresh relevant views
[tableDocumentInstance setStatusRequiresReload:YES];
- [self loadTable:selectedTable];
-
- // Mark the content table cache for refresh
[tableDocumentInstance setContentRequiresReload:YES];
+ [tableDocumentInstance setRelationsRequiresReload:YES];
+
+ [self loadTable:selectedTable];
}
[tableDocumentInstance endTask];