Revision: 26915 http://sourceforge.net/p/bibdesk/svn/26915 Author: hofman Date: 2021-09-17 14:52:37 +0000 (Fri, 17 Sep 2021) Log Message: ----------- Create tree nodes before starting background calculation. Rename some methods. Reset progress indicator to 0 when searching.
Modified Paths: -------------- trunk/bibdesk/BDSKFileMatcher.m Modified: trunk/bibdesk/BDSKFileMatcher.m =================================================================== --- trunk/bibdesk/BDSKFileMatcher.m 2021-09-17 09:37:29 UTC (rev 26914) +++ trunk/bibdesk/BDSKFileMatcher.m 2021-09-17 14:52:37 UTC (rev 26915) @@ -70,10 +70,10 @@ @interface BDSKFileMatcher (Private) - (NSArray *)copyTreeNodesWithPublications:(NSArray *)pubs; -- (void)doSearchWithPublications:(NSArray *)pubs usingIndex:(SKIndexRef)searchIndex; +- (void)searchIndex:(SKIndexRef)searchIndex withPublicationNodes:(NSArray *)pubNodes; // entry point to the searching/matching; acquire indexingLock first -- (void)indexFiles:(NSArray *)absoluteURLs withPublications:(NSArray *)pubs; +- (void)indexAndSearchFiles:(NSArray *)fileURLs withPublicationNodes:(NSArray *)pubNodes; - (void)handleRemoveDocumentNotification:(NSNotification *)notification; @@ -169,9 +169,14 @@ OSAtomicCompareAndSwap32Barrier(1, 0, &_matchFlags.shouldAbort); + // get the root nodes array on the main thread, since it uses BibItem methods + NSArray *treeNodes = [self copyTreeNodesWithPublications:pubs]; + dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [self indexFiles:absoluteURLs withPublications:pubs]; + [self indexAndSearchFiles:absoluteURLs withPublicationNodes:treeNodes]; }); + + [treeNodes release]; } - (IBAction)openAction:(id)sender; @@ -441,28 +446,22 @@ } // this method iterates available publications, trying to match them up with a file -- (void)doSearchWithPublications:(NSArray *)pubs usingIndex:(SKIndexRef)searchIndex; +- (void)searchIndex:(SKIndexRef)searchIndex withPublicationNodes:(NSArray *)pubNodes; { - // get the root nodes array on the main thread, since it uses BibItem methods - __block NSArray *treeNodes = nil; - dispatch_sync(dispatch_get_main_queue(), ^{ - treeNodes = [self copyTreeNodesWithPublications:pubs]; - }); - - BDSKPOSTCONDITION([treeNodes count]); + BDSKPRECONDITION([pubNodes count]); NSParameterAssert(NULL != searchIndex); SKIndexFlush(searchIndex); dispatch_async(dispatch_get_main_queue(), ^{ - [progressIndicator setDoubleValue:(1.0)]; + [progressIndicator setDoubleValue:(0.0)]; [statusField setStringValue:[NSLocalizedString(@"Searching document", @"") stringByAppendingEllipsis]]; }); double val = 0; - double max = [treeNodes count]; + double max = [pubNodes count]; - for (BDSKTreeNode *node in treeNodes) { + for (BDSKTreeNode *node in pubNodes) { if (_matchFlags.shouldAbort) break; @@ -534,8 +533,6 @@ [pool drain]; } - [treeNodes release]; - if (0 == _matchFlags.shouldAbort) { dispatch_async(dispatch_get_main_queue(), ^{ [progressIndicator setDoubleValue:(1.0)]; @@ -565,13 +562,11 @@ return searchIndex; } -- (void)indexFiles:(NSArray *)absoluteURLs withPublications:(NSArray *)pubs; +- (void)indexAndSearchFiles:(NSArray *)fileURLs withPublicationNodes:(NSArray *)pubNodes; { - // empty out a previous index (if any) SKIndexRef searchIndex = [self newSearchIndex]; - double val = 0; - double max = [absoluteURLs count]; + double max = [fileURLs count]; dispatch_async(dispatch_get_main_queue(), ^{ [progressIndicator setDoubleValue:0.0]; @@ -581,7 +576,7 @@ // some HTML files cause a deadlock or crash in -[NSHTMLReader _loadUsingLibXML2] rdar://problem/4988303 (fixed in 10.5) BOOL shouldLog = [[NSUserDefaults standardUserDefaults] boolForKey:BDSKShouldLogFilesAddedToMatchingSearchIndexKey]; - for (NSURL *url in absoluteURLs) { + for (NSURL *url in fileURLs) { if (_matchFlags.shouldAbort) break; SKDocumentRef doc = SKDocumentCreateWithURL((CFURLRef)url); @@ -605,7 +600,7 @@ [progressIndicator setDoubleValue:(1.0)]; [statusField setStringValue:NSLocalizedString(@"Indexing complete!", @"")]; }); - [self doSearchWithPublications:pubs usingIndex:searchIndex]; + [self searchIndex:searchIndex withPublicationNodes:pubNodes]; } else { dispatch_async(dispatch_get_main_queue(), ^{ [statusField setStringValue:NSLocalizedString(@"Indexing aborted.", @"")]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit