Revision: 15446
          http://sourceforge.net/p/skim-app/code/15446
Author:   hofman
Date:     2025-06-12 14:16:03 +0000 (Thu, 12 Jun 2025)
Log Message:
-----------
Add local variable. Save normal setup when reverting to locked document 
together. Restore page only for unlocked documents.

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

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2025-06-11 22:24:10 UTC (rev 15445)
+++ trunk/SKMainWindowController.m      2025-06-12 14:16:03 UTC (rev 15446)
@@ -1081,13 +1081,19 @@
     NSArray *snapshotDicts = nil;
     NSDictionary *openState = nil;
     BOOL isLocked = [pdfDocument isLocked];
+    NSUInteger pageCount = [pdfDocument pageCount];
     
     if (oldPdfDoc) {
         // this is a revert
         // need to clean up data and actions, and remember settings to restore
         dest = [pdfView currentDestination:YES];
-        if (secondaryPdfView)
+        if (dest.pageIndex >= pageCount && dest.pageIndex != NSNotFound)
+            dest = (SKDestination){pageCount - 1, SKUnspecifiedPoint};
+        if (secondaryPdfView) {
             secondaryDest = [secondaryPdfView currentDestination:YES];
+            if (secondaryDest.pageIndex >= pageCount && 
secondaryDest.pageIndex != NSNotFound)
+                secondaryDest = (SKDestination){pageCount - 1, 
SKUnspecifiedPoint};
+        }
         openState = [self expansionStateForOutline:[[pdfView document] 
outlineRoot]];
         
         [oldPdfDoc cancelFindString];
@@ -1124,6 +1130,12 @@
                 if ([self interactionMode] == SKNormalMode)
                     [savedNormalSetup setDictionary:[pdfView displaySettings]];
                 [savedNormalSetup setObject:@YES forKey:LOCKED_KEY];
+                if (dest.pageIndex != NSNotFound)
+                    [savedNormalSetup setObject:[NSNumber 
numberWithUnsignedInteger:dest.pageIndex] forKey:PAGEINDEX_KEY];
+                if (NSEqualPoints(dest.point, SKUnspecifiedPoint) == NO)
+                    [savedNormalSetup setObject:NSStringFromPoint(dest.point) 
forKey:SCROLLPOINT_KEY];
+                if ([snapshotDicts count])
+                    [savedNormalSetup setObject:snapshotDicts 
forKey:SNAPSHOTS_KEY];
             } else
                 [self performSelector:@selector(documentDidUnlockDelayed) 
withObject:nil afterDelay:0.0];
         }
@@ -1138,10 +1150,10 @@
     if ([noteDicts count]) {
         PDFDocument *pdfDoc = pdfDocument;
         if ([pdfDoc allowsNotes] == NO) {
-            NSUInteger i, pageCount = MIN([pdfDoc pageCount], [[noteDicts 
valueForKeyPath:@"@max.pageIndex"] unsignedIntegerValue] + 1);
+            NSUInteger i, iMax = MIN(pageCount, [[noteDicts 
valueForKeyPath:@"@max.pageIndex"] unsignedIntegerValue] + 1);
             pdfDoc = placeholderPdfDocument = [[SKPDFDocument alloc] init];
             [placeholderPdfDocument setContainingDocument:[self document]];
-            for (i = 0; i < pageCount; i++)
+            for (i = 0; i < iMax; i++)
                 [placeholderPdfDocument insertPage:[[SKPDFPage alloc] init] 
atIndex:i];
         }
         
@@ -1185,40 +1197,19 @@
     [self updatePageLabelsAndOutlineForExpansionState:openState];
     [self updateNoteSelection];
     
-    if ([snapshotDicts count]) {
-        if (isLocked)
-            [savedNormalSetup setObject:snapshotDicts forKey:SNAPSHOTS_KEY];
-        else
-            [self showSnapshotsWithSetups:snapshotDicts];
-    }
+    if (isLocked == NO && [snapshotDicts count])
+        [self showSnapshotsWithSetups:snapshotDicts];
     
-    if ([pdfDocument pageCount] && (dest.pageIndex != NSNotFound || 
secondaryDest.pageIndex != NSNotFound)) {
-        if (dest.pageIndex != NSNotFound) {
-            if (dest.pageIndex >= [pdfDocument pageCount]) {
-                dest.pageIndex = [pdfDocument pageCount] - 1;
-                dest.point = SKUnspecifiedPoint;
-            }
-            if (isLocked) {
-                [savedNormalSetup setObject:[NSNumber 
numberWithUnsignedInteger:dest.pageIndex] forKey:PAGEINDEX_KEY];
-                if (NSEqualPoints(dest.point, SKUnspecifiedPoint) == NO)
-                    [savedNormalSetup setObject:NSStringFromPoint(dest.point) 
forKey:SCROLLPOINT_KEY];
-             } else {
-                [pdfView goToCurrentDestination:dest];
-            }
-        }
-        if (secondaryDest.pageIndex != NSNotFound) {
-            if (secondaryDest.pageIndex >= [pdfDocument pageCount]) {
-                secondaryDest.pageIndex = [pdfDocument pageCount] - 1;
-                secondaryDest.point = SKUnspecifiedPoint;
-            }
+    if (isLocked == NO && pageCount && dest.pageIndex != NSNotFound) {
+        [pdfView goToCurrentDestination:dest];
+        if (secondaryDest.pageIndex != NSNotFound)
             [secondaryPdfView goToCurrentDestination:secondaryDest];
-        }
         [pdfView resetHistory];
     }
     
-    if (markedPage.pageIndex >= [pdfDocument pageCount])
+    if (markedPage.pageIndex >= pageCount)
         markedPage.pageIndex = beforeMarkedPage.pageIndex = NSNotFound;
-    else if (beforeMarkedPage.pageIndex >= [pdfDocument pageCount])
+    else if (beforeMarkedPage.pageIndex >= pageCount)
         beforeMarkedPage.pageIndex = NSNotFound;
     
     // the number of pages may have changed

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



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to