From f3e421d2e4ba9ec54878968c34044dce89dc6f09 Mon Sep 17 00:00:00 2001 From: bamse16 Date: Thu, 4 Jun 2009 12:44:22 +0000 Subject: Added print accesory view with option to Print Backgrounds --- Source/SPExportController.m | 6 ++++++ Source/SPPrintAccessory.h | 10 ++++++++++ Source/SPPrintAccessory.m | 46 +++++++++++++++++++++++++++++++++++++++++++++ Source/SPSSHTunnel.m | 5 +++++ Source/TableDocument.m | 15 +++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 Source/SPPrintAccessory.h create mode 100644 Source/SPPrintAccessory.m (limited to 'Source') diff --git a/Source/SPExportController.m b/Source/SPExportController.m index 036ba588..d0cc34f9 100644 --- a/Source/SPExportController.m +++ b/Source/SPExportController.m @@ -176,4 +176,10 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn return self; } + +- (void)dealloc +{ + [tables release]; + [super dealloc]; +} @end diff --git a/Source/SPPrintAccessory.h b/Source/SPPrintAccessory.h new file mode 100644 index 00000000..5bdf4343 --- /dev/null +++ b/Source/SPPrintAccessory.h @@ -0,0 +1,10 @@ +#import + + +@interface SPPrintAccessory : NSViewController +{ + IBOutlet NSView *printAccessoryView; + IBOutlet NSUserDefaultsController *defaultsController; +} + +@end diff --git a/Source/SPPrintAccessory.m b/Source/SPPrintAccessory.m new file mode 100644 index 00000000..4128e8ad --- /dev/null +++ b/Source/SPPrintAccessory.m @@ -0,0 +1,46 @@ +#import "SPPrintAccessory.h" +#import + +@implementation SPPrintAccessory + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + defaultsController = [NSUserDefaultsController sharedUserDefaultsController]; + return [super initWithNibName:@"printAccessory" bundle:nibBundleOrNil]; +} + +- (void)awakeFromNib +{ + [self setView:printAccessoryView]; + [defaultsController addObserver:self forKeyPath:@"values.PrintBackground" options:NSKeyValueObservingOptionNew context:@"PrinterSettingsChanged"]; +} + +- (NSArray *)localizedSummaryItems +{ + return [NSArray arrayWithObject:[NSDictionary dictionary]]; +} + +- (NSSet *)keyPathsForValuesAffectingPreview +{ + return [NSSet setWithObjects: + @"defaultsController.values.PrintBackground", +// @"defaultsController.values.PrintGrid", + nil]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + if ([(NSString *)context isEqualToString:@"PrinterSettingsChanged"]) { + [[WebPreferences standardPreferences] setShouldPrintBackgrounds:[[defaultsController valueForKeyPath:@"values.PrintBackground"] boolValue] ]; + } else { + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + } +} + +- (void)dealloc +{ + [defaultsController removeObserver:self forKeyPath:@"values.PrintBackground"]; + [super dealloc]; +} + +@end \ No newline at end of file diff --git a/Source/SPSSHTunnel.m b/Source/SPSSHTunnel.m index 9568efe6..83beb8a7 100644 --- a/Source/SPSSHTunnel.m +++ b/Source/SPSSHTunnel.m @@ -422,4 +422,9 @@ [NSApp stopModalWithCode:[sender tag]]; } +- (void)dealloc +{ + [super dealloc]; +} + @end diff --git a/Source/TableDocument.m b/Source/TableDocument.m index d0b04d5e..6804e5a4 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -46,6 +46,7 @@ #import "MainController.h" #import "SPExtendedTableInfo.h" #import "SPPreferenceController.h" +#import "SPPrintAccessory.h" // Used for printing #import "MGTemplateEngine.h" @@ -134,6 +135,15 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum //add ability to select orientation to print panel NSPrintPanel *printPanel = [op printPanel]; [printPanel setOptions:[printPanel options] + NSPrintPanelShowsOrientation + NSPrintPanelShowsScaling + NSPrintPanelShowsPaperSize]; + + SPPrintAccessory *printAccessory = [[SPPrintAccessory alloc] init]; + [printAccessory initWithNibName:@"printAccessory" bundle:nil]; + [printPanel addAccessoryController:printAccessory]; + + NSPageLayout *pageLayout = [NSPageLayout pageLayout]; + [pageLayout addAccessoryController:printAccessory]; + [printAccessory release]; + [op setPrintPanel:printPanel]; [op runOperationModalForWindow:tableWindow @@ -217,8 +227,13 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum rows, @"rows", nil]; + [connection release]; + [rows release]; + // Process the template and display the results. NSString *result = [engine processTemplateInFileAtPath:templatePath withVariables:print_data]; + NSLog(@"result %@", result); + return result; } -- cgit v1.2.3