diff options
author | stuconnolly <stuart02@gmail.com> | 2012-01-22 12:19:21 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-01-22 12:19:21 +0000 |
commit | 1d7ed99d602bf9c7aa4ea40a9a2ab6458864e51f (patch) | |
tree | 6c08ad29618ea02caf302180706d010c90cd57e0 /Source/SPIndexesController.m | |
parent | e23ba5155a53c43a106ac9646f51321ccc7d86f4 (diff) | |
download | sequelpro-1d7ed99d602bf9c7aa4ea40a9a2ab6458864e51f.tar.gz sequelpro-1d7ed99d602bf9c7aa4ea40a9a2ab6458864e51f.tar.bz2 sequelpro-1d7ed99d602bf9c7aa4ea40a9a2ab6458864e51f.zip |
Bring outlinew view branch up to date with trunk (r3375:3468).
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]; } |