Revision: 6992
          http://skim-app.svn.sourceforge.net/skim-app/?rev=6992&view=rev
Author:   hofman
Date:     2010-12-19 22:26:09 +0000 (Sun, 19 Dec 2010)

Log Message:
-----------
make copy of print info and set custom values when loading, also set first and 
last page

Modified Paths:
--------------
    trunk/SKMainDocument.m

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2010-12-18 22:17:23 UTC (rev 6991)
+++ trunk/SKMainDocument.m      2010-12-19 22:26:09 UTC (rev 6992)
@@ -184,8 +184,6 @@
 }
 
 - (void)setDataFromTmpData {
-    [[self undoManager] disableUndoRegistration];
-    
     if ([[tmpData pdfDocument] isLocked])
         [self tryToUnlockDocument:[tmpData pdfDocument]];
     [[self mainWindowController] setPdfDocument:[tmpData pdfDocument]];
@@ -199,14 +197,26 @@
     
     [[self mainWindowController] setRating:[tmpData openMetaRating]];
     
-    [[self undoManager] enableUndoRegistration];
+    [[[self printInfo] dictionary] setValue:[NSNumber 
numberWithInteger:[[tmpData pdfDocument] pageCount]] forKey:NSPrintLastPage];
 }
 
 - (void)windowControllerDidLoadNib:(NSWindowController *)aController{
+    [[self undoManager] disableUndoRegistration];
+    
+    NSPrintInfo *printInfo = [[[self printInfo] copy] autorelease];
+    NSMutableDictionary *printDict = [printInfo dictionary];
+    [printDict setValue:[NSNumber numberWithBool:YES] 
forKey:@"PDFPrintAutoRotate"];
+    [printDict setValue:[NSNumber numberWithInteger:kPDFPrintPageScaleNone] 
forKey:@"PDFPrintScalingMode"];
+    [printDict setValue:[NSNumber numberWithInteger:1] 
forKey:NSPrintFirstPage];
+    [printDict setValue:[NSNumber numberWithInteger:1] forKey:NSPrintLastPage];
+    [self setPrintInfo:printInfo];
+    
     [self setDataFromTmpData];
     [tmpData release];
     tmpData = nil;
     
+    [[self undoManager] enableUndoRegistration];
+    
     [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self 
forKey:SKAutoCheckFileUpdateKey 
context:&SKMainDocumentDefaultsObservationContext];
        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleWindowWillCloseNotification:) 
                                                  
name:NSWindowWillCloseNotification object:[[self mainWindowController] window]];
@@ -843,7 +853,9 @@
     BOOL success = [super revertToContentsOfURL:absoluteURL ofType:typeName 
error:outError];
     
     if (success) {
+        [[self undoManager] disableUndoRegistration];
         [self setDataFromTmpData];
+        [[self undoManager] enableUndoRegistration];
         [[self undoManager] removeAllActions];
         // file watching could have been disabled if the file was deleted
         if (watchedFile == nil && fileUpdateTimer == nil)
@@ -863,7 +875,8 @@
 
 - (IBAction)printDocument:(id)sender{
     BOOL autoRotate = [[[self printInfo] 
valueForKeyPath:@"dictionary.PDFPrintAutoRotate"] boolValue];
-    [[self pdfView] printWithInfo:[self printInfo] autoRotate:autoRotate];
+    PDFPrintScalingMode pageScaling = [[[self printInfo] 
valueForKeyPath:@"dictionary.PDFPrintScalingMode"] integerValue];
+    [[self pdfView] printWithInfo:[self printInfo] autoRotate:autoRotate 
pageScaling:pageScaling];
 }
 
 - (void)readNotesFromURL:(NSURL *)notesURL replace:(BOOL)replace {
@@ -1738,11 +1751,14 @@
 
 - (NSPrintInfo *)printInfo {
     NSPrintInfo *printInfo = [super printInfo];
-    if ([[self pdfDocument] pageCount]) {
+    NSUInteger pageCount = [[self pdfDocument] pageCount];
+    if (pageCount) {
         PDFPage *page = [[self pdfDocument] pageAtIndex:0];
         NSSize pageSize = [page boundsForBox:kPDFDisplayBoxMediaBox].size;
         BOOL isLandscape = [page rotation] % 180 == 90 ? pageSize.height > 
pageSize.width : pageSize.width > pageSize.height;
         
+        [[printInfo dictionary] setValue:[NSNumber numberWithInteger:1] 
forKey:NSPrintFirstPage];
+        [[printInfo dictionary] setValue:[NSNumber 
numberWithInteger:pageCount] forKey:NSPrintLastPage];
         [[printInfo dictionary] setValue:[NSNumber numberWithBool:YES] 
forKey:@"PDFPrintAutoRotate"];
         [printInfo setOrientation:isLandscape ? NSLandscapeOrientation : 
NSPortraitOrientation];
     }
@@ -2020,13 +2036,8 @@
             [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]) {
+        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:NSPrintLastPage];
-            if ([settings objectForKey:NSPrintLastPage] == nil)
-                [settings setObject:[NSNumber numberWithInteger:[[self 
pdfDocument] pageCount]] forKey:NSPrintLastPage];
-        }
         [[printInfo dictionary] addEntriesFromDictionary:settings];
     }
     


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