diff options
author | stuconnolly <stuart02@gmail.com> | 2010-03-10 20:33:51 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-03-10 20:33:51 +0000 |
commit | e92951358fd80fb42f33fe4ce0e33a39939a9bf3 (patch) | |
tree | 4826063b6fd9b786a8f461b644a5d954a6bc3a51 /Source/TableDocument.m | |
parent | b2f78ecd1395905c8031d4a2a670128c2d06c1e7 (diff) | |
download | sequelpro-e92951358fd80fb42f33fe4ce0e33a39939a9bf3.tar.gz sequelpro-e92951358fd80fb42f33fe4ce0e33a39939a9bf3.tar.bz2 sequelpro-e92951358fd80fb42f33fe4ce0e33a39939a9bf3.zip |
Include the current table name in printing support. Fixes issue #501.
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r-- | Source/TableDocument.m | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 2ce0ef9e..249faee9 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -779,7 +779,7 @@ - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { - //because I need the webFrame loaded (for preview), I've moved the actuall printing here. + // Because I need the webFrame loaded (for preview), I've moved the actuall printing here. NSPrintInfo *printInfo = [self printInfo]; [printInfo setHorizontalPagination:NSFitPagination]; [printInfo setVerticalPagination:NSAutoPagination]; @@ -817,21 +817,20 @@ - (IBAction)printDocument:(id)sender { - //here load the printing document. The actual printing is done in the doneLoading delegate. + // Here load the printing document. The actual printing is done in the doneLoading delegate. [[printWebView mainFrame] loadHTMLString:[self getHTMLforPrint] baseURL:nil]; } -- (void)printOperationDidRun:(NSPrintOperation *)printOperation - success:(BOOL)success - contextInfo:(void *)info +- (void)printOperationDidRun:(NSPrintOperation *)printOperation success:(BOOL)success contextInfo:(void *)info { - //selector for print... maybe we can get rid of this? + // Selector for print... maybe we can get rid of this? } - (NSString *)getHTMLforPrint { // Set up template engine with your chosen matcher. MGTemplateEngine *engine = [MGTemplateEngine templateEngine]; + [engine setMatcher:[ICUTemplateMatcher matcherWithTemplateEngine:engine]]; NSString *versionForPrint = [NSString stringWithFormat:@"%@ %@ (build %@)", @@ -841,58 +840,66 @@ ]; NSMutableDictionary *connection = [[NSMutableDictionary alloc] init]; - if([[self user] length]) + + if ([[self user] length]) { [connection setValue:[self user] forKey:@"username"]; + } + + if ([[self table] length]) { + [connection setValue:[self table] forKey:@"table"]; + } + [connection setValue:[self host] forKey:@"hostname"]; - if([connectionController port] &&[[connectionController port] length]) + + if ([connectionController port] && [[connectionController port] length]) { [connection setValue:[connectionController port] forKey:@"port"]; + } + [connection setValue:selectedDatabase forKey:@"database"]; [connection setValue:versionForPrint forKey:@"version"]; - NSArray *columns, *rows; - rows = nil; - columns = [self columnNames]; + NSArray *rows = nil; + NSArray *columns = [self columnNames]; - if ( [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 0 ){ - if([[tableSourceInstance tableStructureForPrint] count] > 1) + if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 0) { + if ([[tableSourceInstance tableStructureForPrint] count] > 1) rows = [[NSArray alloc] initWithArray: [[tableSourceInstance tableStructureForPrint] objectsAtIndexes: - [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableSourceInstance tableStructureForPrint] count]-1)] + [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableSourceInstance tableStructureForPrint] count] - 1)] ] ]; } - else if ( [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1 ){ - if([[tableContentInstance currentResult] count] > 1) + else if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1) { + if ([[tableContentInstance currentResult] count] > 1) rows = [[NSArray alloc] initWithArray: [[tableContentInstance currentDataResult] objectsAtIndexes: - [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableContentInstance currentResult] count]-1)] + [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableContentInstance currentResult] count] - 1)] ] ]; + [connection setValue:[tableContentInstance usedQuery] forKey:@"query"]; } - else if ( [tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 2 ){ - if([[customQueryInstance currentResult] count] > 1) + else if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 2) { + if ([[customQueryInstance currentResult] count] > 1) rows = [[NSArray alloc] initWithArray: [[customQueryInstance currentResult] objectsAtIndexes: - [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[customQueryInstance currentResult] count]-1)] + [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[customQueryInstance currentResult] count] - 1)] ] ]; + [connection setValue:[customQueryInstance usedQuery] forKey:@"query"]; } [engine setObject:connection forKey:@"c"]; - // Get path to template. - NSString *templatePath = [[NSBundle mainBundle] pathForResource:@"sequel-pro-print-template" ofType:@"html"]; - NSDictionary *print_data = [NSDictionary dictionaryWithObjectsAndKeys: - columns, @"columns", - rows, @"rows", - nil]; + + NSDictionary *printData = [NSDictionary dictionaryWithObjectsAndKeys:columns, @"columns", rows, @"rows", nil]; [connection release]; + if (rows) [rows release]; // Process the template and display the results. - NSString *result = [engine processTemplateInFileAtPath:templatePath withVariables:print_data]; + NSString *result = [engine processTemplateInFileAtPath:[[NSBundle mainBundle] pathForResource:@"sequel-pro-print-template" ofType:@"html"] withVariables:printData]; return result; } |