Permalink
Browse files

Fix some threading issues during print output generation (#3025)

  • Loading branch information...
dmoagx committed Apr 20, 2018
1 parent 5a531bc commit 0a2228435cae7db15af7574eb829eab5799f7704
Showing with 91 additions and 91 deletions.
  1. +91 −91 Source/SPDatabaseDocument.m
@@ -7414,130 +7414,130 @@ - (void)generateHTMLForPrinting
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Set up template engine with your chosen matcher
MGTemplateEngine *engine = [MGTemplateEngine templateEngine];
[engine setMatcher:[ICUTemplateMatcher matcherWithTemplateEngine:engine]];
NSMutableDictionary *connection = [NSMutableDictionary dictionary];
NSMutableDictionary *printData = [NSMutableDictionary dictionary];
NSMutableDictionary *connection = [self connectionInformation];
SPMainQSync(^{
[connection setDictionary:[self connectionInformation]];
[printData setObject:[self columnNames] forKey:@"columns"];
SPTableViewType view = [self currentlySelectedView];
NSString *heading = @"";
NSArray *rows, *indexes, *indexColumns = nil;
NSString *heading = @"";
NSArray *columns = [self columnNames];
// Table source view
if (view == SPTableViewStructure) {
NSMutableDictionary *printData = [NSMutableDictionary dictionary];
NSDictionary *tableSource = [tableSourceInstance tableSourceForPrinting];
SPTableViewType view = [self currentlySelectedView];
NSInteger tableType = [tablesListInstance tableType];
// Table source view
if (view == SPTableViewStructure) {
switch (tableType) {
case SPTableTypeTable:
heading = NSLocalizedString(@"Table Structure", @"table structure print heading");
break;
case SPTableTypeView:
heading = NSLocalizedString(@"View Structure", @"view structure print heading");
break;
}
NSDictionary *tableSource = [tableSourceInstance tableSourceForPrinting];
NSArray *rows = [[NSArray alloc] initWithArray:
[[tableSource objectForKey:@"structure"] objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableSource objectForKey:@"structure"] count] - 1)]]
];
NSInteger tableType = [tablesListInstance tableType];
NSArray *indexes = [[NSArray alloc] initWithArray:
[[tableSource objectForKey:@"indexes"] objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableSource objectForKey:@"indexes"] count] - 1)]]
];
switch (tableType) {
case SPTableTypeTable:
heading = NSLocalizedString(@"Table Structure", @"table structure print heading");
break;
case SPTableTypeView:
heading = NSLocalizedString(@"View Structure", @"view structure print heading");
break;
}
NSArray *indexColumns = [[tableSource objectForKey:@"indexes"] objectAtIndex:0];
rows = [[NSArray alloc] initWithArray:
[[tableSource objectForKey:@"structure"] objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableSource objectForKey:@"structure"] count] - 1)]]
];
[printData setObject:rows forKey:@"rows"];
[printData setObject:indexes forKey:@"indexes"];
[printData setObject:indexColumns forKey:@"indexColumns"];
indexes = [[NSArray alloc] initWithArray:
[[tableSource objectForKey:@"indexes"] objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableSource objectForKey:@"indexes"] count] - 1)]]
];
if ([indexes count]) [printData setObject:@1 forKey:@"hasIndexes"];
indexColumns = [[tableSource objectForKey:@"indexes"] objectAtIndex:0];
[rows release];
[indexes release];
}
// Table content view
else if (view == SPTableViewContent) {
[printData setObject:rows forKey:@"rows"];
[printData setObject:indexes forKey:@"indexes"];
[printData setObject:indexColumns forKey:@"indexColumns"];
NSArray *data = [tableContentInstance currentDataResultWithNULLs:NO hideBLOBs:YES];
if ([indexes count]) [printData setObject:@1 forKey:@"hasIndexes"];
heading = NSLocalizedString(@"Table Content", @"table content print heading");
[rows release];
[indexes release];
}
// Table content view
else if (view == SPTableViewContent) {
NSArray *rows = [[NSArray alloc] initWithArray:
[data objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [data count] - 1)]]
];
NSArray *data = [tableContentInstance currentDataResultWithNULLs:NO hideBLOBs:YES];
[printData setObject:rows forKey:@"rows"];
[connection setValue:[tableContentInstance usedQuery] forKey:@"query"];
heading = NSLocalizedString(@"Table Content", @"table content print heading");
[rows release];
}
// Custom query view
else if (view == SPTableViewCustomQuery) {
rows = [[NSArray alloc] initWithArray:
[data objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [data count] - 1)]]
];
NSArray *data = [customQueryInstance currentResult];
[printData setObject:rows forKey:@"rows"];
[connection setValue:[tableContentInstance usedQuery] forKey:@"query"];
heading = NSLocalizedString(@"Query Result", @"query result print heading");
[rows release];
}
// Custom query view
else if (view == SPTableViewCustomQuery) {
NSArray *rows = [[NSArray alloc] initWithArray:
[data objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [data count] - 1)]]
];
NSArray *data = [customQueryInstance currentResult];
[printData setObject:rows forKey:@"rows"];
[connection setValue:[customQueryInstance usedQuery] forKey:@"query"];
heading = NSLocalizedString(@"Query Result", @"query result print heading");
[rows release];
}
// Table relations view
else if (view == SPTableViewRelations) {
rows = [[NSArray alloc] initWithArray:
[data objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [data count] - 1)]]
];
NSArray *data = [tableRelationsInstance relationDataForPrinting];
[printData setObject:rows forKey:@"rows"];
[connection setValue:[customQueryInstance usedQuery] forKey:@"query"];
heading = NSLocalizedString(@"Table Relations", @"toolbar item label for switching to the Table Relations tab");
[rows release];
}
// Table relations view
else if (view == SPTableViewRelations) {
NSArray *rows = [[NSArray alloc] initWithArray:
[data objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, ([data count] - 1))]]
];
NSArray *data = [tableRelationsInstance relationDataForPrinting];
[printData setObject:rows forKey:@"rows"];
heading = NSLocalizedString(@"Table Relations", @"toolbar item label for switching to the Table Relations tab");
[rows release];
}
// Table triggers view
else if (view == SPTableViewTriggers) {
rows = [[NSArray alloc] initWithArray:
[data objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, ([data count] - 1))]]
];
NSArray *data = [tableTriggersInstance triggerDataForPrinting];
[printData setObject:rows forKey:@"rows"];
heading = NSLocalizedString(@"Table Triggers", @"toolbar item label for switching to the Table Triggers tab");
[rows release];
}
// Table triggers view
else if (view == SPTableViewTriggers) {
NSArray *rows = [[NSArray alloc] initWithArray:
[data objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, ([data count] - 1))]]
];
NSArray *data = [tableTriggersInstance triggerDataForPrinting];
[printData setObject:rows forKey:@"rows"];
heading = NSLocalizedString(@"Table Triggers", @"toolbar item label for switching to the Table Triggers tab");
[rows release];
}
rows = [[NSArray alloc] initWithArray:
[data objectsAtIndexes:
[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, ([data count] - 1))]]
];
[printData setObject:heading forKey:@"heading"];
});
[printData setObject:rows forKey:@"rows"];
// Set up template engine with your chosen matcher
MGTemplateEngine *engine = [MGTemplateEngine templateEngine];
[rows release];
}
[engine setMatcher:[ICUTemplateMatcher matcherWithTemplateEngine:engine]];
[engine setObject:connection forKey:@"c"];
[printData setObject:heading forKey:@"heading"];
[printData setObject:columns forKey:@"columns"];
[printData setObject:([prefs boolForKey:SPUseMonospacedFonts]) ? SPDefaultMonospacedFontName : @"Lucida Grande" forKey:@"font"];
[printData setObject:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? @"1px solid #CCCCCC" : @"none" forKey:@"gridlines"];
@@ -7643,12 +7643,12 @@ - (NSArray *)columnNames
*/
- (NSMutableDictionary *)connectionInformation
{
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *versionForPrint = [NSString stringWithFormat:@"%@ %@ (%@ %@)",
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"],
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],
NSLocalizedString(@"build", @"build label"),
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
];
[infoDict objectForKey:@"CFBundleName"],
[infoDict objectForKey:@"CFBundleShortVersionString"],
NSLocalizedString(@"build", @"build label"),
[infoDict objectForKey:@"CFBundleVersion"]];
NSMutableDictionary *connection = [NSMutableDictionary dictionary];

0 comments on commit 0a22284

Please sign in to comment.