From 5bacb5f5dd0a1df9078fea3a208cee1695cd332d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 5 Jan 2013 00:42:45 +0100 Subject: [PATCH] Fix progress bar when running a search in the background. --- .../Project/Gui/SearchAndReplacePanel.cs | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs index 7d7a423c5e..367605aacb 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs @@ -100,33 +100,37 @@ namespace SearchAndReplace void FindAllButtonClicked(object sender, EventArgs e) { WritebackOptions(); - using (var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor()) { - monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"); - try { - var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null); - var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); - var results = SearchManager.FindAllParallel(strategy, location, monitor); - SearchManager.ShowSearchResults(SearchOptions.FindPattern, results); - } catch (SearchPatternException ex) { - MessageService.ShowError(ex.Message); - } catch (OperationCanceledException) {} + var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null); + ISearchStrategy strategy; + try { + strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); + } catch (SearchPatternException ex) { + MessageService.ShowError(ex.Message); + return; } + // No using block for the monitor; it is disposed when the asynchronous search finishes + var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor(); + monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"); + var results = SearchManager.FindAllParallel(strategy, location, monitor); + SearchManager.ShowSearchResults(SearchOptions.FindPattern, results); } void BookmarkAllButtonClicked(object sender, EventArgs e) { WritebackOptions(); - using (var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor()) { - monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"); - try { - var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null); - var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); - var results = SearchManager.FindAllParallel(strategy, location, monitor); - SearchManager.MarkAll(results); - } catch (SearchPatternException ex) { - MessageService.ShowError(ex.Message); - } catch (OperationCanceledException) {} + var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null); + ISearchStrategy strategy; + try { + strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode); + } catch (SearchPatternException ex) { + MessageService.ShowError(ex.Message); + return; } + // No using block for the monitor; it is disposed when the asynchronous search finishes + var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor(); + monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"); + var results = SearchManager.FindAllParallel(strategy, location, monitor); + SearchManager.MarkAll(results); } void ReplaceAllButtonClicked(object sender, EventArgs e)