Revision: 6996
          http://skim-app.svn.sourceforge.net/skim-app/?rev=6996&view=rev
Author:   hofman
Date:     2010-12-20 23:24:03 +0000 (Mon, 20 Dec 2010)

Log Message:
-----------
Override application print scripting. Ignoring any errors as well as callbacks. 
PDFKit does not allow to get any callbacks. Using private method is dangerous, 
especially as there most definitely is a cleanup method we don't know how to 
use.

Modified Paths:
--------------
    trunk/NSDocument_SKExtensions.h
    trunk/NSDocument_SKExtensions.m
    trunk/SKApplication.m
    trunk/SKMainDocument.m

Modified: trunk/NSDocument_SKExtensions.h
===================================================================
--- trunk/NSDocument_SKExtensions.h     2010-12-20 00:58:44 UTC (rev 6995)
+++ trunk/NSDocument_SKExtensions.h     2010-12-20 23:24:03 UTC (rev 6996)
@@ -107,6 +107,8 @@
 - (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 00:58:44 UTC (rev 6995)
+++ trunk/NSDocument_SKExtensions.m     2010-12-20 23:24:03 UTC (rev 6996)
@@ -285,6 +285,10 @@
 
 - (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 00:58:44 UTC (rev 6995)
+++ trunk/SKApplication.m       2010-12-20 23:24:03 UTC (rev 6996)
@@ -224,6 +224,39 @@
     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.m
===================================================================
--- trunk/SKMainDocument.m      2010-12-20 00:58:44 UTC (rev 6995)
+++ trunk/SKMainDocument.m      2010-12-20 23:24:03 UTC (rev 6996)
@@ -880,18 +880,6 @@
     [[self pdfView] printWithInfo:[self printInfo] autoRotate:autoRotate 
pageScaling:pageScaling];
 }
 
-- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)printSettings 
error:(NSError **)outError {
-    NSPrintOperation *printOperation = nil;
-    SKPDFDocument *pdfDoc = (SKPDFDocument *)[self pdfDocument];
-    NSPrintInfo *printInfo = [[[self printInfo] copy] autorelease];
-    BOOL autoRotate = [[printInfo 
valueForKeyPath:@"dictionary.PDFPrintAutoRotate"] boolValue];
-    [[printInfo dictionary] addEntriesFromDictionary:printSettings];
-    printOperation = [pdfDoc getPrintOperationForPrintInfo:printInfo 
autoRotate:autoRotate];
-    if (printOperation == nil)
-        printOperation = [super printOperationWithSettings:printSettings 
error:outError];
-    return printOperation;
-}
-
 - (void)readNotesFromURL:(NSURL *)notesURL replace:(BOOL)replace {
     NSString *extension = [[notesURL path] pathExtension];
     NSArray *array = nil;
@@ -1981,6 +1969,26 @@
     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;
@@ -2044,21 +2052,11 @@
             [settings setObject:[NSNumber numberWithBool:[value intValue] == 
'lwdt'] forKey:NSPrintDetailedErrorReporting];
         if ((value = [settings objectForKey:NSPrintPrinterName]) && (value = 
[NSPrinter printerWithName:value]))
             [settings setObject:value forKey:NSPrintPrinter];
-        if ([settings objectForKey:NSPrintFirstPage] || [settings 
objectForKey:NSPrintLastPage]) {
-            [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];
-        }
         [[printInfo dictionary] addEntriesFromDictionary:settings];
     }
     
-    if ([showPanel boolValue] == NO)
-        [[printInfo dictionary] setObject:[NSNumber numberWithBool:YES] 
forKey:SKSuppressPrintPanel];
+    [self printDocumentWithSettings:settings showPrintPanel:[showPanel 
boolValue]];
     
-    [[self pdfView] printWithInfo:printInfo autoRotate:YES];
-    
     return nil;
 }
 


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

Reply via email to