aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableContentDataSource.m
diff options
context:
space:
mode:
authorAbhi Beckert <abhi@Twist-of-Lemon-2.local>2015-05-16 08:06:06 +1000
committerAbhi Beckert <abhi@Twist-of-Lemon-2.local>2015-05-16 08:06:06 +1000
commit57a6f6c73bdaa202164645370d37fcbe5d14a092 (patch)
treedd30aa6156064f1d4c0e10ea87059625470fc2f9 /Source/SPTableContentDataSource.m
parentb5e972f4504043dfb9c358e272e93fb59ae2127f (diff)
parent0f0c43eb74408b6a65a42e2c6fd46f4142ef8e3f (diff)
downloadsequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.tar.gz
sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.tar.bz2
sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.zip
Merge remote-tracking branch 'sequelpro/master'
Diffstat (limited to 'Source/SPTableContentDataSource.m')
-rw-r--r--Source/SPTableContentDataSource.m199
1 files changed, 97 insertions, 102 deletions
diff --git a/Source/SPTableContentDataSource.m b/Source/SPTableContentDataSource.m
index c7af81be..21422865 100644
--- a/Source/SPTableContentDataSource.m
+++ b/Source/SPTableContentDataSource.m
@@ -54,96 +54,92 @@
if (tableView == filterTableView) {
return filterTableIsSwapped ? [filterTableData count] : [[[filterTableData objectForKey:@"0"] objectForKey:SPTableContentFilterKey] count];
}
- else
#endif
- if (tableView == tableContentView) {
- return tableRowsCount;
- }
+ if (tableView == tableContentView) {
+ return tableRowsCount;
+ }
return 0;
}
- (id)tableView:(SPCopyTable *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
{
+ NSUInteger columnIndex = [[tableColumn identifier] integerValue];
#ifndef SP_CODA
if (tableView == filterTableView) {
- if (filterTableIsSwapped)
-
+ if (filterTableIsSwapped) {
// First column shows the field names
- if ([[tableColumn identifier] integerValue] == 0) {
+ if (columnIndex == 0) {
return [[[NSTableHeaderCell alloc] initTextCell:[[filterTableData objectForKey:[NSNumber numberWithInteger:rowIndex]] objectForKey:@"name"]] autorelease];
}
- else {
- return NSArrayObjectAtIndex([[filterTableData objectForKey:[NSNumber numberWithInteger:rowIndex]] objectForKey:SPTableContentFilterKey], [[tableColumn identifier] integerValue] - 1);
- }
- else {
- return NSArrayObjectAtIndex([[filterTableData objectForKey:[tableColumn identifier]] objectForKey:SPTableContentFilterKey], rowIndex);
+
+ return NSArrayObjectAtIndex([[filterTableData objectForKey:[NSNumber numberWithInteger:rowIndex]] objectForKey:SPTableContentFilterKey], columnIndex - 1);
}
+
+ return NSArrayObjectAtIndex([[filterTableData objectForKey:[tableColumn identifier]] objectForKey:SPTableContentFilterKey], rowIndex);
}
- else
#endif
- if (tableView == tableContentView) {
-
- id value = nil;
- NSUInteger columnIndex = [[tableColumn identifier] integerValue];
+ if (tableView == tableContentView) {
+
+ id value = nil;
+
+ // While the table is being loaded, additional validation is required - data
+ // locks must be used to avoid crashes, and indexes higher than the available
+ // rows or columns may be requested. Return "..." to indicate loading in these
+ // cases.
+ if (isWorking) {
+ pthread_mutex_lock(&tableValuesLock);
- // While the table is being loaded, additional validation is required - data
- // locks must be used to avoid crashes, and indexes higher than the available
- // rows or columns may be requested. Return "..." to indicate loading in these
- // cases.
- if (isWorking) {
- pthread_mutex_lock(&tableValuesLock);
-
- if (rowIndex < (NSInteger)tableRowsCount && columnIndex < [tableValues columnCount]) {
- value = [self _contentValueForTableColumn:columnIndex row:rowIndex asPreview:YES];
- }
-
- pthread_mutex_unlock(&tableValuesLock);
-
- if (!value) return @"...";
- }
- else {
- if ([tableView editedColumn] == (NSInteger)columnIndex && [tableView editedRow] == rowIndex) {
- value = [self _contentValueForTableColumn:columnIndex row:rowIndex asPreview:NO];
- }
- else {
- value = [self _contentValueForTableColumn:columnIndex row:rowIndex asPreview:YES];
- }
+ if (rowIndex < (NSInteger)tableRowsCount && columnIndex < [tableValues columnCount]) {
+ value = [self _contentValueForTableColumn:columnIndex row:rowIndex asPreview:YES];
}
-
- NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[tableContentView delegate] dataColumnDefinitions] objectAtIndex:columnIndex];
-
- NSString *columnType = [columnDefinition objectForKey:@"typegrouping"];
- if ([value isKindOfClass:[SPMySQLGeometryData class]]) {
- return [value wktString];
- }
+ pthread_mutex_unlock(&tableValuesLock);
- if ([value isNSNull]) {
- return [prefs objectForKey:SPNullValue];
+ if (!value) return @"...";
+ }
+ else {
+ if ([tableView editedColumn] == (NSInteger)columnIndex && [tableView editedRow] == rowIndex) {
+ value = [self _contentValueForTableColumn:columnIndex row:rowIndex asPreview:NO];
}
-
- if ([value isKindOfClass:[NSData class]]) {
+ else {
+ value = [self _contentValueForTableColumn:columnIndex row:rowIndex asPreview:YES];
+ }
+ }
- if ([columnType isEqualToString:@"binary"] && [prefs boolForKey:SPDisplayBinaryDataAsHex]) {
- return [NSString stringWithFormat:@"0x%@", [value dataToHexString]];
- }
+ NSDictionary *columnDefinition = [[(id <SPDatabaseContentViewDelegate>)[tableContentView delegate] dataColumnDefinitions] objectAtIndex:columnIndex];
- pthread_mutex_t *fieldEditorCheckLock = NULL;
- if (isWorking) {
- fieldEditorCheckLock = &tableValuesLock;
- }
+ NSString *columnType = [columnDefinition objectForKey:@"typegrouping"];
+
+ if ([value isKindOfClass:[SPMySQLGeometryData class]]) {
+ return [value wktString];
+ }
+
+ if ([value isNSNull]) {
+ return [prefs objectForKey:SPNullValue];
+ }
+
+ if ([value isKindOfClass:[NSData class]]) {
- // Always retrieve the short string representation, truncating the value where necessary
- return [value shortStringRepresentationUsingEncoding:[mySQLConnection stringEncoding]];
+ if ([columnType isEqualToString:@"binary"] && [prefs boolForKey:SPDisplayBinaryDataAsHex]) {
+ return [NSString stringWithFormat:@"0x%@", [value dataToHexString]];
}
-
- if ([value isSPNotLoaded]) {
- return NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields");
+
+ pthread_mutex_t *fieldEditorCheckLock = NULL;
+ if (isWorking) {
+ fieldEditorCheckLock = &tableValuesLock;
}
-
- return value;
+
+ // Always retrieve the short string representation, truncating the value where necessary
+ return [value shortStringRepresentationUsingEncoding:[mySQLConnection stringEncoding]];
+ }
+
+ if ([value isSPNotLoaded]) {
+ return NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields");
}
+
+ return value;
+ }
return nil;
}
@@ -163,49 +159,48 @@
return;
}
- else
#endif
- if (tableView == tableContentView) {
-
- // If the current cell should have been edited in a sheet, do nothing - field closing will have already
- // updated the field.
- if ([tableContentView shouldUseFieldEditorForRow:rowIndex column:[[tableColumn identifier] integerValue] checkWithLock:NULL]) {
- return;
- }
-
- // If table data comes from a view, save back to the view
- if ([tablesListInstance tableType] == SPTableTypeView) {
- [self saveViewCellValue:object forTableColumn:tableColumn row:rowIndex];
- return;
- }
-
- // Catch editing events in the row and if the row isn't currently being edited,
- // start an edit. This allows edits including enum changes to save correctly.
- if (isEditingRow && [tableContentView selectedRow] != currentlyEditingRow) {
- [self saveRowOnDeselect];
- }
+ if (tableView == tableContentView) {
+
+ // If the current cell should have been edited in a sheet, do nothing - field closing will have already
+ // updated the field.
+ if ([tableContentView shouldUseFieldEditorForRow:rowIndex column:[[tableColumn identifier] integerValue] checkWithLock:NULL]) {
+ return;
+ }
+
+ // If table data comes from a view, save back to the view
+ if ([tablesListInstance tableType] == SPTableTypeView) {
+ [self saveViewCellValue:object forTableColumn:tableColumn row:rowIndex];
+ return;
+ }
+
+ // Catch editing events in the row and if the row isn't currently being edited,
+ // start an edit. This allows edits including enum changes to save correctly.
+ if (isEditingRow && [tableContentView selectedRow] != currentlyEditingRow) {
+ [self saveRowOnDeselect];
+ }
+
+ if (!isEditingRow) {
+ [oldRow setArray:[tableValues rowContentsAtIndex:rowIndex]];
- if (!isEditingRow) {
- [oldRow setArray:[tableValues rowContentsAtIndex:rowIndex]];
-
- isEditingRow = YES;
- currentlyEditingRow = rowIndex;
+ isEditingRow = YES;
+ currentlyEditingRow = rowIndex;
+ }
+
+ NSDictionary *column = NSArrayObjectAtIndex(dataColumns, [[tableColumn identifier] integerValue]);
+
+ if (object) {
+ // Restore NULLs if necessary
+ if ([object isEqualToString:[prefs objectForKey:SPNullValue]] && [[column objectForKey:@"null"] boolValue]) {
+ object = [NSNull null];
}
- NSDictionary *column = NSArrayObjectAtIndex(dataColumns, [[tableColumn identifier] integerValue]);
-
- if (object) {
- // Restore NULLs if necessary
- if ([object isEqualToString:[prefs objectForKey:SPNullValue]] && [[column objectForKey:@"null"] boolValue]) {
- object = [NSNull null];
- }
-
- [tableValues replaceObjectInRow:rowIndex column:[[tableColumn identifier] integerValue] withObject:object];
- }
- else {
- [tableValues replaceObjectInRow:rowIndex column:[[tableColumn identifier] integerValue] withObject:@""];
- }
+ [tableValues replaceObjectInRow:rowIndex column:[[tableColumn identifier] integerValue] withObject:object];
+ }
+ else {
+ [tableValues replaceObjectInRow:rowIndex column:[[tableColumn identifier] integerValue] withObject:@""];
}
+ }
}
@end