Revision: 7607
http://skim-app.svn.sourceforge.net/skim-app/?rev=7607&view=rev
Author: hofman
Date: 2011-12-27 19:22:43 +0000 (Tue, 27 Dec 2011)
Log Message:
-----------
disable pdf document delegate during synchronous find operations instead of
keeping track of it
Modified Paths:
--------------
trunk/SKMainDocument.m
trunk/SKMainWindowController.h
trunk/SKMainWindowController.m
trunk/SKPDFDocument.m
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2011-12-27 18:35:34 UTC (rev 7606)
+++ trunk/SKMainDocument.m 2011-12-27 19:22:43 UTC (rev 7607)
@@ -1918,7 +1918,7 @@
if ([caseSensitive isKindOfClass:[NSNumber class]] == NO ||
[caseSensitive boolValue] == NO)
options |= NSCaseInsensitiveSearch;
- if ((selection = [[self mainWindowController] findString:text
fromSelection:selection withOptions:options]))
+ if ((selection = [[self pdfDocument] findString:text
fromSelection:selection withOptions:options]))
specifier = [selection objectSpecifier];
}
Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h 2011-12-27 18:35:34 UTC (rev 7606)
+++ trunk/SKMainWindowController.h 2011-12-27 19:22:43 UTC (rev 7607)
@@ -164,7 +164,6 @@
unsigned int updatingOutlineSelection:1;
unsigned int updatingThumbnailSelection:1;
unsigned int isAnimating:1;
- unsigned int isSynchronousFind:1;
unsigned int caseInsensitiveSearch:1;
unsigned int wholeWordSearch:1;
unsigned int updatingNoteSelection:1;
@@ -286,7 +285,6 @@
- (void)displayNoteViewAnimating:(BOOL)animate;
- (void)displaySnapshotViewAnimating:(BOOL)animate;
-- (PDFSelection *)findString:(NSString *)string fromSelection:(PDFSelection
*)selection withOptions:(NSInteger)options;
- (void)showFindBar;
- (NSInteger)outlineRowForPageIndex:(NSUInteger)pageIndex;
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2011-12-27 18:35:34 UTC (rev 7606)
+++ trunk/SKMainWindowController.m 2011-12-27 19:22:43 UTC (rev 7607)
@@ -225,7 +225,6 @@
interactionMode = SKNormalMode;
searchResults = [[NSMutableArray alloc] init];
searchResultIndex = 0;
- mwcFlags.isSynchronousFind = 0;
mwcFlags.caseInsensitiveSearch = [[NSUserDefaults
standardUserDefaults] boolForKey:SKCaseInsensitiveSearchKey];
mwcFlags.wholeWordSearch = [[NSUserDefaults standardUserDefaults]
boolForKey:SKWholeWordSearchKey];
mwcFlags.caseInsensitiveNoteSearch = [[NSUserDefaults
standardUserDefaults] boolForKey:SKCaseInsensitiveNoteSearchKey];
@@ -1698,30 +1697,24 @@
}
}
-- (PDFSelection *)findString:(NSString *)string fromSelection:(PDFSelection
*)selection withOptions:(NSInteger)options {
- mwcFlags.isSynchronousFind = 1;
- selection = [[pdfView document] findString:string fromSelection:selection
withOptions:options];
- mwcFlags.isSynchronousFind = 0;
- return selection;
-}
-
- (BOOL)findString:(NSString *)string forward:(BOOL)forward {
PDFSelection *sel = [pdfView currentSelection];
NSUInteger pageIndex = [[pdfView currentPage] pageIndex];
+ PDFDocument *pdfDoc = [pdfView document];
NSInteger options = 0;
if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKCaseInsensitiveFindKey])
options |= NSCaseInsensitiveSearch;
if (forward == NO)
options |= NSBackwardsSearch;
- while ([sel hasCharacters] == NO && (forward ? pageIndex-- > 0 :
++pageIndex < [[pdfView document] pageCount])) {
+ while ([sel hasCharacters] == NO && (forward ? pageIndex-- > 0 :
++pageIndex < [pdfDoc pageCount])) {
PDFPage *page = [[pdfView document] pageAtIndex:pageIndex];
NSUInteger length = [[page string] length];
if (length > 0)
sel = [page selectionForRange:NSMakeRange(0, length)];
}
- PDFSelection *selection = [self findString:string fromSelection:sel
withOptions:options];
+ PDFSelection *selection = [pdfDoc findString:string fromSelection:sel
withOptions:options];
if ([selection hasCharacters] == NO && [sel hasCharacters])
- selection = [self findString:string fromSelection:nil
withOptions:options];
+ selection = [pdfDoc findString:string fromSelection:nil
withOptions:options];
if (selection) {
[pdfView setCurrentSelection:selection];
[pdfView scrollSelectionToVisible:self];
@@ -1814,82 +1807,74 @@
#pragma mark PDFDocument delegate
- (void)didMatchString:(PDFSelection *)instance {
- if (mwcFlags.isSynchronousFind == 0) {
- if (mwcFlags.wholeWordSearch) {
- PDFSelection *copy = [[instance copy] autorelease];
- NSString *string = [instance string];
- NSUInteger l = [string length];
- [copy extendSelectionAtEnd:1];
- string = [copy string];
- if ([string length] > l && [[NSCharacterSet letterCharacterSet]
characterIsMember:[string characterAtIndex:l]])
- return;
- l = [string length];
- [copy extendSelectionAtStart:1];
- string = [copy string];
- if ([string length] > l && [[NSCharacterSet letterCharacterSet]
characterIsMember:[string characterAtIndex:0]])
- return;
- }
- [searchResults addObject:instance];
-
- PDFPage *page = [instance safeFirstPage];
- SKGroupedSearchResult *result = [groupedSearchResults lastObject];
- NSUInteger maxCount = [result maxCount];
- if ([[result page] isEqual:page] == NO) {
- result = [SKGroupedSearchResult groupedSearchResultWithPage:page
maxCount:maxCount];
- [groupedSearchResults addObject:result];
- }
- [result addMatch:instance];
-
- if ([result count] > maxCount) {
- maxCount = [result count];
- for (result in groupedSearchResults)
- [result setMaxCount:maxCount];
- }
+ if (mwcFlags.wholeWordSearch) {
+ PDFSelection *copy = [[instance copy] autorelease];
+ NSString *string = [instance string];
+ NSUInteger l = [string length];
+ [copy extendSelectionAtEnd:1];
+ string = [copy string];
+ if ([string length] > l && [[NSCharacterSet letterCharacterSet]
characterIsMember:[string characterAtIndex:l]])
+ return;
+ l = [string length];
+ [copy extendSelectionAtStart:1];
+ string = [copy string];
+ if ([string length] > l && [[NSCharacterSet letterCharacterSet]
characterIsMember:[string characterAtIndex:0]])
+ return;
}
+ [searchResults addObject:instance];
+
+ PDFPage *page = [instance safeFirstPage];
+ SKGroupedSearchResult *result = [groupedSearchResults lastObject];
+ NSUInteger maxCount = [result maxCount];
+ if ([[result page] isEqual:page] == NO) {
+ result = [SKGroupedSearchResult groupedSearchResultWithPage:page
maxCount:maxCount];
+ [groupedSearchResults addObject:result];
+ }
+ [result addMatch:instance];
+
+ if ([result count] > maxCount) {
+ maxCount = [result count];
+ for (result in groupedSearchResults)
+ [result setMaxCount:maxCount];
+ }
}
- (void)documentDidBeginDocumentFind:(NSNotification *)note {
- if (mwcFlags.isSynchronousFind == 0) {
- NSString *message = [NSLocalizedString(@"Searching", @"Message in
search table header") stringByAppendingEllipsis];
- [self setSearchResults:nil];
- [[[leftSideController.findTableView
tableColumnWithIdentifier:RESULTS_COLUMNID] headerCell] setStringValue:message];
- [[leftSideController.findTableView headerView] setNeedsDisplay:YES];
- [[[leftSideController.groupedFindTableView
tableColumnWithIdentifier:RELEVANCE_COLUMNID] headerCell]
setStringValue:message];
- [[leftSideController.groupedFindTableView headerView]
setNeedsDisplay:YES];
- [self setGroupedSearchResults:nil];
- [statusBar setProgressIndicatorStyle:SKProgressIndicatorBarStyle];
- [[statusBar progressIndicator] setMaxValue:[[note object] pageCount]];
- [[statusBar progressIndicator] setDoubleValue:0.0];
- [statusBar startAnimation:self];
- [self willChangeValueForKey:SEARCHRESULTS_KEY];
- [self willChangeValueForKey:GROUPEDSEARCHRESULTS_KEY];
- }
+ NSString *message = [NSLocalizedString(@"Searching", @"Message in search
table header") stringByAppendingEllipsis];
+ [self setSearchResults:nil];
+ [[[leftSideController.findTableView
tableColumnWithIdentifier:RESULTS_COLUMNID] headerCell] setStringValue:message];
+ [[leftSideController.findTableView headerView] setNeedsDisplay:YES];
+ [[[leftSideController.groupedFindTableView
tableColumnWithIdentifier:RELEVANCE_COLUMNID] headerCell]
setStringValue:message];
+ [[leftSideController.groupedFindTableView headerView] setNeedsDisplay:YES];
+ [self setGroupedSearchResults:nil];
+ [statusBar setProgressIndicatorStyle:SKProgressIndicatorBarStyle];
+ [[statusBar progressIndicator] setMaxValue:[[note object] pageCount]];
+ [[statusBar progressIndicator] setDoubleValue:0.0];
+ [statusBar startAnimation:self];
+ [self willChangeValueForKey:SEARCHRESULTS_KEY];
+ [self willChangeValueForKey:GROUPEDSEARCHRESULTS_KEY];
}
- (void)documentDidEndDocumentFind:(NSNotification *)note {
- if (mwcFlags.isSynchronousFind == 0) {
- NSString *message = [NSString stringWithFormat:NSLocalizedString(@"%ld
Results", @"Message in search table header"), (long)[searchResults count]];
- [self didChangeValueForKey:GROUPEDSEARCHRESULTS_KEY];
- [self didChangeValueForKey:SEARCHRESULTS_KEY];
- [[[leftSideController.findTableView
tableColumnWithIdentifier:RESULTS_COLUMNID] headerCell] setStringValue:message];
- [[leftSideController.findTableView headerView] setNeedsDisplay:YES];
- [[[leftSideController.groupedFindTableView
tableColumnWithIdentifier:RELEVANCE_COLUMNID] headerCell]
setStringValue:message];
- [[leftSideController.groupedFindTableView headerView]
setNeedsDisplay:YES];
- [statusBar stopAnimation:self];
- [statusBar setProgressIndicatorStyle:SKProgressIndicatorNone];
- }
+ NSString *message = [NSString stringWithFormat:NSLocalizedString(@"%ld
Results", @"Message in search table header"), (long)[searchResults count]];
+ [self didChangeValueForKey:GROUPEDSEARCHRESULTS_KEY];
+ [self didChangeValueForKey:SEARCHRESULTS_KEY];
+ [[[leftSideController.findTableView
tableColumnWithIdentifier:RESULTS_COLUMNID] headerCell] setStringValue:message];
+ [[leftSideController.findTableView headerView] setNeedsDisplay:YES];
+ [[[leftSideController.groupedFindTableView
tableColumnWithIdentifier:RELEVANCE_COLUMNID] headerCell]
setStringValue:message];
+ [[leftSideController.groupedFindTableView headerView] setNeedsDisplay:YES];
+ [statusBar stopAnimation:self];
+ [statusBar setProgressIndicatorStyle:SKProgressIndicatorNone];
}
- (void)documentDidEndPageFind:(NSNotification *)note {
- if (mwcFlags.isSynchronousFind == 0) {
- NSNumber *pageIndex = [[note userInfo]
objectForKey:@"PDFDocumentPageIndex"];
- [[statusBar progressIndicator] setDoubleValue:[pageIndex doubleValue]];
- if ([pageIndex unsignedIntegerValue] % 50 == 0) {
- [self didChangeValueForKey:GROUPEDSEARCHRESULTS_KEY];
- [self didChangeValueForKey:SEARCHRESULTS_KEY];
- [self willChangeValueForKey:SEARCHRESULTS_KEY];
- [self willChangeValueForKey:GROUPEDSEARCHRESULTS_KEY];
- }
+ NSNumber *pageIndex = [[note userInfo]
objectForKey:@"PDFDocumentPageIndex"];
+ [[statusBar progressIndicator] setDoubleValue:[pageIndex doubleValue]];
+ if ([pageIndex unsignedIntegerValue] % 50 == 0) {
+ [self didChangeValueForKey:GROUPEDSEARCHRESULTS_KEY];
+ [self didChangeValueForKey:SEARCHRESULTS_KEY];
+ [self willChangeValueForKey:SEARCHRESULTS_KEY];
+ [self willChangeValueForKey:GROUPEDSEARCHRESULTS_KEY];
}
}
Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m 2011-12-27 18:35:34 UTC (rev 7606)
+++ trunk/SKPDFDocument.m 2011-12-27 19:22:43 UTC (rev 7607)
@@ -60,4 +60,22 @@
return NO;
}
+// don't send out delegate methods during a synchronous find
+
+- (NSArray *)findString:(NSString *)string withOptions:(NSUInteger)options {
+ id delegate = [self delegate];
+ [self setDelegate:nil];
+ NSArray *array = [super findString:string withOptions:options];
+ [self setDelegate:delegate];
+ return array;
+}
+
+- (PDFSelection *)findString:(NSString *)string fromSelection:(PDFSelection
*)selection withOptions:(NSUInteger)options {
+ id delegate = [self delegate];
+ [self setDelegate:nil];
+ selection = [super findString:string fromSelection:selection
withOptions:options];
+ [self setDelegate:delegate];
+ return selection;
+}
+
@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit