Revision: 6997
http://skim-app.svn.sourceforge.net/skim-app/?rev=6997&view=rev
Author: hofman
Date: 2010-12-21 13:07:42 +0000 (Tue, 21 Dec 2010)
Log Message:
-----------
Printing PDF documents goes through a single method. Invoke the callback from a
sheet end notification when we use a print sheet, just assume it succeeded
because we don't get access to the return code.
Modified Paths:
--------------
trunk/NSDocument_SKExtensions.h
trunk/NSDocument_SKExtensions.m
trunk/SKApplication.m
trunk/SKMainDocument.h
trunk/SKMainDocument.m
Modified: trunk/NSDocument_SKExtensions.h
===================================================================
--- trunk/NSDocument_SKExtensions.h 2010-12-20 23:24:03 UTC (rev 6996)
+++ trunk/NSDocument_SKExtensions.h 2010-12-21 13:07:42 UTC (rev 6997)
@@ -107,8 +107,6 @@
- (NSDictionary *)documentAttributes;
- (BOOL)isPDFDocument;
-- (void)printDocumentWithSettings:(NSDictionary *)printSettings
showPrintPanel:(BOOL)showPrintPanel;
-
- (void)handleRevertScriptCommand:(NSScriptCommand *)command;
- (void)handleGoToScriptCommand:(NSScriptCommand *)command;
- (id)handleFindScriptCommand:(NSScriptCommand *)command;
Modified: trunk/NSDocument_SKExtensions.m
===================================================================
--- trunk/NSDocument_SKExtensions.m 2010-12-20 23:24:03 UTC (rev 6996)
+++ trunk/NSDocument_SKExtensions.m 2010-12-21 13:07:42 UTC (rev 6997)
@@ -285,10 +285,6 @@
- (BOOL)isPDFDocument { return NO; }
-- (void)printDocumentWithSettings:(NSDictionary *)printSettings
showPrintPanel:(BOOL)showPrintPanel {
- [self printDocumentWithSettings:printSettings
showPrintPanel:showPrintPanel delegate:nil didPrintSelector:NULL
contextInfo:NULL];
-}
-
- (void)handleRevertScriptCommand:(NSScriptCommand *)command {
if ([self fileURL] && [[NSFileManager defaultManager]
fileExistsAtPath:[[self fileURL] path]]) {
if ([self revertToContentsOfURL:[self fileURL] ofType:[self fileType]
error:NULL] == NO) {
Modified: trunk/SKApplication.m
===================================================================
--- trunk/SKApplication.m 2010-12-20 23:24:03 UTC (rev 6996)
+++ trunk/SKApplication.m 2010-12-21 13:07:42 UTC (rev 6997)
@@ -224,39 +224,6 @@
return [super newScriptingObjectOfClass:objectClass forValueForKey:key
withContentsValue:contentsValue properties:properties];
}
-- (id)handlePrintScriptCommand:(NSScriptCommand *)command {
- NSDictionary *args = [command evaluatedArguments];
- id settings = [args objectForKey:@"PrintSettings"];
- BOOL showPanel = [[args objectForKey:@"ShowPrintDialog"] boolValue];
- id dP = [command directParameter];
- NSDocumentController *sdc = [NSDocumentController
sharedDocumentController];
-
- if ([settings isKindOfClass:[NSDictionary class]]) {
- settings = [[settings mutableCopy] autorelease];
- id value;
- if (value = [settings objectForKey:NSPrintDetailedErrorReporting])
- [settings setObject:[NSNumber numberWithBool:[value intValue] ==
'lwdt'] forKey:NSPrintDetailedErrorReporting];
- if ((value = [settings objectForKey:NSPrintPrinterName]) && (value =
[NSPrinter printerWithName:value]))
- [settings setObject:value forKey:NSPrintPrinter];
- }
-
- if ([dP isKindOfClass:[NSArray class]] == NO)
- dP = [NSArray arrayWithObjects:dP, nil];
-
- for (NSURL *url in dP) {
- if ([url isKindOfClass:[NSURL class]] == NO)
- continue;
- id doc = [sdc documentForURL:url];
- if (doc == nil)
- doc = [sdc openDocumentWithContentsOfURL:url display:YES
error:NULL];
- if (doc == nil)
- continue;
- [doc printDocumentWithSettings:settings showPrintPanel:showPanel];
- }
-
- return nil;
-}
-
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
- (id <SKApplicationDelegate>)delegate { return
(<SKApplicationDelegate>)[super delegate]; }
- (void)setDelegate:(id <SKApplicationDelegate>)newDelegate { [super
setDelegate:newDelegate]; }
Modified: trunk/SKMainDocument.h
===================================================================
--- trunk/SKMainDocument.h 2010-12-20 23:24:03 UTC (rev 6996)
+++ trunk/SKMainDocument.h 2010-12-21 13:07:42 UTC (rev 6997)
@@ -92,6 +92,8 @@
// only used for network filesystems; fileUpdateTimer is not retained by
the doc
NSDate *lastModifiedDate;
NSTimer *fileUpdateTimer;
+
+ NSInvocation *printCallback;
}
- (void)undoableActionDoesntDirtyDocument;
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2010-12-20 23:24:03 UTC (rev 6996)
+++ trunk/SKMainDocument.m 2010-12-21 13:07:42 UTC (rev 6997)
@@ -174,6 +174,7 @@
SKDESTROY(lastModifiedDate);
SKDESTROY(progressController);
SKDESTROY(tmpData);
+ SKDESTROY(printCallback);
[super dealloc];
}
@@ -872,14 +873,49 @@
return success;
}
-#pragma mark Actions
+#pragma mark Printing
-- (IBAction)printDocument:(id)sender{
- BOOL autoRotate = [[[self printInfo]
valueForKeyPath:@"dictionary.PDFPrintAutoRotate"] boolValue];
- PDFPrintScalingMode pageScaling = [[[self printInfo]
valueForKeyPath:@"dictionary.PDFPrintScalingMode"] integerValue];
- [[self pdfView] printWithInfo:[self printInfo] autoRotate:autoRotate
pageScaling:pageScaling];
+- (void)handleWindowDidEndPrintSheetNotification:(NSNotification
*)notification {
+ // This is only called to delay a print callback
+ [[NSNotificationCenter defaultCenter] removeObserver:self
name:NSWindowDidEndSheetNotification object:[notification object]];
+ if (printCallback) {
+ BOOL didPrint = YES;
+ [printCallback setArgument:&didPrint atIndex:3];
+ [printCallback invoke];
+ SKDESTROY(printCallback);
+ }
}
+- (void)printDocumentWithSettings:(NSDictionary *)printSettings
showPrintPanel:(BOOL)showPrintPanel delegate:(id)delegate
didPrintSelector:(SEL)didPrintSelector contextInfo:(void *)contextInfo {
+ NSPrintInfo *printInfo = [[[self printInfo] copy] autorelease];
+ NSMutableDictionary *infoDict = [printInfo dictionary];
+
+ [infoDict addEntriesFromDictionary:printSettings];
+ if (showPrintPanel == NO)
+ [infoDict setObject:[NSNumber numberWithBool:YES]
forKey:SKSuppressPrintPanel];
+
+ BOOL autoRotate = [[infoDict objectForKey:@"PDFPrintAutoRotate"]
boolValue];
+ PDFPrintScalingMode pageScaling = [[infoDict
objectForKey:@"PDFPrintScalingMode"] integerValue];
+
+ [[self pdfView] printWithInfo:printInfo autoRotate:autoRotate
pageScaling:pageScaling];
+
+ if (delegate && didPrintSelector) {
+ NSInvocation *invocation = [NSInvocation invocationWithTarget:delegate
selector:didPrintSelector];
+ [invocation setArgument:&self atIndex:2];
+ [invocation setArgument:&contextInfo atIndex:4];
+ if (showPrintPanel && [[[self mainWindowController] window]
attachedSheet]) {
+ printCallback = [invocation retain];
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleWindowDidEndPrintSheetNotification:)
name:NSWindowDidEndSheetNotification object:[self windowForSheet]];
+ } else {
+ BOOL didPrint = YES;
+ [invocation setArgument:&didPrint atIndex:3];
+ [invocation invoke];
+ }
+ }
+}
+
+#pragma mark Actions
+
- (void)readNotesFromURL:(NSURL *)notesURL replace:(BOOL)replace {
NSString *extension = [[notesURL path] pathExtension];
NSArray *array = nil;
@@ -1969,26 +2005,6 @@
return YES;
}
-- (void)printDocumentWithSettings:(NSDictionary *)printSettings
showPrintPanel:(BOOL)showPrintPanel {
- NSPrintInfo *printInfo = [[[self printInfo] copy] autorelease];
-
- if ([printSettings objectForKey:NSPrintFirstPage] || [printSettings
objectForKey:NSPrintLastPage]) {
- NSMutableDictionary *settings = [[settings mutableCopy] autorelease];
- [settings setObject:[NSNumber numberWithBool:NO]
forKey:NSPrintAllPages];
- if ([settings objectForKey:NSPrintFirstPage] == nil)
- [settings setObject:[NSNumber numberWithInteger:1]
forKey:NSPrintFirstPage];
- if ([settings objectForKey:NSPrintLastPage] == nil)
- [settings setObject:[NSNumber numberWithInteger:[[self
pdfDocument] pageCount]] forKey:NSPrintLastPage];
- printSettings = settings;
- }
-
- [[printInfo dictionary] addEntriesFromDictionary:printSettings];
- if (showPrintPanel == NO)
- [[printInfo dictionary] setObject:[NSNumber numberWithBool:YES]
forKey:SKSuppressPrintPanel];
-
- [[self pdfView] printWithInfo:printInfo autoRotate:YES];
-}
-
- (id)newScriptingObjectOfClass:(Class)class forValueForKey:(NSString *)key
withContentsValue:(id)contentsValue properties:(NSDictionary *)properties {
if ([key isEqualToString:@"notes"]) {
PDFAnnotation *annotation = nil;
@@ -2038,28 +2054,6 @@
return [super handleSaveScriptCommand:command];
}
-- (id)handlePrintScriptCommand:(NSScriptCommand *)command {
- NSDictionary *args = [command evaluatedArguments];
- id settings = [args objectForKey:@"PrintSettings"];
- id showPanel = [args objectForKey:@"ShowPrintDialog"];
-
- NSPrintInfo *printInfo = [[[self printInfo] copy] autorelease];
-
- if ([settings isKindOfClass:[NSDictionary class]]) {
- settings = [[settings mutableCopy] autorelease];
- id value;
- if (value = [settings objectForKey:NSPrintDetailedErrorReporting])
- [settings setObject:[NSNumber numberWithBool:[value intValue] ==
'lwdt'] forKey:NSPrintDetailedErrorReporting];
- if ((value = [settings objectForKey:NSPrintPrinterName]) && (value =
[NSPrinter printerWithName:value]))
- [settings setObject:value forKey:NSPrintPrinter];
- [[printInfo dictionary] addEntriesFromDictionary:settings];
- }
-
- [self printDocumentWithSettings:settings showPrintPanel:[showPanel
boolValue]];
-
- return nil;
-}
-
- (void)handleRevertScriptCommand:(NSScriptCommand *)command {
if ([self fileURL] && [[NSFileManager defaultManager]
fileExistsAtPath:[[self fileURL] path]]) {
if (docFlags.isUpdatingFile == NO && [self revertToContentsOfURL:[self
fileURL] ofType:[self fileType] error:NULL] == NO) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit