From 88f89987a4329b394ee30a2a77705d3afbb35195 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Fri, 12 Mar 2010 01:02:52 +0000 Subject: Various printing support enhancements, including: - Splitting out all printing methods to SPPrintController which is category of TableDocument. - The ability to print table relations. - If present the inclusion of table indexes when printing a table's source. - If the user has use monospaced fonts enables, then the print out's tabular data will be in a monospaced font. - Lots of other style enhancements, including page headings and sections headings. --- Source/TableSource.m | 56 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 15 deletions(-) (limited to 'Source/TableSource.m') diff --git a/Source/TableSource.m b/Source/TableSource.m index ed624445..05eb0c53 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -1115,22 +1115,50 @@ returns a dictionary containing enum/set field names as key and possible values return [NSDictionary dictionaryWithDictionary:enumFields]; } -- (NSArray *)tableStructureForPrint -{ - MCPResult *queryResult; - NSMutableArray *tempResult = [NSMutableArray array]; +/** + * Returns a dictionary describing the source of the table to be used for printing purposes. The object accessible + * via the key 'structure' is an array of the tables fields, where the first element is always the field names + * and each subsequent element is the field data. This is also true for the table's indexes, which are accessible + * via the key 'indexes'. + */ +- (NSDictionary *)tableSourceForPrinting +{ NSInteger i; + NSMutableArray *tempResult = [NSMutableArray array]; + NSMutableArray *tempResult2 = [NSMutableArray array]; + + MCPResult *structureQueryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@", [selectedTable backtickQuotedString]]]; + MCPResult *indexesQueryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW INDEXES FROM %@", [selectedTable backtickQuotedString]]]; + + [structureQueryResult setReturnDataAsStrings:YES]; + [indexesQueryResult setReturnDataAsStrings:YES]; + + if ([structureQueryResult numOfRows]) [structureQueryResult dataSeek:0]; + if ([indexesQueryResult numOfRows]) [indexesQueryResult dataSeek:0]; + + [tempResult addObject:[structureQueryResult fetchFieldNames]]; + + NSMutableArray *temp = [[[indexesQueryResult fetchFieldNames] mutableCopy] autorelease]; - queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@", [selectedTable backtickQuotedString]]]; - [queryResult setReturnDataAsStrings:YES]; + // Remove the 'table' column + [temp removeObjectAtIndex:0]; - if ([queryResult numOfRows]) [queryResult dataSeek:0]; - [tempResult addObject:[queryResult fetchFieldNames]]; - for ( i = 0 ; i < [queryResult numOfRows] ; i++ ) { - [tempResult addObject:[queryResult fetchRowAsArray]]; + [tempResult2 addObject:temp]; + + for (i = 0 ; i < [structureQueryResult numOfRows]; i++) { + [tempResult addObject:[structureQueryResult fetchRowAsArray]]; } - return tempResult; + for (i = 0 ; i < [indexesQueryResult numOfRows]; i++) { + NSMutableArray *index = [[[indexesQueryResult fetchRowAsArray] mutableCopy] autorelease]; + + // Remove the 'table' column values + [index removeObjectAtIndex:0]; + + [tempResult2 addObject:index]; + } + + return [NSDictionary dictionaryWithObjectsAndKeys:tempResult, @"structure", tempResult2, @"indexes", nil]; } #pragma mark - @@ -1143,8 +1171,7 @@ returns a dictionary containing enum/set field names as key and possible values { // Only proceed if this view is selected. - if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure]) - return; + if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure]) return; [tableSourceView setEnabled:NO]; [addFieldButton setEnabled:NO]; @@ -1166,8 +1193,7 @@ returns a dictionary containing enum/set field names as key and possible values { // Only re-enable elements if the current tab is the structure view - if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure]) - return; + if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure]) return; BOOL editingEnabled = ([tablesListInstance tableType] == SP_TABLETYPE_TABLE); [tableSourceView setEnabled:YES]; -- cgit v1.2.3