Revision: 5707
http://skim-app.svn.sourceforge.net/skim-app/?rev=5707&view=rev
Author: hofman
Date: 2009-09-07 23:36:29 +0000 (Mon, 07 Sep 2009)
Log Message:
-----------
check for empty selection instead of nil selection in more places
Modified Paths:
--------------
trunk/PDFAnnotationMarkup_SKExtensions.m
trunk/PDFSelection_SKExtensions.m
trunk/SKBoundsCommand.m
trunk/SKIndexCommand.m
trunk/SKMainDocument.m
trunk/SKMainWindowController.m
trunk/SKPDFToolTipWindow.m
trunk/SKPDFView.m
trunk/SKPagesCommand.m
trunk/SKSecondaryPDFView.m
trunk/SKSnapshotPDFView.m
Modified: trunk/PDFAnnotationMarkup_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationMarkup_SKExtensions.m 2009-09-07 22:39:55 UTC (rev
5706)
+++ trunk/PDFAnnotationMarkup_SKExtensions.m 2009-09-07 23:36:29 UTC (rev
5707)
@@ -194,7 +194,7 @@
- (id)initSkimNoteWithSelection:(PDFSelection *)selection
markupType:(NSInteger)type {
NSRect bounds = [[selection pages] count] ? [selection
boundsForPage:[[selection pages] objectAtIndex:0]] : NSZeroRect;
- if (selection == nil || NSIsEmptyRect(bounds)) {
+ if ([selection hasCharacters] == NO || NSIsEmptyRect(bounds)) {
[[self initWithBounds:NSZeroRect] release];
self = nil;
} else if (self = [self initSkimNoteWithBounds:bounds markupType:type
quadrilateralPointsAsStrings:nil]) {
@@ -292,7 +292,7 @@
for (i = 0; i < iMax; i++) {
// slightly outset the rect to avoid rounding errors, as
selectionForRect is pretty strict
- if (sel = [[self page] selectionForRect:NSInsetRect(*(NSRect
*)CFArrayGetValueAtIndex(lines, i), -1.0, -1.0)]) {
+ if ((sel = [[self page] selectionForRect:NSInsetRect(*(NSRect
*)CFArrayGetValueAtIndex(lines, i), -1.0, -1.0)]) && [sel hasCharacters]) {
if (selection == nil)
selection = sel;
else
@@ -368,7 +368,7 @@
- (id)selectionSpecifier {
PDFSelection *sel = [self selection];
- return sel ? [sel objectSpecifier] : [NSArray array];
+ return [sel hasCharacters] ? [sel objectSpecifier] : [NSArray array];
}
- (void)setSelectionSpecifier:(id)specifier {
Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m 2009-09-07 22:39:55 UTC (rev 5706)
+++ trunk/PDFSelection_SKExtensions.m 2009-09-07 23:36:29 UTC (rev 5707)
@@ -483,7 +483,7 @@
if (startPage != NSNotFound && startIndex != NSNotFound &&
endPage != NSNotFound && endIndex != NSNotFound) {
PDFSelection *sel = [document
selectionFromPage:[document pageAtIndex:startPage] atCharacterIndex:startIndex
toPage:[document pageAtIndex:endPage] atCharacterIndex:endIndex];
- if (sel) {
+ if ([sel hasCharacters]) {
[selections addObject:sel];
doc = document;
}
@@ -497,7 +497,7 @@
for (i = 0; i < numRanges; i++) {
PDFSelection *sel;
NSRange range = *(NSRange *)CFArrayGetValueAtIndex(ranges,
i);
- if (range.length && (sel = [container
selectionForRange:range])) {
+ if (range.length && (sel = [container
selectionForRange:range]) && [sel hasCharacters]) {
[selections addObject:sel];
doc = [container document];
}
Modified: trunk/SKBoundsCommand.m
===================================================================
--- trunk/SKBoundsCommand.m 2009-09-07 22:39:55 UTC (rev 5706)
+++ trunk/SKBoundsCommand.m 2009-09-07 23:36:29 UTC (rev 5707)
@@ -77,7 +77,7 @@
page = [pages count] ? [pages objectAtIndex:0] : nil;
}
if (page)
- bounds = [selection boundsForPage:page];
+ bounds = [selection hasCharacters] ? [selection
boundsForPage:page] : NSZeroRect;
}
Rect qdBounds = SKQDRectFromNSRect(bounds);
Modified: trunk/SKIndexCommand.m
===================================================================
--- trunk/SKIndexCommand.m 2009-09-07 22:39:55 UTC (rev 5706)
+++ trunk/SKIndexCommand.m 2009-09-07 23:36:29 UTC (rev 5707)
@@ -65,7 +65,7 @@
} else {
PDFSelection *selection = [PDFSelection selectionWithSpecifier:dP
onPage:page];
NSArray *pages = [selection pages];
- if ([pages count] && (page = [pages objectAtIndex:last ? [pages count]
- 1 : 0]))
+ if ([pages count] && [selection hasCharacters] && (page = [pages
objectAtIndex:last ? [pages count] - 1 : 0]))
idx = last ? [selection safeIndexOfLastCharacterOnPage:page] :
[selection safeIndexOfFirstCharacterOnPage:page];
}
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2009-09-07 22:39:55 UTC (rev 5706)
+++ trunk/SKMainDocument.m 2009-09-07 23:36:29 UTC (rev 5707)
@@ -2086,7 +2086,7 @@
[[self synchronizer] findPageAndLocationForLine:[location index]
inFile:[[source path] stringByReplacingPathExtension:@"tex"] options:options];
} else {
PDFSelection *selection = [PDFSelection
selectionWithSpecifier:[[command arguments] objectForKey:@"To"]];
- if ([[selection pages] count]) {
+ if ([selection hasCharacters]) {
PDFPage *page = [[selection pages] objectAtIndex:0];
NSRect bounds = [selection boundsForPage:page];
[[self pdfView] scrollRect:bounds inPageToVisible:page];
@@ -2143,7 +2143,7 @@
if (page) {
NSUInteger pageIndex = [page pageIndex];
PDFSelection *sel = [page selectionForLineAtPoint:point];
- NSRect rect = sel ? [sel boundsForPage:page] : NSMakeRect(point.x -
20.0, point.y - 5.0, 40.0, 10.0);
+ NSRect rect = [sel hasCharacters] ? [sel boundsForPage:page] :
NSMakeRect(point.x - 20.0, point.y - 5.0, 40.0, 10.0);
[[self synchronizer] findFileAndLineForLocation:point inRect:rect
pageBounds:[page boundsForBox:kPDFDisplayBoxMediaBox] atPageIndex:pageIndex];
}
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2009-09-07 22:39:55 UTC (rev 5706)
+++ trunk/SKMainWindowController.m 2009-09-07 23:36:29 UTC (rev 5707)
@@ -1758,20 +1758,23 @@
for (i = 0; i < iMax; i++) {
PDFPage *page = [pages objectAtIndex:i];
- NSRect bounds = NSInsetRect([sel boundsForPage:page], -4.0, -4.0);
- SKPDFAnnotationTemporary *circle = [[SKPDFAnnotationTemporary alloc]
initWithBounds:bounds];
-
- // use a heavier line width at low magnification levels; would be nice
if PDFAnnotation did this for us
- PDFBorder *border = [[PDFBorder alloc] init];
- [border setLineWidth:1.5 / ([pdfView scaleFactor])];
- [border setStyle:kPDFBorderStyleSolid];
- [circle setBorder:border];
- [border release];
- [circle setColor:color];
- [page addAnnotation:circle];
- [pdfView setNeedsDisplayForAnnotation:circle];
- [circle release];
- CFSetAddValue(temporaryAnnotations, (void *)circle);
+ NSRect bounds = [sel boundsForPage:page];
+ if (NSIsEmptyRect(bounds) == NO) {
+ bounds = NSInsetRect(bounds, -4.0, -4.0);
+ SKPDFAnnotationTemporary *circle = [[SKPDFAnnotationTemporary
alloc] initWithBounds:bounds];
+
+ // use a heavier line width at low magnification levels; would be
nice if PDFAnnotation did this for us
+ PDFBorder *border = [[PDFBorder alloc] init];
+ [border setLineWidth:1.5 / ([pdfView scaleFactor])];
+ [border setStyle:kPDFBorderStyleSolid];
+ [circle setBorder:border];
+ [border release];
+ [circle setColor:color];
+ [page addAnnotation:circle];
+ [pdfView setNeedsDisplayForAnnotation:circle];
+ [circle release];
+ CFSetAddValue(temporaryAnnotations, (void *)circle);
+ }
}
}
@@ -1876,7 +1879,7 @@
sel = [page selectionForRect:[page
boundsForBox:kPDFDisplayBoxCropBox]];
}
PDFSelection *selection = [self findString:string fromSelection:sel
withOptions:options];
- if (selection == nil && [sel string])
+ if ([selection hasCharacters] == NO && [sel hasCharacters])
selection = [self findString:string fromSelection:nil
withOptions:options];
if (selection) {
[pdfView setCurrentSelection:selection];
@@ -1914,10 +1917,12 @@
PDFSelection *firstSel = [selE nextObject];
PDFSelection *currentSel = [[firstSel copy] autorelease];
- while (sel = [selE nextObject])
- [currentSel addSelection:sel];
+ while (sel = [selE nextObject]) {
+ if ([sel hasCharacters])
+ [currentSel addSelection:sel];
+ }
- if (scroll && firstSel) {
+ if (scroll && [firstSel hasCharacters]) {
PDFPage *page = [[currentSel pages] objectAtIndex:0];
NSRect rect = NSIntersectionRect(NSInsetRect([currentSel
boundsForPage:page], -50.0, -50.0), [page boundsForBox:kPDFDisplayBoxCropBox]);
[pdfView scrollRect:rect inPageToVisible:page];
@@ -1928,8 +1933,10 @@
// add an annotation so it's easier to see the search result
if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKShouldHighlightSearchResultsKey]) {
selE = [findResults objectEnumerator];
- while (sel = [selE nextObject])
- [self addAnnotationsForSelection:sel];
+ while (sel = [selE nextObject]) {
+ if ([sel hasCharacters])
+ [self addAnnotationsForSelection:sel];
+ }
}
if (highlightTimer)
@@ -1941,7 +1948,7 @@
highlightTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(removeHighlightedSelections:) userInfo:nil
repeats:NO] retain];
}
- if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKDisableAnimatedSearchHighlightKey] == NO && firstSel)
+ if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKDisableAnimatedSearchHighlightKey] == NO && [firstSel
hasCharacters])
[pdfView setCurrentSelection:firstSel animate:YES];
if (currentSel)
Modified: trunk/SKPDFToolTipWindow.m
===================================================================
--- trunk/SKPDFToolTipWindow.m 2009-09-07 22:39:55 UTC (rev 5706)
+++ trunk/SKPDFToolTipWindow.m 2009-09-07 23:36:29 UTC (rev 5707)
@@ -44,6 +44,7 @@
#import "NSParagraphStyle_SKExtensions.h"
#import "NSGeometry_SKExtensions.h"
#import "NSAffineTransform_SKExtensions.h"
+#import "PDFSelection_SKExtensions.h"
#define WINDOW_OFFSET 20.0
#define TEXT_MARGIN_X 2.0
@@ -231,7 +232,7 @@
sourceRect.origin.y -= NSHeight(sourceRect);
- if ([selection string]) {
+ if ([selection hasCharacters]) {
NSRect selBounds = [transform transformRect:[selection
boundsForPage:page]];
CGFloat top = SKCeil(SKMax(NSMaxY(selBounds),
NSMinX(selBounds) + NSHeight(sourceRect)));
CGFloat left = SKFloor(SKMin(NSMinX(selBounds), NSMaxX(bounds)
- NSWidth(sourceRect)));
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2009-09-07 22:39:55 UTC (rev 5706)
+++ trunk/SKPDFView.m 2009-09-07 23:36:29 UTC (rev 5707)
@@ -4118,7 +4118,7 @@
NSPoint location = [self convertPoint:mouseLoc toPage:page];
NSUInteger pageIndex = [page pageIndex];
PDFSelection *sel = [page selectionForLineAtPoint:location];
- NSRect rect = sel ? [sel boundsForPage:page] : NSMakeRect(location.x -
20.0, location.y - 5.0, 40.0, 10.0);
+ NSRect rect = [sel hasCharacters] ? [sel boundsForPage:page] :
NSMakeRect(location.x - 20.0, location.y - 5.0, 40.0, 10.0);
[[document synchronizer] findFileAndLineForLocation:location
inRect:rect pageBounds:[page boundsForBox:kPDFDisplayBoxMediaBox]
atPageIndex:pageIndex];
}
Modified: trunk/SKPagesCommand.m
===================================================================
--- trunk/SKPagesCommand.m 2009-09-07 22:39:55 UTC (rev 5706)
+++ trunk/SKPagesCommand.m 2009-09-07 23:36:29 UTC (rev 5707)
@@ -58,7 +58,7 @@
return [NSArray arrayWithObjects:[dPO page], nil];
} else {
PDFSelection *selection = [PDFSelection selectionWithSpecifier:dP];
- return selection ? [selection pages] : [NSArray array];
+ return [selection hasCharacters] ? [selection pages] : [NSArray array];
}
return nil;
Modified: trunk/SKSecondaryPDFView.m
===================================================================
--- trunk/SKSecondaryPDFView.m 2009-09-07 22:39:55 UTC (rev 5706)
+++ trunk/SKSecondaryPDFView.m 2009-09-07 23:36:29 UTC (rev 5707)
@@ -47,6 +47,7 @@
#import "SKMainDocument.h"
#import "SKPDFSynchronizer.h"
#import "SKStringConstants.h"
+#import "PDFSelection_SKExtensions.h"
@interface NSResponder (BDSKGesturesPrivate)
@@ -593,7 +594,7 @@
NSPoint location = [self convertPoint:mouseLoc toPage:page];
NSUInteger pageIndex = [page pageIndex];
PDFSelection *sel = [page selectionForLineAtPoint:location];
- NSRect rect = sel ? [sel boundsForPage:page] :
NSMakeRect(location.x - 20.0, location.y - 5.0, 40.0, 10.0);
+ NSRect rect = [sel hasCharacters] ? [sel boundsForPage:page] :
NSMakeRect(location.x - 20.0, location.y - 5.0, 40.0, 10.0);
[[document synchronizer] findFileAndLineForLocation:location
inRect:rect pageBounds:[page boundsForBox:kPDFDisplayBoxMediaBox]
atPageIndex:pageIndex];
}
Modified: trunk/SKSnapshotPDFView.m
===================================================================
--- trunk/SKSnapshotPDFView.m 2009-09-07 22:39:55 UTC (rev 5706)
+++ trunk/SKSnapshotPDFView.m 2009-09-07 23:36:29 UTC (rev 5707)
@@ -45,6 +45,7 @@
#import "SKMainDocument.h"
#import "SKPDFSynchronizer.h"
#import "SKStringConstants.h"
+#import "PDFSelection_SKExtensions.h"
@implementation SKSnapshotPDFView
@@ -445,7 +446,7 @@
NSPoint location = [self convertPoint:mouseLoc toPage:page];
NSUInteger pageIndex = [page pageIndex];
PDFSelection *sel = [page selectionForLineAtPoint:location];
- NSRect rect = sel ? [sel boundsForPage:page] :
NSMakeRect(location.x - 20.0, location.y - 5.0, 40.0, 10.0);
+ NSRect rect = [sel hasCharacters] ? [sel boundsForPage:page] :
NSMakeRect(location.x - 20.0, location.y - 5.0, 40.0, 10.0);
[[document synchronizer] findFileAndLineForLocation:location
inRect:rect pageBounds:[page boundsForBox:kPDFDisplayBoxMediaBox]
atPageIndex:pageIndex];
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit