Revision: 15465
          http://sourceforge.net/p/skim-app/code/15465
Author:   hofman
Date:     2025-06-15 14:40:50 +0000 (Sun, 15 Jun 2025)
Log Message:
-----------
convenience methods to get and set destination structs in a setup dictionary

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

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2025-06-15 14:20:49 UTC (rev 15464)
+++ trunk/SKMainWindowController.m      2025-06-15 14:40:50 UTC (rev 15465)
@@ -187,6 +187,9 @@
 
 - (void)cleanup;
 
+- (SKDestination)destinationFromSetup:(NSDictionary *)setup;
+- (void)setDestination:(SKDestination)dest inSetup:(NSMutableDictionary 
*)setup;
+
 - (void)applyLeftSideWidth:(CGFloat)leftSideWidth 
rightSideWidth:(CGFloat)rightSideWidth;
 
 - (void)updateTableFont;
@@ -452,25 +455,17 @@
     }
     
     // Go to page?
-    NSNumber *pageNumber = [savedNormalSetup objectForKey:PAGEINDEX_KEY];
-    NSUInteger pageIndex = NSNotFound;
-    NSString *pointString = nil;
-    if (pageNumber) {
-        pageIndex = [pageNumber unsignedIntegerValue];
-        pointString = [savedNormalSetup objectForKey:SCROLLPOINT_KEY];
-    } else if ([sud boolForKey:SKRememberLastPageViewedKey]) {
-        pageIndex = [[SKBookmarkController sharedBookmarkController] 
pageIndexForRecentDocumentAtURL:[doc fileURL]];
+    SKDestination dest = [self destinationFromSetup:savedNormalSetup];
+    if (dest.pageIndex == NSNotFound && [sud 
boolForKey:SKRememberLastPageViewedKey]) {
+        dest.pageIndex = [[SKBookmarkController sharedBookmarkController] 
pageIndexForRecentDocumentAtURL:[doc fileURL]];
     }
-    if (pageIndex != NSNotFound && [[pdfView document] pageCount] > pageIndex) 
{
+    if (dest.pageIndex != NSNotFound && [[pdfView document] pageCount] > 
dest.pageIndex) {
         if ([[pdfView document] isLocked]) {
-            [savedNormalSetup setObject:[NSNumber 
numberWithUnsignedInteger:pageIndex] forKey:PAGEINDEX_KEY];
-        } else if ([[pdfView currentPage] pageIndex] != pageIndex || 
pointString) {
-            SKDestination dest = {pageIndex, SKUnspecifiedPoint};
-            if (pointString)
-                dest.point = NSPointFromString(pointString);
+            [self setDestination:dest inSetup:savedNormalSetup];
+        } else if ([[pdfView currentPage] pageIndex] != dest.pageIndex || 
NSEqualPoints(dest.point, SKUnspecifiedPoint) == NO) {
             [pdfView goToCurrentDestination:dest];
             [lastViewedPages setCount:0];
-            [lastViewedPages addPointer:(void *)pageIndex];
+            [lastViewedPages addPointer:(void *)dest.pageIndex];
             [pdfView resetHistory];
             if (@available(macOS 12.0, *)) {
                 if (([pdfView displayMode] & kPDFDisplaySinglePageContinuous)) 
{
@@ -619,14 +614,9 @@
             if ([snapshotSetups count])
                 [self showSnapshotsWithSetups:snapshotSetups];
             
-            NSNumber *pageIndexNumber = [setup objectForKey:PAGEINDEX_KEY];
-            SKDestination dest = {[pageIndexNumber unsignedIntegerValue], 
SKUnspecifiedPoint};
-            if (pageIndexNumber && dest.pageIndex != NSNotFound && 
dest.pageIndex != [[pdfView currentPage] pageIndex]) {
-                NSString *pointString = [setup objectForKey:SCROLLPOINT_KEY];
-                if (pointString)
-                    dest.point = NSPointFromString(pointString);
+            SKDestination dest = [self destinationFromSetup:setup];
+            if (dest.pageIndex != NSNotFound && dest.pageIndex != [[pdfView 
currentPage] pageIndex])
                 [pdfView goToCurrentDestination:dest];
-            }
         }
     }
 }
@@ -642,9 +632,7 @@
         [setup setObject:NSStringFromRect([[self window] frame]) 
forKey:MAINWINDOWFRAME_KEY];
     [setup setObject:[NSNumber numberWithDouble:[self leftSideWidth]] 
forKey:LEFTSIDEPANEWIDTH_KEY];
     [setup setObject:[NSNumber numberWithDouble:[self rightSideWidth]] 
forKey:RIGHTSIDEPANEWIDTH_KEY];
-    [setup setObject:[NSNumber numberWithUnsignedInteger:dest.pageIndex] 
forKey:PAGEINDEX_KEY];
-    if (NSEqualPoints(dest.point, SKUnspecifiedPoint) == NO)
-        [setup setObject:NSStringFromPoint(dest.point) forKey:SCROLLPOINT_KEY];
+    [self setDestination:dest inSetup:setup];
     if (cropBoxes)
         [setup setObject:cropBoxes forKey:CROPBOXES_KEY];
     if ([snapshots count])
@@ -659,6 +647,28 @@
     return setup;
 }
 
+- (SKDestination)destinationFromSetup:(NSDictionary *)setup {
+    SKDestination dest = {NSNotFound, SKUnspecifiedPoint};
+    NSNumber *pageNumber = [setup objectForKey:PAGEINDEX_KEY];
+    if (pageNumber) {
+        dest.pageIndex = [pageNumber unsignedIntegerValue];
+        if (dest.pageIndex != NSNotFound) {
+            NSString *pointString = [setup objectForKey:SCROLLPOINT_KEY];
+            if (pointString)
+                dest.point = NSPointFromString(pointString);
+        }
+    }
+    return dest;
+}
+
+- (void)setDestination:(SKDestination)dest inSetup:(NSMutableDictionary 
*)setup {
+    if (dest.pageIndex != NSNotFound) {
+        [setup setObject:[NSNumber numberWithUnsignedInteger:dest.pageIndex] 
forKey:PAGEINDEX_KEY];
+        if (NSEqualPoints(dest.point, SKUnspecifiedPoint) == NO)
+            [setup setObject:NSStringFromPoint(dest.point) 
forKey:SCROLLPOINT_KEY];
+    }
+}
+
 #pragma mark UI updating
 
 - (void)updateSubtitle {
@@ -1147,10 +1157,7 @@
                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];
+                [self setDestination:dest inSetup:savedNormalSetup];
                 if ([snapshotDicts count])
                     [savedNormalSetup setObject:snapshotDicts 
forKey:SNAPSHOTS_KEY];
             }
@@ -2102,16 +2109,11 @@
     
     [self applyChangedCropBoxes:[savedNormalSetup objectForKey:CROPBOXES_KEY] 
inDocument:[self pdfDocument]];
     
-    NSNumber *pageIndexNumber = [savedNormalSetup objectForKey:PAGEINDEX_KEY];
-    NSUInteger pageIndex = pageIndexNumber ? [pageIndexNumber 
unsignedIntegerValue] : NSNotFound;
-    if (pageIndex != NSNotFound) {
-        SKDestination dest = {pageIndex, SKUnspecifiedPoint};
-        NSString *pointString = [savedNormalSetup 
objectForKey:SCROLLPOINT_KEY];
-        if (pointString)
-            dest.point = NSPointFromString(pointString);
+    SKDestination dest = [self destinationFromSetup:savedNormalSetup];
+    if (dest.pageIndex != NSNotFound) {
         [pdfView goToCurrentDestination:dest];
         [lastViewedPages setCount:0];
-        [lastViewedPages addPointer:(void *)pageIndex];
+        [lastViewedPages addPointer:(void *)dest.pageIndex];
         [pdfView resetHistory];
     }
     

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