diff options
Diffstat (limited to 'Source/SPIndexesController.m')
-rw-r--r-- | Source/SPIndexesController.m | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/Source/SPIndexesController.m b/Source/SPIndexesController.m index 989ec02c..8bdfb5bc 100644 --- a/Source/SPIndexesController.m +++ b/Source/SPIndexesController.m @@ -67,6 +67,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; { if ((self = [super initWithWindowNibName:@"IndexesView"])) { + _mainNibLoaded = NO; table = @""; fields = [[NSMutableArray alloc] init]; @@ -102,6 +103,11 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; */ - (void)awakeFromNib { + + // As this controller also loads its own nib, it may call awakeFromNib multiple times; perform setup only once. + if (_mainNibLoaded) return; + _mainNibLoaded = YES; + #ifndef SP_REFACTOR /* patch */ // Set the index tables view's vertical gridlines if required [indexesTableView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone]; @@ -229,6 +235,10 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; [indexedFields removeAllObjects]; [indexedFields addObject:initialField]; + // Determine whether to show or hide the size column initially depending on whether the + // initial key has a required size + [indexSizeTableColumn setHidden:![requiresLength containsObject:[[initialField objectForKey:@"type"] uppercaseString]]]; + [indexedColumnsTableView reloadData]; [addIndexedColumnButton setEnabled:([indexedFields count] < [fields count])]; @@ -401,7 +411,15 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; [indexAdvancedOptionsViewButton setState:showAdvancedView]; [indexAdvancedOptionsView setHidden:(!showAdvancedView)]; - [indexSizeTableColumn setHidden:(!showAdvancedView)]; + // When hiding the advanced options, the size column would normally be hidden as well + // - unless any of the ndexes fields have a required key size. + BOOL hideSizesColumn = !showAdvancedView; + if (hideSizesColumn) { + for (NSDictionary *aField in indexedFields) { + if ([requiresLength containsObject:[[aField objectForKey:@"type"] uppercaseString]]) hideSizesColumn = NO; + } + } + [indexSizeTableColumn setHidden:hideSizesColumn]; [self _resizeWindowForAdvancedOptionsViewByHeightDelta:(showAdvancedView) ? ([indexAdvancedOptionsView frame].size.height + 10) : 0]; } @@ -421,7 +439,11 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; return [[indexes objectAtIndex:rowIndex] objectForKey:[tableColumn identifier]]; } else { - return [[indexedFields objectAtIndex:rowIndex] objectForKey:[tableColumn identifier]]; + id object = [[indexedFields objectAtIndex:rowIndex] objectForKey:[tableColumn identifier]]; + if ([[tableColumn identifier] isEqualToString:@"Size"] && object) { + object = [NSNumber numberWithLongLong:[object longLongValue]]; + } + return object; } } @@ -441,7 +463,16 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; } } else { - [[indexedFields objectAtIndex:rowIndex] setObject:object forKey:[tableColumn identifier]]; + + // Ensure conversion to string for Size column and its formatter + if ([object isKindOfClass:[NSNumber class]]) { + object = [NSString stringWithFormat:@"%llu", [object unsignedLongLongValue]]; + } + if (object) { + [[indexedFields objectAtIndex:rowIndex] setObject:object forKey:[tableColumn identifier]]; + } else { + [[indexedFields objectAtIndex:rowIndex] removeObjectForKey:[tableColumn identifier]]; + } } [self _reloadIndexedColumnsTableData]; @@ -975,6 +1006,10 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; if (indexedFields) [indexedFields release], indexedFields = nil; +#ifndef SP_REFACTOR + [prefs removeObserver:self forKeyPath:SPDisplayTableViewVerticalGridlines]; +#endif + [super dealloc]; } |