Revision: 4196
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4196&view=rev
Author:   hofman
Date:     2008-07-12 04:51:29 -0700 (Sat, 12 Jul 2008)

Log Message:
-----------
Add a hidden pref to use logical page numbers for page labels. Implemented by 
passing all calls to the page's label through a new PDFPage accessor.

Modified Paths:
--------------
    trunk/PDFPage_SKExtensions.h
    trunk/PDFPage_SKExtensions.m
    trunk/PDFSelection_SKExtensions.m
    trunk/SKMainWindowController.m
    trunk/SKMainWindowController_UI.m
    trunk/SKNoteWindowController.m
    trunk/SKPDFHoverWindow.m
    trunk/SKSecondaryPDFView.m
    trunk/SKSnapshotWindowController.m
    trunk/SKStringConstants.h
    trunk/SKStringConstants.m

Modified: trunk/PDFPage_SKExtensions.h
===================================================================
--- trunk/PDFPage_SKExtensions.h        2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/PDFPage_SKExtensions.h        2008-07-12 11:51:29 UTC (rev 4196)
@@ -69,6 +69,8 @@
 - (NSArray *)lineBounds;
 
 - (unsigned int)pageIndex;
+- (NSString *)logicalLabel;
+- (NSString *)displayLabel;
 
 - (NSScriptObjectSpecifier *)objectSpecifier;
 - (SKPDFDocument *)containingDocument;

Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m        2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/PDFPage_SKExtensions.m        2008-07-12 11:51:29 UTC (rev 4196)
@@ -323,6 +323,17 @@
     return [[self document] indexForPage:self];
 }
 
