Revision: 14296
          http://sourceforge.net/p/skim-app/code/14296
Author:   hofman
Date:     2024-06-03 15:58:56 +0000 (Mon, 03 Jun 2024)
Log Message:
-----------
Separrate code to generate placeholder thumbnail

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

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2024-06-03 14:42:09 UTC (rev 14295)
+++ trunk/SKMainWindowController.m      2024-06-03 15:58:56 UTC (rev 14296)
@@ -2846,37 +2846,40 @@
     mwcFlags.updatingThumbnailSelection = 0;
 }
 
+- (NSImage *)placeholderThumbnailImage {
+    PDFPage *page = [[pdfView document] pageAtIndex:0];
+    NSSize size = [page boundsForBox:[pdfView displayBox]].size;
+    if (([page rotation] % 180) == 90)
+        size = NSMakeSize(size.height, size.width);
+    CGFloat width = ceil(0.8 * fmin(size.width, size.height));
+    NSRect rect = NSMakeRect(0.5 * (size.width - width), 0.5 * (size.height - 
width), width, width);
+    NSMutableArray *stamps = [NSMutableArray array];
+    NSString *type = [[self document] fileType];
+    if ([type isEqualToString:SKPostScriptDocumentType])
+        type = @"PS";
+    else if ([type isEqualToString:SKEncapsulatedPostScriptDocumentType])
+        type = @"EPS";
+    else if ([type isEqualToString:SKDVIDocumentType])
+        type = @"DVI";
+    else if ([type isEqualToString:SKXDVDocumentType])
+        type = @"XDV";
+    else
+        type = @"PDF";
+
+    page = [[PDFPage alloc] init];
+    [page setBounds:(NSRect){NSZeroPoint, size} forBox:kPDFDisplayBoxMediaBox];
+    
+    [stamps addObject:[[SKThumbnailStamp alloc] initWithImage:[NSImage 
stampForType:type] rect:rect fraction:1.0]];
+    if ([[pdfView document] isLocked])
+        [stamps addObject:[[SKThumbnailStamp alloc] 
initWithImage:[[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)] rect:rect 
fraction:0.5]];
+    
+    return [page thumbnailWithSize:thumbnailCacheSize 
forBox:kPDFDisplayBoxMediaBox hasShadow:YES highlights:stamps];
+}
+
 - (void)resetThumbnails {
     NSMutableArray *newThumbnails = [NSMutableArray array];
     if ([pageLabels count] > 0) {
-        PDFPage *page = [[pdfView document] pageAtIndex:0];
-        NSSize size = [page boundsForBox:[pdfView displayBox]].size;
-        if (([page rotation] % 180) == 90)
-            size = NSMakeSize(size.height, size.width);
-        CGFloat width = ceil(0.8 * fmin(size.width, size.height));
-        NSRect rect = NSMakeRect(0.5 * (size.width - width), 0.5 * 
(size.height - width), width, width);
-        NSMutableArray *stamps = [NSMutableArray array];
-        NSString *type = [[self document] fileType];
-        if ([type isEqualToString:SKPostScriptDocumentType])
-            type = @"PS";
-        else if ([type isEqualToString:SKEncapsulatedPostScriptDocumentType])
-            type = @"EPS";
-        else if ([type isEqualToString:SKDVIDocumentType])
-            type = @"DVI";
-        else if ([type isEqualToString:SKXDVDocumentType])
-            type = @"XDV";
-        else
-            type = @"PDF";
-
-        page = [[PDFPage alloc] init];
-        [page setBounds:(NSRect){NSZeroPoint, size} 
forBox:kPDFDisplayBoxMediaBox];
-        
-        [stamps addObject:[[SKThumbnailStamp alloc] initWithImage:[NSImage 
stampForType:type] rect:rect fraction:1.0]];
-        if ([[pdfView document] isLocked])
-            [stamps addObject:[[SKThumbnailStamp alloc] 
initWithImage:[[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)] rect:rect 
fraction:0.5]];
-        
-        NSImage *pageImage = [page thumbnailWithSize:thumbnailCacheSize 
forBox:kPDFDisplayBoxMediaBox hasShadow:YES highlights:stamps];
-        
+        NSImage *pageImage = [self placeholderThumbnailImage];
         [pageLabels enumerateObjectsUsingBlock:^(NSString *label, NSUInteger 
i, BOOL *stop) {
             SKThumbnail *thumbnail = [[SKThumbnail alloc] 
initWithImage:pageImage label:label pageIndex:i];
             [thumbnail setDirty:YES];
@@ -2886,11 +2889,12 @@
     // reloadData resets the selection, so we have to ignore its notification 
and reset it
     mwcFlags.updatingThumbnailSelection = 1;
     [self setThumbnails:newThumbnails];
-    [self updateThumbnailSelection];
+    NSIndexSet *indexes = [NSIndexSet indexSetWithIndex:[[pdfView currentPage] 
pageIndex]];
+    [leftSideController.thumbnailTableView selectRowIndexes:indexes 
byExtendingSelection:NO];
+    [leftSideController.thumbnailTableView scrollRowToVisible:[indexes 
firstIndex]];
     if (overviewView) {
-        mwcFlags.updatingThumbnailSelection = 1;
         [overviewView reloadData];
-        [overviewView setSelectionIndexes:[NSIndexSet 
indexSetWithIndex:[[pdfView currentPage] pageIndex]]];
+        [overviewView setSelectionIndexes:indexes];
         [self updateOverviewItemSize];
     }
     mwcFlags.updatingThumbnailSelection = 0;

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to