aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-01-11 01:06:12 +0000
committerrowanbeentje <rowan@beent.je>2012-01-11 01:06:12 +0000
commit425a60ca9fe7b7e9883542c80a80328f9b6eb625 (patch)
tree7aed7bded8d051246c81d57ab9e0721abe2c40c2 /Source
parent9d22f2feaf57a9bc15c258b932c7254d2a665c26 (diff)
downloadsequelpro-425a60ca9fe7b7e9883542c80a80328f9b6eb625.tar.gz
sequelpro-425a60ca9fe7b7e9883542c80a80328f9b6eb625.tar.bz2
sequelpro-425a60ca9fe7b7e9883542c80a80328f9b6eb625.zip
Improve index addition, especially where key sizes are required:
- Fix exceptions caused by the sizes column formatter requiring a NSNumber - When displaying the indexes view ensure the sizes column is hidden by default, as the advanced view is closed - unless a field with a required size has been selected - If a field with a required size has been selected, don't hide the sizes column when collapsing the advanaced view
Diffstat (limited to 'Source')
-rw-r--r--Source/SPIndexesController.m31
1 files changed, 28 insertions, 3 deletions
diff --git a/Source/SPIndexesController.m b/Source/SPIndexesController.m
index 92a0ddf6..26e4b196 100644
--- a/Source/SPIndexesController.m
+++ b/Source/SPIndexesController.m
@@ -246,6 +246,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])];
@@ -431,7 +435,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];
#endif
@@ -452,7 +464,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;
}
}
@@ -472,7 +488,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];