Revision: 5463
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5463&view=rev
Author:   hofman
Date:     2009-07-04 14:57:42 +0000 (Sat, 04 Jul 2009)

Log Message:
-----------
Generate thumbnails with a zero delay in case some thumbnails draw slowly. 
Still does not fix the deadlock in some images though, I'm sure that's a bug in 
the frameworks.

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

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2009-07-04 14:35:55 UTC (rev 5462)
+++ trunk/SKMainWindowController.m      2009-07-04 14:57:42 UTC (rev 5463)
@@ -2528,6 +2528,28 @@
 
 #pragma mark Thumbnails
 
+- (void)makeImageForThumbnail:(SKThumbnail *)thumbnail {
+    NSSize newSize, oldSize = [thumbnail size];
+    PDFDocument *pdfDoc = [pdfView document];
+    PDFPage *page = [pdfDoc pageAtIndex:[thumbnail pageIndex]];
+    NSRect readingBarRect = [[[pdfView readingBar] page] isEqual:page] ? 
[[pdfView readingBar] currentBoundsForBox:[pdfView displayBox]] : NSZeroRect;
+    NSImage *image = [page thumbnailWithSize:thumbnailCacheSize 
forBox:[pdfView displayBox] readingBarRect:readingBarRect];
+    
+    [thumbnail setImage:image];
+    
+    newSize = [image size];
+    if (SKAbs(newSize.width - oldSize.width) > 1.0 || SKAbs(newSize.height - 
oldSize.height) > 1.0)
+        [thumbnailTableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet 
indexSetWithIndex:[thumbnail pageIndex]]];
+    //[thumbnailTableView setNeedsDisplayInRect:[thumbnailTableView 
frameOfCellAtColumn:0 row:[thumbnail pageIndex]]];
+}
+
+- (BOOL)generateImageForThumbnail:(SKThumbnail *)thumbnail {
+    if (mwcFlags.isAnimating || [thumbnailTableView isScrolling] || [[pdfView 
document] isLocked])
+        return NO;
+    [self performSelector:@selector(makeImageForThumbnail:) 
withObject:thumbnail afterDelay:0.0];
+    return YES;
+}
+
 - (void)updateThumbnailSelection {
        // Get index of current page.
        NSUInteger pageIndex = [[pdfView currentPage] pageIndex];
@@ -2583,37 +2605,22 @@
 }
 
 - (void)updateThumbnailAtPageIndex:(NSUInteger)anIndex {
-    [[self objectInThumbnailsAtIndex:anIndex] setDirty:YES];
+    SKThumbnail *tn = [self objectInThumbnailsAtIndex:anIndex];
+    [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(makeImageForThumbnail:) object:tn];
+    [tn setDirty:YES];
     [thumbnailTableView reloadData];
 }
 
 - (void)allThumbnailsNeedUpdate {
     NSEnumerator *te = [thumbnails objectEnumerator];
     SKThumbnail *tn;
-    while (tn = [te nextObject])
+    while (tn = [te nextObject]) {
+        [[self class] cancelPreviousPerformRequestsWithTarget:self 
selector:@selector(makeImageForThumbnail:) object:tn];
         [tn setDirty:YES];
+    }
     [thumbnailTableView reloadData];
 }
 
-
-- (NSImage *)imageForThumbnail:(SKThumbnail *)thumbnail {
-    NSImage *image = nil;
-    if (0 == mwcFlags.isAnimating && NO == [thumbnailTableView isScrolling] && 
[[pdfView document] isLocked] == NO) {
-        
-        NSSize newSize, oldSize = [thumbnail size];
-        PDFDocument *pdfDoc = [pdfView document];
-        PDFPage *page = [pdfDoc pageAtIndex:[thumbnail pageIndex]];
-        NSRect readingBarRect = [[[pdfView readingBar] page] isEqual:page] ? 
[[pdfView readingBar] currentBoundsForBox:[pdfView displayBox]] : NSZeroRect;
-        image = [page thumbnailWithSize:thumbnailCacheSize forBox:[pdfView 
displayBox] readingBarRect:readingBarRect];
-        
-        newSize = [image size];
-        if (SKAbs(newSize.width - oldSize.width) > 1.0 || SKAbs(newSize.height 
- oldSize.height) > 1.0) {
-            [thumbnailTableView 
performSelector:@selector(noteHeightOfRowsWithIndexesChanged:) 
withObject:[NSIndexSet indexSetWithIndex:[thumbnail pageIndex]] afterDelay:0.0];
-        }
-    }
-    return image;
-}
-
 #pragma mark Notes
 
 - (void)updateNoteSelection {

Modified: trunk/SKThumbnail.h
===================================================================
--- trunk/SKThumbnail.h 2009-07-04 14:35:55 UTC (rev 5462)
+++ trunk/SKThumbnail.h 2009-07-04 14:57:42 UTC (rev 5463)
@@ -56,6 +56,7 @@
 - (void)setDirty:(BOOL)flag;
 
 - (NSImage *)image;
+- (void)setImage:(NSImage *)newImage;
 
 - (NSString *)label;
 
@@ -66,5 +67,5 @@
 @end
 
 @interface NSObject (SKThumbnailDelegate)
-- (NSImage *)imageForThumbnail:(SKThumbnail *)thumbnail;
+- (BOOL)generateImageForThumbnail:(SKThumbnail *)thumbnail;
 @end

Modified: trunk/SKThumbnail.m
===================================================================
--- trunk/SKThumbnail.m 2009-07-04 14:35:55 UTC (rev 5462)
+++ trunk/SKThumbnail.m 2009-07-04 14:57:42 UTC (rev 5463)
@@ -73,13 +73,8 @@
 }
 
 - (NSImage *)image {
-    if (dirty) {
-        NSImage *anImage = [delegate imageForThumbnail:self];
-        if (anImage) {
-            [self setDirty:NO];
-            [self setImage:anImage];
-        }
-    }
+    if (dirty && [delegate generateImageForThumbnail:self])
+        [self setDirty:NO];
     return image;
 }
 


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