Revision: 7737
http://skim-app.svn.sourceforge.net/skim-app/?rev=7737&view=rev
Author: hofman
Date: 2012-10-19 17:29:39 +0000 (Fri, 19 Oct 2012)
Log Message:
-----------
use enumeration using blocks when index is needed
Modified Paths:
--------------
trunk/PDFSelection_SKExtensions.m
trunk/SKMainWindowController.m
trunk/SKMainWindowController_Actions.m
trunk/SKSecondaryPDFView.m
Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m 2012-10-19 15:22:12 UTC (rev 7736)
+++ trunk/PDFSelection_SKExtensions.m 2012-10-19 17:29:39 UTC (rev 7737)
@@ -202,24 +202,27 @@
}
static inline NSRange rangeOfSubstringOfStringAtIndex(NSString *string,
NSArray *substrings, NSUInteger anIndex) {
+ if (anIndex >= [substrings count])
+ return NSMakeRange(NSNotFound, 0);
+
NSUInteger length = [string length];
- NSRange range = NSMakeRange(0, 0);
- NSUInteger i, iMax = [substrings count];
+ __block NSRange range = NSMakeRange(0, 0);
- if (anIndex >= iMax)
- return NSMakeRange(NSNotFound, 0);
- for (i = 0; i <= anIndex; i++) {
- NSString *substring = [substrings objectAtIndex:i];
+ [substrings enumerateObjectsUsingBlock:^(id substring, NSUInteger i, BOOL
*stop) {
NSRange searchRange = NSMakeRange(NSMaxRange(range), length -
NSMaxRange(range));
if ([substring length] == 0) {
- if (i == anIndex)
- return NSMakeRange(NSNotFound, 0);
- continue;
+ if (i == anIndex) {
+ range = NSMakeRange(NSNotFound, 0);
+ *stop = YES;
+ }
+ return;
}
range = [string rangeOfString:substring options:NSLiteralSearch
range:searchRange];
- if (range.location == NSNotFound)
- return NSMakeRange(NSNotFound, 0);
- }
+ if (range.location == NSNotFound) {
+ range = NSMakeRange(NSNotFound, 0);
+ *stop = YES;
+ }
+ }];
return range;
}
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2012-10-19 15:22:12 UTC (rev 7736)
+++ trunk/SKMainWindowController.m 2012-10-19 17:29:39 UTC (rev 7737)
@@ -2401,13 +2401,12 @@
}
- (void)resetThumbnails {
- NSUInteger i, count = [pageLabels count];
// cancel all delayed perform requests for makeImageForThumbnail:
for (SKThumbnail *tn in thumbnails)
[[self class] cancelPreviousPerformRequestsWithTarget:self
selector:@selector(makeImageForThumbnail:) object:tn];
[self willChangeValueForKey:THUMBNAILS_KEY];
[thumbnails removeAllObjects];
- if (count) {
+ if ([pageLabels count] > 0) {
PDFPage *firstPage = [[pdfView document] pageAtIndex:0];
PDFPage *emptyPage = [[[SKPDFPage alloc] init] autorelease];
[emptyPage setBounds:[firstPage boundsForBox:kPDFDisplayBoxCropBox]
forBox:kPDFDisplayBoxCropBox];
@@ -2424,13 +2423,13 @@
[[[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)] drawInRect:imgRect
fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:0.5];
[image unlockFocus];
- for (i = 0; i < count; i++) {
- SKThumbnail *thumbnail = [[SKThumbnail alloc] initWithImage:image
label:[pageLabels objectAtIndex:i] pageIndex:i];
+ [pageLabels enumerateObjectsUsingBlock:^(id label, NSUInteger i, BOOL
*stop) {
+ SKThumbnail *thumbnail = [[SKThumbnail alloc] initWithImage:image
label:label pageIndex:i];
[thumbnail setDelegate:self];
[thumbnail setDirty:YES];
[thumbnails addObject:thumbnail];
[thumbnail release];
- }
+ }];
}
[self didChangeValueForKey:THUMBNAILS_KEY];
[self allThumbnailsNeedUpdate];
@@ -2470,33 +2469,29 @@
- (void)updateNoteSelection {
NSArray *orderedNotes = [rightSideController.noteArrayController
arrangedObjects];
- PDFAnnotation *annotation, *selAnnotation = nil;
+ __block PDFAnnotation *selAnnotation = nil;
NSUInteger pageIndex = [[pdfView currentPage] pageIndex];
- NSInteger i, count = [orderedNotes count];
NSMutableIndexSet *selPageIndexes = [NSMutableIndexSet indexSet];
for (selAnnotation in [self selectedNotes])
[selPageIndexes addIndex:[selAnnotation pageIndex]];
- if (count == 0 || [selPageIndexes containsIndex:pageIndex])
+ if ([orderedNotes count] == 0 || [selPageIndexes containsIndex:pageIndex])
return;
// Walk outline view looking for best firstpage number match.
- for (i = 0; i < count; i++) {
- // Get the destination of the given row....
- annotation = [orderedNotes objectAtIndex:i];
-
+ [orderedNotes enumerateObjectsUsingBlock:^(id annotation, NSUInteger i,
BOOL *stop) {
if ([annotation pageIndex] == pageIndex) {
selAnnotation = annotation;
- break;
+ *stop = YES;
} else if ([annotation pageIndex] > pageIndex) {
if (i == 0)
selAnnotation = [orderedNotes objectAtIndex:0];
else if ([selPageIndexes containsIndex:[[orderedNotes
objectAtIndex:i - 1] pageIndex]])
selAnnotation = [orderedNotes objectAtIndex:i - 1];
- break;
+ *stop = YES;
}
- }
+ }];
if (selAnnotation) {
mwcFlags.updatingNoteSelection = 1;
[rightSideController.noteOutlineView selectRowIndexes:[NSIndexSet
indexSetWithIndex:[rightSideController.noteOutlineView
rowForItem:selAnnotation]] byExtendingSelection:NO];
Modified: trunk/SKMainWindowController_Actions.m
===================================================================
--- trunk/SKMainWindowController_Actions.m 2012-10-19 15:22:12 UTC (rev
7736)
+++ trunk/SKMainWindowController_Actions.m 2012-10-19 17:29:39 UTC (rev
7737)
@@ -206,12 +206,10 @@
}
- (IBAction)toggleHideNotes:(id)sender{
- BOOL wasHidden = [pdfView hideNotes];
- for (PDFAnnotation *note in notes) {
- [note setShouldDisplay:wasHidden];
- [note setShouldPrint:wasHidden];
- }
- [pdfView setHideNotes:wasHidden == NO];
+ NSNumber *wasHidden = [NSNumber numberWithBool:[pdfView hideNotes]];
+ [notes setValue:wasHidden forKey:@"shouldDisplay"];
+ [notes setValue:wasHidden forKey:@"shouldPrint"];
+ [pdfView setHideNotes:[pdfView hideNotes] == NO];
}
- (IBAction)takeSnapshot:(id)sender{
Modified: trunk/SKSecondaryPDFView.m
===================================================================
--- trunk/SKSecondaryPDFView.m 2012-10-19 15:22:12 UTC (rev 7736)
+++ trunk/SKSecondaryPDFView.m 2012-10-19 17:29:39 UTC (rev 7737)
@@ -151,26 +151,24 @@
- (void)reloadPagePopUpButton {
NSArray *labels = [[self document] pageLabels];
- NSUInteger i, count = [pagePopUpButton numberOfItems];
- NSString *label;
- CGFloat width, maxWidth = 0.0;
+ NSUInteger count = [pagePopUpButton numberOfItems];
NSSize size = NSMakeSize(1000.0, 1000.0);
NSDictionary *attrs = [NSDictionary
dictionaryWithObjectsAndKeys:[pagePopUpButton font], NSFontAttributeName, nil];
- NSUInteger maxIndex = 0;
+ __block CGFloat maxWidth = 0.0;
+ __block NSUInteger maxIndex = 0;
while (count--)
[pagePopUpButton removeItemAtIndex:count];
- if ((count = [labels count])) {
- for (i = 0; i < count; i++) {
- label = [labels objectAtIndex:i];
- width = NSWidth([label boundingRectWithSize:size options:0
attributes:attrs]);
+ if ([labels count] > 0) {
+ [labels enumerateObjectsUsingBlock:^(id label, NSUInteger i, BOOL
*stop) {
+ CGFloat width = NSWidth([label boundingRectWithSize:size options:0
attributes:attrs]);
if (width > maxWidth) {
maxWidth = width;
maxIndex = i;
}
[pagePopUpButton addItemWithTitle:label];
- }
+ }];
sizePopUpToItemAtIndex(pagePopUpButton, maxIndex);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit