From b8e84e344c1e2f7e4effd636adbede8bd255b83e Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Tue, 15 Nov 2016 22:56:42 +0700 Subject: [PATCH] =?UTF-8?q?Let=20Open=20Quickly=E2=80=A6=20block=20main=20?= =?UTF-8?q?thread=20until=20open=20documents=20are=20loaded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should ensure that ⌘T quickly followed by ↩ will always select the last document (as long as it is still open). --- Frameworks/OakFilterList/src/FileChooser.mm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Frameworks/OakFilterList/src/FileChooser.mm b/Frameworks/OakFilterList/src/FileChooser.mm index d1ccd12e..4cd330a3 100644 --- a/Frameworks/OakFilterList/src/FileChooser.mm +++ b/Frameworks/OakFilterList/src/FileChooser.mm @@ -486,15 +486,28 @@ static NSDictionary* globs_for_path (std::string const& path) [_searchResults removeAllObjects]; } + dispatch_semaphore_t sem = dispatch_semaphore_create(0); + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + __block BOOL didSignal = NO; + [OakDocumentController.sharedInstance enumerateDocumentsAtPath:path options:options usingBlock:^(OakDocument* document, BOOL* stop){ @synchronized(_searchResults) { + if(document.open == NO) + { + dispatch_semaphore_signal(sem); + didSignal = YES; + } + if(searchToken == _lastSearchToken) [_searchResults addObject:document]; else *stop = YES; } }]; + if(didSignal == NO) + dispatch_semaphore_signal(sem); + dispatch_async(dispatch_get_main_queue(), ^{ if(searchToken == _lastSearchToken) { @@ -504,6 +517,9 @@ static NSDictionary* globs_for_path (std::string const& path) }); }); + dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); + [self handleSearchResults:nil]; + _pollInterval = 0.02; _pollTimer = [NSTimer scheduledTimerWithTimeInterval:_pollInterval target:self selector:@selector(handleSearchResults:) userInfo:nil repeats:NO]; [_progressIndicator performSelector:@selector(startAnimation:) withObject:self afterDelay:0.2];