From 784641222e5d9ee521a5846682f9ec2cc4cf6a3f Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 5 Aug 2012 13:21:44 +0000 Subject: - 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 --- Source/SPTableStructureDelegate.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'Source/SPTableStructureDelegate.m') diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m index 582f961f..a220b85e 100644 --- a/Source/SPTableStructureDelegate.m +++ b/Source/SPTableStructureDelegate.m @@ -75,12 +75,25 @@ [[tableColumn dataCell] removeAllItems]; if ([collations count] > 0) { + NSString *defaultCollation = [[tableDataInstance statusValues] objectForKey:@"collation"]; + if (!defaultCollation) { + defaultCollation = [databaseDataInstance getDatabaseDefaultCollation]; + } [[tableColumn dataCell] addItemWithTitle:@""]; // Populate collation popup button for (NSDictionary *collation in collations) { - [[tableColumn dataCell] addItemWithTitle:[collation objectForKey:@"COLLATION_NAME"]]; + NSString *collationName = [collation objectForKey:@"COLLATION_NAME"]; + [[tableColumn dataCell] addItemWithTitle:collationName]; + + // If this matches the table's collation, draw in gray + if ([collationName length] && [collationName isEqualToString:defaultCollation]) { + NSMenuItem *collationMenuItem = [(NSPopUpButtonCell *)[tableColumn dataCell] itemAtIndex:([[tableColumn dataCell] numberOfItems] - 1)]; + NSDictionary *menuAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSColor lightGrayColor], NSForegroundColorAttributeName, [NSFont systemFontOfSize: [NSFont smallSystemFontSize]], NSFontAttributeName, nil]; + NSAttributedString *itemString = [[[NSAttributedString alloc] initWithString:collationName attributes:menuAttributes] autorelease]; + [collationMenuItem setAttributedTitle:itemString]; + } } } } @@ -380,7 +393,7 @@ // Mark the content table cache for refresh [tableDocumentInstance setContentRequiresReload:YES]; - [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:destinationRowIndex - (originalRowIndex < destinationRowIndex) ? 1 : 0] byExtendingSelection:NO]; + [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:destinationRowIndex - ((originalRowIndex < destinationRowIndex) ? 1 : 0)] byExtendingSelection:NO]; } [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -- cgit v1.2.3