+- (NSString *)logicalLabel {
+    return [NSString stringWithFormat:@"%u", [self pageIndex] + 1];
+}
+
+- (NSString *)displayLabel {
+    NSString *label = nil;
+    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKLogicalPageNumberingKey] == NO)
+        label = [self label];
+    return label ? label : [self logicalLabel];
+}
+
 #pragma mark Scripting support
 
 - (NSScriptObjectSpecifier *)objectSpecifier {

Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m   2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/PDFSelection_SKExtensions.m   2008-07-12 11:51:29 UTC (rev 4196)
@@ -54,7 +54,7 @@
 // returns the label of the first page (if the selection spans multiple pages)
 - (NSString *)firstPageLabel { 
     NSArray *pages = [self pages];
-    return [pages count] ? [[pages objectAtIndex:0] label] : nil;
+    return [pages count] ? [[pages objectAtIndex:0] displayLabel] : nil;
 }
 
 - (NSAttributedString *)contextString {

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/SKMainWindowController.m      2008-07-12 11:51:29 UTC (rev 4196)
@@ -696,20 +696,16 @@
 
 - (void)updatePageLabelsAndOutline {
     PDFDocument *pdfDoc = [pdfView document];
-    int i, count = [pdfDoc pageCount];
+    unsigned int i, count = [pdfDoc pageCount];
     
     // update page labels, also update the size of the table columns 
displaying the labels
     [self willChangeValueForKey:SKMainWindowPageLabelsKey];
     [pageLabels removeAllObjects];
-    for (i = 0; i < count; i++) {
-        NSString *label = [[pdfDoc pageAtIndex:i] label];
-        if (label == nil)
-            label = [NSString stringWithFormat:@"%i", i+1];
-        [pageLabels addObject:label];
-    }
+    for (i = 0; i < count; i++)
+        [pageLabels addObject:[[pdfDoc pageAtIndex:i] displayLabel]];
     [self didChangeValueForKey:SKMainWindowPageLabelsKey];
     
-    [self setPageLabel:[[pdfView currentPage] label]];
+    [self setPageLabel:[[pdfView currentPage] displayLabel]];
     
     [self updatePageColumnWidthForTableView:thumbnailTableView];
     [self updatePageColumnWidthForTableView:snapshotTableView];
@@ -913,7 +909,7 @@
 }
 
 - (void)updatePageLabel {
-    NSString *label = [[pdfView currentPage] label];
+    NSString *label = [[pdfView currentPage] displayLabel];
     if (label != pageLabel) {
         [self willChangeValueForKey:SKMainWindowPageLabelKey];
         [pageLabel release];
@@ -928,7 +924,7 @@
 
 - (void)setPageLabel:(NSString *)label {
     unsigned int idx = [pageLabels indexOfObject:label];
-    if (idx != NSNotFound && [[[pdfView currentPage] label] isEqual:label] == 
NO)
+    if (idx != NSNotFound && [[[pdfView currentPage] displayLabel] 
isEqual:label] == NO)
         [self goToPage:[[pdfView document] pageAtIndex:idx]];
 }
 

Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m   2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/SKMainWindowController_UI.m   2008-07-12 11:51:29 UTC (rev 4196)
@@ -292,7 +292,7 @@
             SKGroupedSearchResult *result = [groupedSearchResults 
objectAtIndex:idx];
             NSArray *matches = [result matches];
             [string appendString:@"* "];
-            [string appendFormat:NSLocalizedString(@"Page %@", @""), [[result 
page] label]];
+            [string appendFormat:NSLocalizedString(@"Page %@", @""), [[result 
page] displayLabel]];
             [string appendString:@": "];
             [string appendFormat:NSLocalizedString(@"%i Results", @""), 
[matches count]];
             [string appendFormat:@":[EMAIL PROTECTED]", [[matches 
valueForKeyPath:@"contextString.string"] componentsJoinedByString:@"\n\t"]];
@@ -473,7 +473,7 @@
         if([tcID isEqualToString:SKMainWindowLabelColumnIdentifer]){
             return [(PDFOutline *)item label];
         }else if([tcID isEqualToString:SKMainWindowPageColumnIdentifer]){
-            return [[[(PDFOutline *)item destination] page] label];
+            return [[[(PDFOutline *)item destination] page] displayLabel];
         }else{
             [NSException raise:@"Unexpected tablecolumn identifier" format:@" 
- %@ ", tcID];
             return nil;
@@ -485,7 +485,7 @@
         } else if([tcID isEqualToString:SKMainWindowTypeColumnIdentifer]) {
             return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber 
numberWithBool:item == [pdfView activeAnnotation]], 
SKAnnotationTypeImageCellActiveKey, [item type], 
SKAnnotationTypeImageCellTypeKey, nil];
         } else if([tcID isEqualToString:SKMainWindowPageColumnIdentifer]) {
-            return [[item page] label];
+            return [[item page] displayLabel];
         }
     }
     return nil;

Modified: trunk/SKNoteWindowController.m
===================================================================
--- trunk/SKNoteWindowController.m      2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/SKNoteWindowController.m      2008-07-12 11:51:29 UTC (rev 4196)
@@ -49,6 +49,7 @@
 #import "NSUserDefaultsController_SKExtensions.h"
 #import "SKStringConstants.h"
 #import "SKUtilities.h"
+#import "PDFPage_SKExtensions.h"
 
 static NSString *SKNoteWindowFrameAutosaveName = @"SKNoteWindow";
 
@@ -124,7 +125,7 @@
 
 - (void)updateStatusMessage {
     NSRect bounds = [note bounds];
-    [statusBar setLeftStringValue:[NSString 
stringWithFormat:NSLocalizedString(@"Page %@ at (%i, %i)", @"Status message"), 
[[note page] label], (int)NSMidX(bounds), (int)NSMidY(bounds)]];
+    [statusBar setLeftStringValue:[NSString 
stringWithFormat:NSLocalizedString(@"Page %@ at (%i, %i)", @"Status message"), 
[[note page] displayLabel], (int)NSMidX(bounds), (int)NSMidY(bounds)]];
 }
 
 - (void)windowDidLoad {

Modified: trunk/SKPDFHoverWindow.m
===================================================================
--- trunk/SKPDFHoverWindow.m    2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/SKPDFHoverWindow.m    2008-07-12 11:51:29 UTC (rev 4196)
@@ -238,7 +238,7 @@
             sourceRect = SKConstrainRect(sourceRect, pageImageRect);
             
             NSDictionary *attrs = [[NSDictionary alloc] 
initWithObjectsAndKeys:labelFont, NSFontAttributeName, color, 
NSForegroundColorAttributeName, [NSParagraphStyle 
defaultClippingParagraphStyle], NSParagraphStyleAttributeName, nil];
-            NSAttributedString *labelString = [[NSAttributedString alloc] 
initWithString:[NSString stringWithFormat:NSLocalizedString(@"Page %@", @"Tool 
tip label format"), [page label]] attributes:attrs];
+            NSAttributedString *labelString = [[NSAttributedString alloc] 
initWithString:[NSString stringWithFormat:NSLocalizedString(@"Page %@", @"Tool 
tip label format"), [page displayLabel]] attributes:attrs];
             NSRect labelRect = [labelString boundingRectWithSize:NSZeroSize 
options:NSStringDrawingUsesLineFragmentOrigin];
             
             labelRect.size.width = floorf(NSWidth(labelRect));

Modified: trunk/SKSecondaryPDFView.m
===================================================================
--- trunk/SKSecondaryPDFView.m  2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/SKSecondaryPDFView.m  2008-07-12 11:51:29 UTC (rev 4196)
@@ -40,6 +40,7 @@
 #import "BDSKHeaderPopUpButton.h"
 #import "NSScrollView_SKExtensions.h"
 #import "PDFAnnotation_SKExtensions.h"
+#import "PDFPage_SKExtensions.h"
 
 
 @implementation SKSecondaryPDFView
@@ -138,9 +139,7 @@
     
     if (count = [pdfDoc pageCount]) {
         for (i = 0; i < count; i++) {
-            label = [[pdfDoc pageAtIndex:i] label];
-            if (label == nil)
-                label = [NSString stringWithFormat:@"%i", i + 1];
+            label = [[pdfDoc pageAtIndex:i] displayLabel];
             width = NSWidth([label boundingRectWithSize:size options:0 
attributes:attrs]);
             if (width > maxWidth) {
                 maxWidth = width;

Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m  2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/SKSnapshotWindowController.m  2008-07-12 11:51:29 UTC (rev 4196)
@@ -105,7 +105,7 @@
 }
 
 - (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName {
-    return [NSString stringWithFormat:NSLocalizedString(@"%@ %C Page %@", 
@"Window title format: [filename] - Page [number]"), displayName, 0x2014, 
[[pdfView currentPage] label]];
+    return [NSString stringWithFormat:NSLocalizedString(@"%@ %C Page %@", 
@"Window title format: [filename] - Page [number]"), displayName, 0x2014, 
[[pdfView currentPage] displayLabel]];
 }
 
 - (void)setNeedsDisplayInRect:(NSRect)rect ofPage:(PDFPage *)page {
@@ -139,15 +139,13 @@
 }
 
 - (void)handlePageChangedNotification:(NSNotification *)notification {
-    NSString *label = [[pdfView currentPage] label];
-    [self setPageLabel:label ? label : [NSString stringWithFormat:@"%i", [self 
pageIndex]]];
+    [self setPageLabel:[[pdfView currentPage] displayLabel]];
     [[self window] setTitle:[self windowTitleForDocumentDisplayName:[[self 
document] displayName]]];
 }
 
 - (void)handleDocumentDidUnlockNotification:(NSNotification *)notification {
     [[self window] setTitle:[self windowTitleForDocumentDisplayName:[[self 
document] displayName]]];
-    NSString *label = [[pdfView currentPage] label];
-    [self setPageLabel:label ? label : [NSString stringWithFormat:@"%i", [self 
pageIndex]]];
+    [self setPageLabel:[[pdfView currentPage] displayLabel]];
 }
 
 - (void)handlePDFViewFrameChangedNotification:(NSNotification *)notification {

Modified: trunk/SKStringConstants.h
===================================================================
--- trunk/SKStringConstants.h   2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/SKStringConstants.h   2008-07-12 11:51:29 UTC (rev 4196)
@@ -114,3 +114,4 @@
 extern NSString *SKAutoCloseDownloadsWindowKey;
 extern NSString *SKShouldSetCreatorCodeKey;
 extern NSString *SKTableFontSizeKey;
+extern NSString *SKLogicalPageNumberingKey;

Modified: trunk/SKStringConstants.m
===================================================================
--- trunk/SKStringConstants.m   2008-07-12 11:06:04 UTC (rev 4195)
+++ trunk/SKStringConstants.m   2008-07-12 11:51:29 UTC (rev 4196)
@@ -115,3 +115,4 @@
 NSString *SKAutoCloseDownloadsWindowKey = @"SKAutoCloseDownloadsWindow";
 NSString *SKShouldSetCreatorCodeKey = @"SKShouldSetCreatorCode";
 NSString *SKTableFontSizeKey = @"SKTableFontSize";
+NSString *SKLogicalPageNumberingKey = @"SKLogicalPageNumbering";


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to