From e1844b541077a938608df70bedeb2b3905133b57 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 25 Jan 2007 20:25:18 +0000 Subject: [PATCH] Fixed SD2-1275: Searching using an invalid regex shows search in progress dialog git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2327 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Engine/SearchReplaceInFilesManager.cs | 8 ++++---- .../SearchAndReplace/Engine/SearchReplaceManager.cs | 12 ++++++------ .../SearchStrategy/BruteForceSearchStrategy.cs | 2 +- .../Engine/SearchStrategy/ISearchStrategy.cs | 10 ++++++---- .../Engine/SearchStrategy/RegExSearchStrategy.cs | 5 ++++- .../Engine/SearchStrategy/WildcardSearchStrategy.cs | 2 +- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs index 54e70e7ca7..9a4fa60800 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs @@ -37,12 +37,12 @@ namespace SearchAndReplace find.DocumentIterator = SearchReplaceUtilities.CreateDocumentIterator(SearchOptions.DocumentIteratorType); } - static bool InitializeSearchInFiles() + static bool InitializeSearchInFiles(IProgressMonitor monitor) { SetSearchOptions(); find.Reset(); - if (!find.SearchStrategy.CompilePattern()) + if (!find.SearchStrategy.CompilePattern(monitor)) return false; currentFileName = String.Empty; @@ -71,7 +71,7 @@ namespace SearchAndReplace public static void FindAll(IProgressMonitor monitor) { - if (!InitializeSearchInFiles()) { + if (!InitializeSearchInFiles(monitor)) { return; } @@ -88,7 +88,7 @@ namespace SearchAndReplace public static void FindAll(int offset, int length, IProgressMonitor monitor) { - if (!InitializeSearchInFiles()) { + if (!InitializeSearchInFiles(monitor)) { return; } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs index 663f152c80..835e11e0f0 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs @@ -103,7 +103,7 @@ namespace SearchAndReplace SetSearchOptions(); ClearSelection(); find.Reset(); - if (!find.SearchStrategy.CompilePattern()) + if (!find.SearchStrategy.CompilePattern(monitor)) return; List textAreas = new List(); int count; @@ -128,7 +128,7 @@ namespace SearchAndReplace SetSearchOptions(); find.Reset(); - if (!find.SearchStrategy.CompilePattern()) + if (!find.SearchStrategy.CompilePattern(monitor)) return; List textAreas = new List(); @@ -191,7 +191,7 @@ namespace SearchAndReplace SetSearchOptions(); ClearSelection(); find.Reset(); - if (!find.SearchStrategy.CompilePattern()) + if (!find.SearchStrategy.CompilePattern(monitor)) return; List textAreas = new List(); @@ -239,7 +239,7 @@ namespace SearchAndReplace SetSearchOptions(); find.Reset(); - if (!find.SearchStrategy.CompilePattern()) + if (!find.SearchStrategy.CompilePattern(monitor)) return; for (int count = 0;; count++) { @@ -274,7 +274,7 @@ namespace SearchAndReplace return; } - if (!find.SearchStrategy.CompilePattern()) { + if (!find.SearchStrategy.CompilePattern(monitor)) { find.Reset(); lastResult = null; return; @@ -319,7 +319,7 @@ namespace SearchAndReplace return; } - if (!find.SearchStrategy.CompilePattern()) { + if (!find.SearchStrategy.CompilePattern(monitor)) { find.Reset(); lastResult = null; return; diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs index 8dde45f934..29167d0ac6 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs @@ -71,7 +71,7 @@ namespace SearchAndReplace return -1; } - public bool CompilePattern() + public bool CompilePattern(ICSharpCode.SharpDevelop.Gui.IProgressMonitor monitor) { searchPattern = SearchOptions.MatchCase ? SearchOptions.FindPattern : SearchOptions.FindPattern.ToUpper(); return true; diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs index fdcd3c96cc..a0e04f2395 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs @@ -6,24 +6,26 @@ // using System; +using ICSharpCode.SharpDevelop.Gui; namespace SearchAndReplace { /// - /// This interface is the basic interface which all + /// This interface is the basic interface which all /// search algorithms must implement. /// public interface ISearchStrategy { /// /// Only with a call to this method the search strategy must - /// update their pattern information. This method will be called + /// update their pattern information. This method will be called /// before the FindNext function. + /// The method might show a message box to the user if the pattern is invalid. /// - bool CompilePattern(); + bool CompilePattern(IProgressMonitor monitor); /// - /// The find next method should search the next occurrence of the + /// The find next method should search the next occurrence of the /// compiled pattern in the text using the textIterator and options. /// SearchResult FindNext(ITextIterator textIterator); diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs index 31817f6831..352c223d0d 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs @@ -8,6 +8,7 @@ using System; using System.Text.RegularExpressions; using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Gui; namespace SearchAndReplace { @@ -15,7 +16,7 @@ namespace SearchAndReplace { Regex regex = null; - public bool CompilePattern() + public bool CompilePattern(IProgressMonitor monitor) { RegexOptions regexOptions = RegexOptions.Compiled; if (!SearchOptions.MatchCase) { @@ -25,7 +26,9 @@ namespace SearchAndReplace regex = new Regex(SearchOptions.FindPattern, regexOptions); return true; } catch (ArgumentException ex) { + if (monitor != null) monitor.ShowingDialog = true; MessageService.ShowError("${res:Dialog.NewProject.SearchReplace.ErrorParsingRegex}\n" + ex.Message); + if (monitor != null) monitor.ShowingDialog = false; return false; } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs index 1b24c24cdf..8ff398b72c 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs @@ -164,7 +164,7 @@ namespace SearchAndReplace return -1; } - public bool CompilePattern() + public bool CompilePattern(ICSharpCode.SharpDevelop.Gui.IProgressMonitor monitor) { CompilePattern(SearchOptions.FindPattern, !SearchOptions.MatchCase); return true;