aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableStructureLoading.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-08-05 13:21:44 +0000
committerrowanbeentje <rowan@beent.je>2012-08-05 13:21:44 +0000
commit784641222e5d9ee521a5846682f9ec2cc4cf6a3f (patch)
tree788473085483ff733c9b8942803268c88b89391a /Source/SPTableStructureLoading.m
parent55d98a1ec966116a6cd821c7e90bd658ca3c5530 (diff)
downloadsequelpro-784641222e5d9ee521a5846682f9ec2cc4cf6a3f.tar.gz
sequelpro-784641222e5d9ee521a5846682f9ec2cc4cf6a3f.tar.bz2
sequelpro-784641222e5d9ee521a5846682f9ec2cc4cf6a3f.zip
- Fix table structure issues with default collations on non-default encodings, fixing a number of exceptions with various actions (Issue #1416)
- Fix which item is selected after reordering columns in the structure view - Display enodings and collations which match the table settings in gray
Diffstat (limited to 'Source/SPTableStructureLoading.m')
-rw-r--r--Source/SPTableStructureLoading.m29
1 files changed, 20 insertions, 9 deletions
diff --git a/Source/SPTableStructureLoading.m b/Source/SPTableStructureLoading.m
index 9ee6b430..b790b384 100644
--- a/Source/SPTableStructureLoading.m
+++ b/Source/SPTableStructureLoading.m
@@ -116,6 +116,7 @@
NSArray *encodings = [databaseDataInstance getDatabaseCharacterSetEncodings];
if ([encodings count]) {
+ NSString *defaultEncodingDescription = nil;
// Populate encoding popup button
NSMutableArray *encodingTitles = [[NSMutableArray alloc] initWithCapacity:[encodings count]+1];
@@ -125,10 +126,22 @@
for (NSDictionary *encoding in encodings)
{
[encodingTitles addObject:(![encoding objectForKey:@"DESCRIPTION"]) ? [encoding objectForKey:@"CHARACTER_SET_NAME"] : [NSString stringWithFormat:@"%@ (%@)", [encoding objectForKey:@"DESCRIPTION"], [encoding objectForKey:@"CHARACTER_SET_NAME"]]];
+ if ([[encoding objectForKey:@"CHARACTER_SET_NAME"] isEqualToString:[tableDataInstance tableEncoding]]) {
+ defaultEncodingDescription = [encodingTitles lastObject];
+ }
}
[[encodingPopupCell onMainThread] removeAllItems];
[[encodingPopupCell onMainThread] addItemsWithTitles:encodingTitles];
+
+ // Take the encoding that matches the table's encoding and gray it out
+ if (defaultEncodingDescription) {
+ NSMenuItem *tableEncodingMenuItem = [[encodingPopupCell menu] itemWithTitle:defaultEncodingDescription];
+ NSDictionary *menuAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSColor lightGrayColor], NSForegroundColorAttributeName, [NSFont systemFontOfSize: [NSFont smallSystemFontSize]], NSFontAttributeName, nil];
+ NSAttributedString *itemString = [[[NSAttributedString alloc] initWithString:defaultEncodingDescription attributes:menuAttributes] autorelease];
+ [[tableEncodingMenuItem onMainThread] setAttributedTitle:itemString];
+ }
+
[encodingTitles release];
}
else {
@@ -158,23 +171,22 @@
collation = [databaseDataInstance getDatabaseDefaultCollation];
}
}
-
+
if (encoding) {
for (id enc in encodings)
{
if ([[enc objectForKey:@"CHARACTER_SET_NAME"] isEqualToString:encoding]) {
fieldEncoding = encoding;
+
+ // Set the selected index as the match index +1 due to the leading @"" in the popup list
+ [theField setObject:[NSNumber numberWithInteger:(selectedIndex + 1)] forKey:@"encoding"];
break;
}
selectedIndex++;
}
-
- // Due to leading @"" in popup list
- selectedIndex++;
}
- [theField setObject:[NSNumber numberWithInteger:selectedIndex] forKey:@"encoding"];
selectedIndex = 0;
@@ -186,6 +198,9 @@
{
if ([[col objectForKey:@"COLLATION_NAME"] isEqualToString:collation]) {
+ // Set the selected index as the match index +1 due to the leading @"" in the popup list
+ [theField setObject:[NSNumber numberWithInteger:(selectedIndex + 1)] forKey:@"collation"];
+
// Set BINARY if collation ends with _bin for convenience
if ([[col objectForKey:@"COLLATION_NAME"] hasSuffix:@"_bin"]) {
[theField setObject:[NSNumber numberWithInt:1] forKey:@"binary"];
@@ -196,12 +211,8 @@
selectedIndex++;
}
-
- // Due to leading @"" in popup list
- selectedIndex++;
}
- [theField setObject:[NSNumber numberWithInteger:selectedIndex] forKey:@"collation"];
// Get possible values if the field is an enum or a set
if (([type isEqualToString:@"ENUM"] || [type isEqualToString:@"SET"]) && [theField objectForKey:@"values"]) {