From 3916b4227d1e02942504e13a2d36b3e6f57670bb Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 21 Mar 2012 01:31:09 +0000 Subject: - Fix a possible race condition exception when switching between tables when th structure view was active, the collation column was visible, and fields had custom collations --- Source/SPTableStructure.m | 10 +++++++--- Source/SPTableStructureDelegate.m | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'Source') diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m index 085cc558..c6f20ded 100644 --- a/Source/SPTableStructure.m +++ b/Source/SPTableStructure.m @@ -292,15 +292,19 @@ // Set up the encoding PopUpButtonCell NSArray *encodings = [databaseDataInstance getDatabaseCharacterSetEncodings]; if ([encodings count]) { - [[encodingPopupCell onMainThread] removeAllItems]; - [[encodingPopupCell onMainThread] addItemWithTitle:@""]; // Populate encoding popup button + NSMutableArray *encodingTitles = [[NSMutableArray alloc] initWithCapacity:[encodings count]+1]; + [encodingTitles addObject:@""]; for (NSDictionary *encoding in encodings) - [[encodingPopupCell onMainThread] addItemWithTitle:(![encoding objectForKey:@"DESCRIPTION"]) ? [encoding objectForKey:@"CHARACTER_SET_NAME"] : [NSString stringWithFormat:@"%@ (%@)", [encoding objectForKey:@"DESCRIPTION"], [encoding objectForKey:@"CHARACTER_SET_NAME"]]]; + [encodingTitles addObject:(![encoding objectForKey:@"DESCRIPTION"]) ? [encoding objectForKey:@"CHARACTER_SET_NAME"] : [NSString stringWithFormat:@"%@ (%@)", [encoding objectForKey:@"DESCRIPTION"], [encoding objectForKey:@"CHARACTER_SET_NAME"]]]; + [[encodingPopupCell onMainThread] removeAllItems]; + [[encodingPopupCell onMainThread] addItemsWithTitles:encodingTitles]; + [encodingTitles release]; } else { + [[encodingPopupCell onMainThread] removeAllItems]; [[encodingPopupCell onMainThread] addItemWithTitle:NSLocalizedString(@"Not available", @"not available label")]; } diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m index 6493e850..d0bbbf75 100644 --- a/Source/SPTableStructureDelegate.m +++ b/Source/SPTableStructureDelegate.m @@ -49,7 +49,7 @@ if([[tableColumn identifier] isEqualToString:@"collation"]) { NSInteger idx = 0; - if((idx = [[NSArrayObjectAtIndex(tableFields,rowIndex) objectForKey:@"encoding"] integerValue]) > 0) { + if((idx = [[NSArrayObjectAtIndex(tableFields,rowIndex) objectForKey:@"encoding"] integerValue]) > 0 && idx < [encodingPopupCell numberOfItems]) { NSString *enc = [[encodingPopupCell itemAtIndex:idx] title]; NSInteger start = [enc rangeOfString:@"("].location+1; NSInteger end = [enc length] - start - 1; -- cgit v1.2.3