diff options
Diffstat (limited to 'Source/SPTableRelations.m')
-rw-r--r-- | Source/SPTableRelations.m | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/Source/SPTableRelations.m b/Source/SPTableRelations.m index 10780fd1..a88da5e7 100644 --- a/Source/SPTableRelations.m +++ b/Source/SPTableRelations.m @@ -41,6 +41,7 @@ @implementation SPTableRelations @synthesize connection; +@synthesize relationData; /** * init @@ -316,8 +317,7 @@ { // Only proceed if this view is selected. - if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableRelations]) - return; + if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableRelations]) return; [addRelationButton setEnabled:NO]; [refreshRelationsButton setEnabled:NO]; @@ -331,13 +331,13 @@ { // Only proceed if this view is selected. - if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableRelations]) - return; + if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableRelations]) return; if ([relationsTableView isEnabled]) { [addRelationButton setEnabled:YES]; [refreshRelationsButton setEnabled:YES]; } + [removeRelationButton setEnabled:([relationsTableView numberOfSelectedRows] > 0)]; } @@ -345,6 +345,42 @@ #pragma mark Other /** + * Returns an array of relation 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 relation data. + */ +- (NSArray *)relationDataForPrinting +{ + NSMutableArray *headings = [NSMutableArray array]; + NSMutableArray *tempData = [NSMutableArray array]; + NSMutableArray *data = [NSMutableArray array]; + + // Get the relations table view's columns + for (NSTableColumn *column in [relationsTableView tableColumns]) + { + [headings addObject:[[column headerCell] stringValue]]; + } + + [data addObject:headings]; + + // Get the relation data + for (NSDictionary *relation in relationData) + { + NSMutableArray *temp = [NSMutableArray array]; + + [temp addObject:[relation objectForKey:@"name"]]; + [temp addObject:[relation objectForKey:@"columns"]]; + [temp addObject:[relation objectForKey:@"fk_table"]]; + [temp addObject:[relation objectForKey:@"fk_columns"]]; + [temp addObject:([relation objectForKey:@"on_update"]) ? [relation objectForKey:@"on_update"] : @""]; + [temp addObject:([relation objectForKey:@"on_delete"]) ? [relation objectForKey:@"on_delete"] : @""]; + + [data addObject:temp]; + } + + return data; +} + +/** * NSAlert didEnd method. */ - (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo |