aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Resources/English.lproj/sequel-pro-print-template.html130
-rw-r--r--Source/TableDocument.m61
2 files changed, 104 insertions, 87 deletions
diff --git a/Resources/English.lproj/sequel-pro-print-template.html b/Resources/English.lproj/sequel-pro-print-template.html
index 9dd2f624..9fe2fe29 100644
--- a/Resources/English.lproj/sequel-pro-print-template.html
+++ b/Resources/English.lproj/sequel-pro-print-template.html
@@ -1,76 +1,86 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
-<title>Sequel Pro</title>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<style type="text/css" media="all">
-html {
- font-size:82%;
-}
-.nowrap {
- white-space:nowrap;
-}
-div.nowrap {
- margin:0;
- padding:0;
-}
-body, table, th, td {
- background-color:#FFFFFF;
- color:#000000;
-}
-table, th, td {
- border:0.1em solid #000000;
-}
+ <title>Sequel Pro</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-table {
- border-collapse:collapse;
- border-spacing:0;
- width: 100%;
-}
+ <style type="text/css" media="all">
+ html {
+ font-size: 82%;
+ }
+
+ .nowrap {
+ white-space: nowrap;
+ }
+
+ div.nowrap {
+ margin: 0;
+ padding: 0;
+ }
+
+ body, table, th, td {
+ background-color: #FFFFFF;
+ color: #000000;
+ }
+
+ table, th, td {
+ border: 0.1em solid #000000;
+ }
-th, td {
- padding:0.2em;
-}
+ table {
+ border-collapse: collapse;
+ border-spacing: 0;
+ width: 100%;
+ }
-th {
- background-color:#E5E5E5;
- font-weight:bold;
-}
+ th, td {
+ padding: 0.2em;
+ }
-tr > td {
- text-align: left;
-}
+ th {
+ background-color: #E5E5E5;
+ font-weight: bold;
+ }
-tr.even > td {
- background-color: #EDF3FE;
-}
+ tr > td {
+ text-align: left;
+ }
-tr.odd > td {
- background-color: #FFFFFF;
-}
+ tr.even > td {
+ background-color: #EDF3FE;
+ }
-</style>
+ tr.odd > td {
+ background-color: #FFFFFF;
+ }
+ </style>
</head>
<body>
-<p>
- <b>Connection:</b> {{c.username}}{% if c.username %}@{% /if %}{{c.hostname}}{% if c.port %}:{% /if %}{{c.port}}/{{c.database}}<br>
- <b>Generated on:</b> {% now | date_format: "dd MMM yyyy 'at' HH:mm:ss" %} by {{c.version}}<br>
- {% if c.query %}<b>SQL query:</b> {{c.query}}{% /if %}
- <br>
-</p>
-<table id="table_results" class="data">
-<thead><tr>
-{% for column in columns %}<th>{{ column }}</th>{% /for %}
-</tr></thead>
+ <p>
+ {% if c.table %}<b>Table:</b> {{c.table}}<br>{% /if %}
+ <b>Connection:</b> {{c.username}}{% if c.username %}@{% /if %}{{c.hostname}}{% if c.port %}:{% /if %}{{c.port}}/{{c.database}}<br>
+ <b>Generated on:</b> {% now | date_format: "dd MMM yyyy 'at' HH:mm:ss" %} by {{c.version}}<br>
+ {% if c.query %}<b>SQL query:</b> {{c.query}}{% /if %}
+ <br>
+ </p>
+
+ <table id="table_results" class="data">
+ <thead>
+ <tr>
+ {% for column in columns %}<th>{{ column }}</th>{% /for %}
+ </tr>
+ </thead>
-<tbody>
-{% for row in rows %}
-<tr {% cycle 'class="odd" ' 'class="even" ' %}>
- {% for cell in row %}<td>{{ cell }}</td>{% /for %}
-</tr>
-{% /for %}
-</tbody>
+ <tbody>
+ {% for row in rows %}
+ <tr {% cycle 'class="odd" ' 'class="even" ' %}>
+ {% for cell in row %}<td>{{ cell }}</td>{% /for %}
+ </tr>
+ {% /for %}
+ </tbody>
</table>
-</body></html>
+</body>
+</html>
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;
}