diff options
author | stuconnolly <stuart02@gmail.com> | 2010-03-13 14:43:04 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-03-13 14:43:04 +0000 |
commit | f07531d1361e810a63a30f2e3b26313c18b3c302 (patch) | |
tree | 5502ffce3bbee9e6780eb5b56ce19babe2a199c3 | |
parent | 710c28ff5d55ccb26b362d80e866d53d2a4583ad (diff) | |
download | sequelpro-f07531d1361e810a63a30f2e3b26313c18b3c302.tar.gz sequelpro-f07531d1361e810a63a30f2e3b26313c18b3c302.tar.bz2 sequelpro-f07531d1361e810a63a30f2e3b26313c18b3c302.zip |
Add support for printing the table triggers view as well some HTML generation performance improvements.
-rw-r--r-- | Source/SPPrintController.m | 47 | ||||
-rw-r--r-- | Source/SPTableRelations.m | 9 | ||||
-rw-r--r-- | Source/SPTableTriggers.h | 3 | ||||
-rw-r--r-- | Source/SPTableTriggers.m | 43 |
4 files changed, 89 insertions, 13 deletions
diff --git a/Source/SPPrintController.m b/Source/SPPrintController.m index f890ad01..3b0e07c7 100644 --- a/Source/SPPrintController.m +++ b/Source/SPPrintController.m @@ -34,6 +34,7 @@ #import "ICUTemplateMatcher.h" #import "SPConnectionController.h" #import "SPExtendedTableInfo.h" +#import "SPTableTriggers.h" @implementation TableDocument (SPPrintController) @@ -100,7 +101,6 @@ [[printWebView mainFrame] loadHTMLString:([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 3) ? [self generateTableInfoHTMLForPrinting] :[self generateHTMLForPrinting] baseURL:nil]; } - /** * Generates the HTML for the current view that is being printed. */ @@ -146,13 +146,16 @@ } // Table content view else if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1) { - if ([[tableContentInstance currentResult] count] > 1) { + + NSArray *data = [tableContentInstance currentDataResult]; + + if ([data count] > 1) { heading = NSLocalizedString(@"Table Content", @"table content print heading"); rows = [[NSArray alloc] initWithArray: - [[tableContentInstance currentDataResult] objectsAtIndexes: - [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[tableContentInstance currentResult] count] - 1)]] + [data objectsAtIndexes: + [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [data count] - 1)]] ]; [connection setValue:[tableContentInstance usedQuery] forKey:@"query"]; @@ -160,13 +163,16 @@ } // Custom query view else if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 2) { - if ([[customQueryInstance currentResult] count] > 1) { + + NSArray *data = [customQueryInstance currentResult]; + + if ([data count] > 1) { heading = NSLocalizedString(@"Query Result", @"query result print heading"); rows = [[NSArray alloc] initWithArray: - [[customQueryInstance currentResult] objectsAtIndexes: - [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [[customQueryInstance currentResult] count] - 1)]] + [data objectsAtIndexes: + [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [data count] - 1)]] ]; [connection setValue:[customQueryInstance usedQuery] forKey:@"query"]; @@ -174,12 +180,28 @@ } // Table relations view else if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 4) { - if ([[tableRelationsInstance relationDataForPrinting] count] > 1) { + + NSArray *data = [tableRelationsInstance relationDataForPrinting]; + + if ([data count] > 1) { heading = NSLocalizedString(@"Table Relations", @"table relations print heading"); - NSArray *data = [tableRelationsInstance relationDataForPrinting]; + rows = [[NSArray alloc] initWithArray: + [data objectsAtIndexes: + [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, ([data count] - 1))]] + ]; + } + } + // Table triggers view + else if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 5) { + + NSArray *data = [tableTriggersInstance triggerDataForPrinting]; + + if ([data count] > 1) { + heading = NSLocalizedString(@"Table Triggers", @"table triggers print heading"); + rows = [[NSArray alloc] initWithArray: [data objectsAtIndexes: [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, ([data count] - 1))]] @@ -257,6 +279,12 @@ columns = [[NSArray alloc] initWithArray:[[tableRelationsInstance relationDataForPrinting] objectAtIndex:0] copyItems:YES]; } + // Table triggers view + else if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 5 + && [[tableTriggersInstance triggerDataForPrinting] count] > 0) { + + columns = [[NSArray alloc] initWithArray:[[tableTriggersInstance triggerDataForPrinting] objectAtIndex:0] copyItems:YES]; + } if (columns) [columns autorelease]; @@ -285,7 +313,6 @@ [connection setValue:[self table] forKey:@"table"]; } - if ([connectionController port] && [[connectionController port] length]) { [connection setValue:[connectionController port] forKey:@"port"]; } diff --git a/Source/SPTableRelations.m b/Source/SPTableRelations.m index a88da5e7..7d8ef9e3 100644 --- a/Source/SPTableRelations.m +++ b/Source/SPTableRelations.m @@ -350,8 +350,7 @@ */ - (NSArray *)relationDataForPrinting { - NSMutableArray *headings = [NSMutableArray array]; - NSMutableArray *tempData = [NSMutableArray array]; + NSMutableArray *headings = [[NSMutableArray alloc] init]; NSMutableArray *data = [NSMutableArray array]; // Get the relations table view's columns @@ -361,11 +360,13 @@ } [data addObject:headings]; + + [headings release]; // Get the relation data for (NSDictionary *relation in relationData) { - NSMutableArray *temp = [NSMutableArray array]; + NSMutableArray *temp = [[NSMutableArray alloc] init]; [temp addObject:[relation objectForKey:@"name"]]; [temp addObject:[relation objectForKey:@"columns"]]; @@ -375,6 +376,8 @@ [temp addObject:([relation objectForKey:@"on_delete"]) ? [relation objectForKey:@"on_delete"] : @""]; [data addObject:temp]; + + [temp release]; } return data; diff --git a/Source/SPTableTriggers.h b/Source/SPTableTriggers.h index 74e5c9b3..d492253b 100644 --- a/Source/SPTableTriggers.h +++ b/Source/SPTableTriggers.h @@ -68,4 +68,7 @@ - (void)startDocumentTaskForTab:(NSNotification *)notification; - (void)endDocumentTaskForTab:(NSNotification *)notification; +// Other +- (NSArray *)triggerDataForPrinting; + @end diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m index 5ca424e7..26011044 100644 --- a/Source/SPTableTriggers.m +++ b/Source/SPTableTriggers.m @@ -393,6 +393,49 @@ [self _toggleConfirmAddTriggerButtonEnabled]; } +/** + * Returns an array of trigger data to be used for printing purposes. The first element in the array is always + * an array of the columns and each subsequent element is an array of trigger data. + */ +- (NSArray *)triggerDataForPrinting +{ + NSMutableArray *headings = [[NSMutableArray alloc] init]; + NSMutableArray *data = [NSMutableArray array]; + + // Get the relations table view's columns + for (NSTableColumn *column in [triggersTableView tableColumns]) + { + [headings addObject:[[column headerCell] stringValue]]; + } + + // Get rid of the 'Table' column + [headings removeObjectAtIndex:0]; + + [data addObject:headings]; + + [headings release]; + + // Get the relation data + for (NSDictionary *trigger in triggerData) + { + NSMutableArray *temp = [[NSMutableArray alloc] init]; + + [temp addObject:[trigger objectForKey:@"trigger"]]; + [temp addObject:[trigger objectForKey:@"event"]]; + [temp addObject:[trigger objectForKey:@"timing"]]; + [temp addObject:[trigger objectForKey:@"statement"]]; + [temp addObject:[trigger objectForKey:@"definer"]]; + [temp addObject:([trigger objectForKey:@"created"]) ? [trigger objectForKey:@"created"] : @""]; + [temp addObject:[trigger objectForKey:@"sql_mode"]]; + + [data addObject:temp]; + + [temp release]; + } + + return data; +} + #pragma mark - /* |