Revision: 4701
http://skim-app.svn.sourceforge.net/skim-app/?rev=4701&view=rev
Author: hofman
Date: 2008-09-28 00:06:32 +0000 (Sun, 28 Sep 2008)
Log Message:
-----------
Update dirty thumbnails lazily using a delegate methods when the image is
needed rather than when the thumbnail is requested. This prevents slowdown if
for some reason all thumbnails are requested in bulk due to further binding
bugs.
Modified Paths:
--------------
trunk/SKMainWindowController.h
trunk/SKMainWindowController.m
trunk/SKMainWindowController_UI.m
trunk/SKThumbnail.h
trunk/SKThumbnail.m
Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h 2008-09-27 22:32:07 UTC (rev 4700)
+++ trunk/SKMainWindowController.h 2008-09-28 00:06:32 UTC (rev 4701)
@@ -359,6 +359,7 @@
- (void)removeObjectFromNotesAtIndex:(unsigned int)theIndex;
- (void)removeAllObjectsFromNotes;
+- (NSArray *)thumbnails;
- (unsigned int)countOfThumbnails;
- (SKThumbnail *)objectInThumbnailsAtIndex:(unsigned int)theIndex;
- (void)insertObject:(SKThumbnail *)thumbnail inThumbnailsAtIndex:(unsigned
int)theIndex;
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2008-09-27 22:32:07 UTC (rev 4700)
+++ trunk/SKMainWindowController.m 2008-09-28 00:06:32 UTC (rev 4701)
@@ -1051,31 +1051,16 @@
}
}
+- (NSArray *)thumbnails {
+ return [[thumbnails copy] autorelease];
+}
+
- (unsigned int)countOfThumbnails {
return [thumbnails count];
}
- (SKThumbnail *)objectInThumbnailsAtIndex:(unsigned int)theIndex {
- SKThumbnail *thumbnail = [thumbnails objectAtIndex:theIndex];
-
- if ([thumbnail isDirty] && NO == isAnimating && NO == [thumbnailTableView
isScrolling] && [[pdfView document] isLocked] == NO) {
-
- NSSize newSize, oldSize = [[thumbnail image] size];
- PDFDocument *pdfDoc = [pdfView document];
- PDFPage *page = [pdfDoc pageAtIndex:theIndex];
- NSRect readingBarRect = [[[pdfView readingBar] page] isEqual:page] ?
[[pdfView readingBar] currentBoundsForBox:[pdfView displayBox]] : NSZeroRect;
- NSImage *image = [page thumbnailWithSize:thumbnailCacheSize
forBox:[pdfView displayBox] readingBarRect:readingBarRect];
-
- // setImage: sends a KVO notification that results in calling
objectInThumbnailsAtIndex: endlessly, so set dirty to NO first
- [thumbnail setDirty:NO];
- [thumbnail setImage:image];
-
- newSize = [image size];
- if (fabsf(newSize.width - oldSize.width) > 1.0 || fabsf(newSize.height
- oldSize.height) > 1.0) {
- [thumbnailTableView
performSelector:@selector(noteHeightOfRowsWithIndexesChanged:)
withObject:[NSIndexSet indexSetWithIndex:theIndex] afterDelay:0.0];
- }
- }
- return thumbnail;
+ return [thumbnails objectAtIndex:theIndex];
}
- (void)insertObject:(SKThumbnail *)thumbnail inThumbnailsAtIndex:(unsigned
int)theIndex {
@@ -3578,6 +3563,7 @@
for (i = 0; i < count; i++) {
SKThumbnail *thumbnail = [[SKThumbnail alloc] initWithImage:image
label:[pageLabels objectAtIndex:i]];
+ [thumbnail setDelegate:self];
[thumbnail setDirty:YES];
[thumbnails addObject:thumbnail];
[thumbnail release];
@@ -3614,6 +3600,26 @@
[thumbnailTableView reloadData];
}
+
+- (NSImage *)imageForThumbnail:(SKThumbnail *)thumbnail {
+ NSImage *image = nil;
+ if (NO == isAnimating && NO == [thumbnailTableView isScrolling] &&
[[pdfView document] isLocked] == NO) {
+
+ unsigned int theIndex = [thumbnails indexOfObject:thumbnail];
+ NSSize newSize, oldSize = [thumbnail size];
+ PDFDocument *pdfDoc = [pdfView document];
+ PDFPage *page = [pdfDoc pageAtIndex:theIndex];
+ 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 (fabsf(newSize.width - oldSize.width) > 1.0 || fabsf(newSize.height
- oldSize.height) > 1.0) {
+ [thumbnailTableView
performSelector:@selector(noteHeightOfRowsWithIndexesChanged:)
withObject:[NSIndexSet indexSetWithIndex:theIndex] afterDelay:0.0];
+ }
+ }
+ return image;
+}
+
#pragma mark Notes
- (void)updateNoteSelection {
Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m 2008-09-27 22:32:07 UTC (rev 4700)
+++ trunk/SKMainWindowController_UI.m 2008-09-28 00:06:32 UTC (rev 4701)
@@ -326,7 +326,7 @@
- (float)tableView:(NSTableView *)tv heightOfRow:(int)row {
if ([tv isEqual:thumbnailTableView]) {
- NSSize thumbSize = [[[thumbnails objectAtIndex:row] image] size];
+ NSSize thumbSize = [[thumbnails objectAtIndex:row] size];
NSSize cellSize = NSMakeSize([[tv
tableColumnWithIdentifier:SKMainWindowImageColumnIdentifer] width],
fminf(thumbSize.height,
roundedThumbnailSize));
if (thumbSize.height < [tv rowHeight])
Modified: trunk/SKThumbnail.h
===================================================================
--- trunk/SKThumbnail.h 2008-09-27 22:32:07 UTC (rev 4700)
+++ trunk/SKThumbnail.h 2008-09-28 00:06:32 UTC (rev 4701)
@@ -43,10 +43,14 @@
NSImage *image;
NSString *label;
BOOL dirty;
+ id delegate;
}
- (id)initWithImage:(NSImage *)anImage label:(NSString *)aLabel;
+- (id)delegate;
+- (void)setDelegate:(id)newDelegate;
+
- (BOOL)isDirty;
- (void)setDirty:(BOOL)flag;
@@ -56,4 +60,10 @@
- (NSString *)label;
- (void)setLabel:(NSString *)newLabel;
+- (NSSize)size;
+
@end
+
[EMAIL PROTECTED] NSObject (SKThumbnailDelegate)
+- (NSImage *)imageForThumbnail:(SKThumbnail *)thumbnail;
[EMAIL PROTECTED]
Modified: trunk/SKThumbnail.m
===================================================================
--- trunk/SKThumbnail.m 2008-09-27 22:32:07 UTC (rev 4700)
+++ trunk/SKThumbnail.m 2008-09-28 00:06:32 UTC (rev 4701)
@@ -56,10 +56,22 @@
[super dealloc];
}
+- (id)delegate { return delegate; }
+
+- (void)setDelegate:(id)newDelegate { delegate = newDelegate; }
+
- (BOOL)isDirty { return dirty; }
+
- (void)setDirty:(BOOL)flag { dirty = flag; }
- (NSImage *)image {
+ if (dirty) {
+ NSImage *anImage = [delegate imageForThumbnail:self];
+ if (anImage) {
+ [self setDirty:NO];
+ [self setImage:anImage];
+ }
+ }
return image;
}
@@ -81,4 +93,8 @@
}
}
+- (NSSize)size {
+ return [image size];
+}
+
@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit