diff options
author | stuconnolly <stuart02@gmail.com> | 2010-03-13 15:52:33 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-03-13 15:52:33 +0000 |
commit | 653c9049335bd1604700e454ab3058a72bf13b5c (patch) | |
tree | 9127132e055a742f36dcc14bf6b1b03c91703904 | |
parent | f07531d1361e810a63a30f2e3b26313c18b3c302 (diff) | |
download | sequelpro-653c9049335bd1604700e454ab3058a72bf13b5c.tar.gz sequelpro-653c9049335bd1604700e454ab3058a72bf13b5c.tar.bz2 sequelpro-653c9049335bd1604700e454ab3058a72bf13b5c.zip |
Add support for printing a table's create syntax with syntax highlighting.
-rw-r--r-- | Resources/sequel-pro-table-info-print-template.html | 4 | ||||
-rw-r--r-- | Source/SPExtendedTableInfo.m | 27 |
2 files changed, 24 insertions, 7 deletions
diff --git a/Resources/sequel-pro-table-info-print-template.html b/Resources/sequel-pro-table-info-print-template.html index 30198ec2..acc13ad3 100644 --- a/Resources/sequel-pro-table-info-print-template.html +++ b/Resources/sequel-pro-table-info-print-template.html @@ -142,8 +142,10 @@ <p><em>{{i.comments}}</em></p> {% /if %} + {% if i.createSyntax > 0 %} <h2>Create Syntax</h2> - <pre>{{i.createSyntax}}</pre> + {{i.createSyntax}} + {% /if %} </body> </html> diff --git a/Source/SPExtendedTableInfo.m b/Source/SPExtendedTableInfo.m index 852b1007..30741424 100644 --- a/Source/SPExtendedTableInfo.m +++ b/Source/SPExtendedTableInfo.m @@ -171,11 +171,11 @@ - (IBAction)resetAutoIncrement:(id)sender { - - if([sender tag] == 1) { + if ([sender tag] == 1) { [tableRowAutoIncrement setEditable:YES]; [tableRowAutoIncrement selectText:nil]; - } else { + } + else { [tableRowAutoIncrement setEditable:NO]; [tableSourceInstance resetAutoIncrement:sender]; } @@ -189,12 +189,12 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { - // Listen to ESC to abort editing of auto increment input field if (command == @selector(cancelOperation:) && control == tableRowAutoIncrement) { [tableRowAutoIncrement abortEditing]; return YES; } + return NO; } @@ -368,7 +368,7 @@ } /** - * + * Returns a dictionary describing the information of the table to be used for printing purposes. */ - (NSDictionary *)tableInformationForPrinting { @@ -391,7 +391,22 @@ [tableInfo setObject:[self _formatValueWithKey:@"Data_free" inDictionary:statusFields] forKey:@"sizeFree"]; [tableInfo setObject:[tableCommentsTextView string] forKey:@"comments"]; - [tableInfo setObject:[tableCreateSyntaxTextView string] forKey:@"createSyntax"]; + + NSError *error = nil; + NSArray *HTMLExcludes = [NSArray arrayWithObjects:@"doctype", @"html", @"head", @"body", @"xml", nil]; + + NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:NSHTMLTextDocumentType, NSDocumentTypeDocumentAttribute, HTMLExcludes, NSExcludedElementsDocumentAttribute, nil]; + NSData *HTMLData = [[tableCreateSyntaxTextView textStorage] dataFromRange:NSMakeRange(0, [[tableCreateSyntaxTextView string] length]) documentAttributes:attributes error:&error]; + + if (error != nil) { + NSLog(@"Error generating table's create syntax HTML for printing. Excluding from print out. Error was: %@", [error localizedDescription]); + + return tableInfo; + } + + NSString *HTMLString = [[[NSString alloc] initWithData:HTMLData encoding:NSUTF8StringEncoding] autorelease]; + + [tableInfo setObject:HTMLString forKey:@"createSyntax"]; return tableInfo; } |