Browse Source

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
shortcuts
Daniel Grunwald 19 years ago
parent
commit
e1844b5410
  1. 8
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs
  2. 12
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs
  3. 2
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs
  4. 10
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs
  5. 5
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs
  6. 2
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs

8
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs

@ -37,12 +37,12 @@ namespace SearchAndReplace
find.DocumentIterator = SearchReplaceUtilities.CreateDocumentIterator(SearchOptions.DocumentIteratorType); find.DocumentIterator = SearchReplaceUtilities.CreateDocumentIterator(SearchOptions.DocumentIteratorType);
} }
static bool InitializeSearchInFiles() static bool InitializeSearchInFiles(IProgressMonitor monitor)
{ {
SetSearchOptions(); SetSearchOptions();
find.Reset(); find.Reset();
if (!find.SearchStrategy.CompilePattern()) if (!find.SearchStrategy.CompilePattern(monitor))
return false; return false;
currentFileName = String.Empty; currentFileName = String.Empty;
@ -71,7 +71,7 @@ namespace SearchAndReplace
public static void FindAll(IProgressMonitor monitor) public static void FindAll(IProgressMonitor monitor)
{ {
if (!InitializeSearchInFiles()) { if (!InitializeSearchInFiles(monitor)) {
return; return;
} }
@ -88,7 +88,7 @@ namespace SearchAndReplace
public static void FindAll(int offset, int length, IProgressMonitor monitor) public static void FindAll(int offset, int length, IProgressMonitor monitor)
{ {
if (!InitializeSearchInFiles()) { if (!InitializeSearchInFiles(monitor)) {
return; return;
} }

12
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs

@ -103,7 +103,7 @@ namespace SearchAndReplace
SetSearchOptions(); SetSearchOptions();
ClearSelection(); ClearSelection();
find.Reset(); find.Reset();
if (!find.SearchStrategy.CompilePattern()) if (!find.SearchStrategy.CompilePattern(monitor))
return; return;
List<TextEditorControl> textAreas = new List<TextEditorControl>(); List<TextEditorControl> textAreas = new List<TextEditorControl>();
int count; int count;
@ -128,7 +128,7 @@ namespace SearchAndReplace
SetSearchOptions(); SetSearchOptions();
find.Reset(); find.Reset();
if (!find.SearchStrategy.CompilePattern()) if (!find.SearchStrategy.CompilePattern(monitor))
return; return;
List<TextEditorControl> textAreas = new List<TextEditorControl>(); List<TextEditorControl> textAreas = new List<TextEditorControl>();
@ -191,7 +191,7 @@ namespace SearchAndReplace
SetSearchOptions(); SetSearchOptions();
ClearSelection(); ClearSelection();
find.Reset(); find.Reset();
if (!find.SearchStrategy.CompilePattern()) if (!find.SearchStrategy.CompilePattern(monitor))
return; return;
List<TextEditorControl> textAreas = new List<TextEditorControl>(); List<TextEditorControl> textAreas = new List<TextEditorControl>();
@ -239,7 +239,7 @@ namespace SearchAndReplace
SetSearchOptions(); SetSearchOptions();
find.Reset(); find.Reset();
if (!find.SearchStrategy.CompilePattern()) if (!find.SearchStrategy.CompilePattern(monitor))
return; return;
for (int count = 0;; count++) { for (int count = 0;; count++) {
@ -274,7 +274,7 @@ namespace SearchAndReplace
return; return;
} }
if (!find.SearchStrategy.CompilePattern()) { if (!find.SearchStrategy.CompilePattern(monitor)) {
find.Reset(); find.Reset();
lastResult = null; lastResult = null;
return; return;
@ -319,7 +319,7 @@ namespace SearchAndReplace
return; return;
} }
if (!find.SearchStrategy.CompilePattern()) { if (!find.SearchStrategy.CompilePattern(monitor)) {
find.Reset(); find.Reset();
lastResult = null; lastResult = null;
return; return;

2
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs

@ -71,7 +71,7 @@ namespace SearchAndReplace
return -1; return -1;
} }
public bool CompilePattern() public bool CompilePattern(ICSharpCode.SharpDevelop.Gui.IProgressMonitor monitor)
{ {
searchPattern = SearchOptions.MatchCase ? SearchOptions.FindPattern : SearchOptions.FindPattern.ToUpper(); searchPattern = SearchOptions.MatchCase ? SearchOptions.FindPattern : SearchOptions.FindPattern.ToUpper();
return true; return true;

10
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs

@ -6,24 +6,26 @@
// </file> // </file>
using System; using System;
using ICSharpCode.SharpDevelop.Gui;
namespace SearchAndReplace namespace SearchAndReplace
{ {
/// <summary> /// <summary>
/// This interface is the basic interface which all /// This interface is the basic interface which all
/// search algorithms must implement. /// search algorithms must implement.
/// </summary> /// </summary>
public interface ISearchStrategy public interface ISearchStrategy
{ {
/// <remarks> /// <remarks>
/// Only with a call to this method the search strategy must /// 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. /// before the FindNext function.
/// The method might show a message box to the user if the pattern is invalid.
/// </remarks> /// </remarks>
bool CompilePattern(); bool CompilePattern(IProgressMonitor monitor);
/// <remarks> /// <remarks>
/// 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. /// compiled pattern in the text using the textIterator and options.
/// </remarks> /// </remarks>
SearchResult FindNext(ITextIterator textIterator); SearchResult FindNext(ITextIterator textIterator);

5
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs

@ -8,6 +8,7 @@
using System; using System;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace SearchAndReplace namespace SearchAndReplace
{ {
@ -15,7 +16,7 @@ namespace SearchAndReplace
{ {
Regex regex = null; Regex regex = null;
public bool CompilePattern() public bool CompilePattern(IProgressMonitor monitor)
{ {
RegexOptions regexOptions = RegexOptions.Compiled; RegexOptions regexOptions = RegexOptions.Compiled;
if (!SearchOptions.MatchCase) { if (!SearchOptions.MatchCase) {
@ -25,7 +26,9 @@ namespace SearchAndReplace
regex = new Regex(SearchOptions.FindPattern, regexOptions); regex = new Regex(SearchOptions.FindPattern, regexOptions);
return true; return true;
} catch (ArgumentException ex) { } catch (ArgumentException ex) {
if (monitor != null) monitor.ShowingDialog = true;
MessageService.ShowError("${res:Dialog.NewProject.SearchReplace.ErrorParsingRegex}\n" + ex.Message); MessageService.ShowError("${res:Dialog.NewProject.SearchReplace.ErrorParsingRegex}\n" + ex.Message);
if (monitor != null) monitor.ShowingDialog = false;
return false; return false;
} }
} }

2
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs

@ -164,7 +164,7 @@ namespace SearchAndReplace
return -1; return -1;
} }
public bool CompilePattern() public bool CompilePattern(ICSharpCode.SharpDevelop.Gui.IProgressMonitor monitor)
{ {
CompilePattern(SearchOptions.FindPattern, !SearchOptions.MatchCase); CompilePattern(SearchOptions.FindPattern, !SearchOptions.MatchCase);
return true; return true;

Loading…
Cancel
Save