Browse Source

simplify SearchManager API

pull/23/head
Siegfried Pammer 14 years ago
parent
commit
1b7aab3e1d
  1. 9
      src/AddIns/Misc/SearchAndReplace/Project/Commands/SearchMainMenuCommands.cs
  2. 85
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchLocation.cs
  3. 134
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs
  4. 20
      src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs
  5. 1
      src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.csproj
  6. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Search/ISearchStrategy.cs
  7. 11
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Search/RegexSearchStrategy.cs

9
src/AddIns/Misc/SearchAndReplace/Project/Commands/SearchMainMenuCommands.cs

@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Search; using ICSharpCode.AvalonEdit.Search;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
@ -39,7 +40,9 @@ namespace SearchAndReplace
public override void Run() public override void Run()
{ {
if (SearchOptions.CurrentFindPattern.Length > 0) { if (SearchOptions.CurrentFindPattern.Length > 0) {
var result = SearchManager.FindNext(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode, SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection() : null);
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
var result = SearchManager.FindNext(strategy, location);
SearchManager.SelectResult(result); SearchManager.SelectResult(result);
} else { } else {
Find find = new Find(); Find find = new Find();
@ -93,7 +96,9 @@ namespace SearchAndReplace
if (SearchOptions.SearchTarget == SearchTarget.CurrentSelection) { if (SearchOptions.SearchTarget == SearchTarget.CurrentSelection) {
SearchOptions.SearchTarget = SearchTarget.CurrentDocument; SearchOptions.SearchTarget = SearchTarget.CurrentDocument;
} }
var result = SearchManager.FindNext(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode, SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection() : null);
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
var result = SearchManager.FindNext(strategy, location);
SearchManager.SelectResult(result); SearchManager.SelectResult(result);
} }
} }

85
src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchLocation.cs

@ -0,0 +1,85 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
namespace SearchAndReplace
{
/// <summary>
/// Describes a set of files or a file + selection to search in.
/// </summary>
public class SearchLocation
{
public SearchTarget Target { get; private set; }
public string BaseDirectory { get; private set; }
public string Filter { get; private set; }
public bool SearchSubdirs { get; private set; }
public ISegment Selection { get; private set; }
public SearchLocation(SearchTarget target, string baseDirectory, string filter, bool searchSubdirs, ISegment selection)
{
this.Target = target;
this.BaseDirectory = baseDirectory;
this.Filter = filter ?? "*.*";
this.SearchSubdirs = searchSubdirs;
this.Selection = selection;
}
public bool EqualsWithoutSelection(SearchLocation other)
{
return other != null &&
Target == other.Target &&
BaseDirectory == other.BaseDirectory &&
Filter == other.Filter &&
SearchSubdirs == other.SearchSubdirs;
}
public virtual IEnumerable<FileName> GenerateFileList()
{
List<FileName> files = new List<FileName>();
switch (Target) {
case SearchTarget.CurrentDocument:
case SearchTarget.CurrentSelection:
ITextEditorProvider vc = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;
if (vc != null)
files.Add(vc.TextEditor.FileName);
break;
case SearchTarget.AllOpenFiles:
foreach (ITextEditorProvider editor in WorkbenchSingleton.Workbench.ViewContentCollection.OfType<ITextEditorProvider>())
files.Add(editor.TextEditor.FileName);
break;
case SearchTarget.WholeProject:
if (ProjectService.CurrentProject == null)
break;
foreach (FileProjectItem item in ProjectService.CurrentProject.Items.OfType<FileProjectItem>())
files.Add(new FileName(item.FileName));
break;
case SearchTarget.WholeSolution:
if (ProjectService.OpenSolution == null)
break;
foreach (var item in ProjectService.OpenSolution.SolutionFolderContainers.Select(f => f.SolutionItems).SelectMany(si => si.Items))
files.Add(new FileName(Path.Combine(ProjectService.OpenSolution.Directory, item.Location)));
foreach (var item in ProjectService.OpenSolution.Projects.SelectMany(p => p.Items).OfType<FileProjectItem>())
files.Add(new FileName(item.FileName));
break;
case SearchTarget.Directory:
if (!Directory.Exists(BaseDirectory))
break;
return FileUtility.LazySearchDirectory(BaseDirectory, Filter, SearchSubdirs);
default:
throw new Exception("Invalid value for FileListType");
}
return files.Distinct();
}
}
}

134
src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs

@ -28,24 +28,18 @@ namespace SearchAndReplace
public class SearchManager public class SearchManager
{ {
#region FindAll #region FindAll
public static IObservable<SearchedFile> FindAllParallel(IProgressMonitor progressMonitor, string pattern, bool ignoreCase, bool matchWholeWords, SearchMode mode, public static IObservable<SearchedFile> FindAllParallel(ISearchStrategy strategy, SearchLocation location, IProgressMonitor progressMonitor)
SearchTarget target, string baseDirectory = null, string filter = "*.*", bool searchSubdirs = false, ISegment selection = null)
{ {
currentSearchRegion = null; currentSearchRegion = null;
var strategy = SearchStrategyFactory.Create(pattern, ignoreCase, matchWholeWords, mode);
ParseableFileContentFinder fileFinder = new ParseableFileContentFinder(); ParseableFileContentFinder fileFinder = new ParseableFileContentFinder();
IEnumerable<FileName> fileList = GenerateFileList(target, baseDirectory, filter, searchSubdirs); return new SearchRun(strategy, fileFinder, location.GenerateFileList(), progressMonitor) { Target = location.Target, Selection = location.Selection };
return new SearchRun(strategy, fileFinder, fileList, progressMonitor) { Target = target, Selection = selection };
} }
public static IEnumerable<SearchedFile> FindAll(IProgressMonitor progressMonitor, string pattern, bool ignoreCase, bool matchWholeWords, SearchMode mode, public static IEnumerable<SearchedFile> FindAll(ISearchStrategy strategy, SearchLocation location, IProgressMonitor progressMonitor)
SearchTarget target, string baseDirectory = null, string filter = "*.*", bool searchSubdirs = false, ISegment selection = null)
{ {
currentSearchRegion = null; currentSearchRegion = null;
var strategy = SearchStrategyFactory.Create(pattern, ignoreCase, matchWholeWords, mode);
ParseableFileContentFinder fileFinder = new ParseableFileContentFinder(); ParseableFileContentFinder fileFinder = new ParseableFileContentFinder();
IEnumerable<FileName> fileList = GenerateFileList(target, baseDirectory, filter, searchSubdirs); return new SearchRun(strategy, fileFinder, location.GenerateFileList(), progressMonitor) { Target = location.Target, Selection = location.Selection }.GetResults();
return new SearchRun(strategy, fileFinder, fileList, progressMonitor) { Target = target, Selection = selection }.GetResults();
} }
class SearchRun : IObservable<SearchedFile>, IDisposable class SearchRun : IObservable<SearchedFile>, IDisposable
@ -195,18 +189,13 @@ namespace SearchAndReplace
#region FindNext #region FindNext
static SearchRegion currentSearchRegion; static SearchRegion currentSearchRegion;
public static SearchResultMatch FindNext(string pattern, bool ignoreCase, bool matchWholeWords, SearchMode mode, public static SearchResultMatch FindNext(ISearchStrategy strategy, SearchLocation location)
SearchTarget target, string baseDirectory = null, string filter = "*.*", bool searchSubdirs = false)
{ {
if (string.IsNullOrEmpty(pattern)) var files = location.GenerateFileList().ToArray();
return null;
var files = GenerateFileList(target, baseDirectory, filter, searchSubdirs).ToArray();
if (files.Length == 0) if (files.Length == 0)
return null; return null;
if (currentSearchRegion == null || !currentSearchRegion.IsSameState(files, pattern, ignoreCase, matchWholeWords, mode, if (currentSearchRegion == null || !currentSearchRegion.IsSameState(files, strategy, location))
target, baseDirectory, filter, searchSubdirs)) currentSearchRegion = SearchRegion.CreateSearchRegion(files, strategy, location);
currentSearchRegion = SearchRegion.CreateSearchRegion(files, pattern, ignoreCase, matchWholeWords, mode,
target, baseDirectory, filter, searchSubdirs);
if (currentSearchRegion == null) if (currentSearchRegion == null)
return null; return null;
var result = currentSearchRegion.FindNext(); var result = currentSearchRegion.FindNext();
@ -218,7 +207,7 @@ namespace SearchAndReplace
class SearchRegion class SearchRegion
{ {
FileName[] files; FileName[] files;
AnchorSegment selection; SearchLocation location;
ISearchStrategy strategy; ISearchStrategy strategy;
public SearchResultMatch FindNext() public SearchResultMatch FindNext()
@ -242,9 +231,9 @@ namespace SearchAndReplace
int length; int length;
// if (target == SearchTarget.CurrentSelection) selection will not be null // if (target == SearchTarget.CurrentSelection) selection will not be null
// hence use the selection as search region. // hence use the selection as search region.
if (selection != null) { if (location.Selection != null) {
searchOffset = Math.Max(selection.Offset, searchOffset); searchOffset = Math.Max(location.Selection.Offset, searchOffset);
length = selection.EndOffset - searchOffset; length = location.Selection.EndOffset - searchOffset;
} else { } else {
length = document.TextLength - searchOffset; length = document.TextLength - searchOffset;
} }
@ -264,9 +253,9 @@ namespace SearchAndReplace
if (buffer == null) if (buffer == null)
continue; continue;
int length; int length;
if (selection != null) { if (location.Selection != null) {
searchOffset = selection.Offset; searchOffset = location.Selection.Offset;
length = selection.Length; length = location.Selection.Length;
} else { } else {
searchOffset = 0; searchOffset = 0;
length = buffer.TextLength; length = buffer.TextLength;
@ -300,56 +289,30 @@ namespace SearchAndReplace
return files.FindIndex(file => editor.FileName.Equals(file)); return files.FindIndex(file => editor.FileName.Equals(file));
} }
public static SearchRegion CreateSearchRegion(FileName[] files, string pattern, bool ignoreCase, bool matchWholeWords, SearchMode mode, SearchTarget target, string baseDirectory, string filter, bool searchSubdirs) public static SearchRegion CreateSearchRegion(FileName[] files, ISearchStrategy strategy, SearchLocation location)
{ {
ITextEditor editor = GetActiveTextEditor(); ITextEditor editor = GetActiveTextEditor();
if (editor != null) { if (editor != null) {
var document = new TextDocument(DocumentUtilitites.GetTextSource(editor.Document)); return new SearchRegion(files, strategy, location);
AnchorSegment selection = null;
if (target == SearchTarget.CurrentSelection)
selection = new AnchorSegment(document, editor.SelectionStart, editor.SelectionLength);
return new SearchRegion(files, selection, pattern, ignoreCase, matchWholeWords, mode, target, baseDirectory, filter, searchSubdirs) { strategy = SearchStrategyFactory.Create(pattern, ignoreCase, matchWholeWords, mode) };
} }
return null; return null;
} }
SearchRegion(FileName[] files, AnchorSegment selection, string pattern, bool ignoreCase, bool matchWholeWords, SearchMode mode, SearchTarget target, string baseDirectory, string filter, bool searchSubdirs) SearchRegion(FileName[] files, ISearchStrategy strategy, SearchLocation location)
{ {
if (files == null) if (files == null)
throw new ArgumentNullException("files"); throw new ArgumentNullException("files");
this.files = files; this.files = files;
this.selection = selection; this.strategy = strategy;
this.pattern = pattern; this.location = location;
this.ignoreCase = ignoreCase;
this.matchWholeWords = matchWholeWords;
this.mode = mode;
this.target = target;
this.baseDirectory = baseDirectory;
this.filter = filter;
this.searchSubdirs = searchSubdirs;
} }
string pattern; public bool IsSameState(FileName[] files, ISearchStrategy strategy, SearchLocation location)
bool ignoreCase;
bool matchWholeWords;
SearchMode mode;
SearchTarget target;
string baseDirectory;
string filter;
bool searchSubdirs;
public bool IsSameState(FileName[] files, string pattern, bool ignoreCase, bool matchWholeWords, SearchMode mode, SearchTarget target, string baseDirectory, string filter, bool searchSubdirs)
{ {
return this.files.SequenceEqual(files) && return this.files.SequenceEqual(files) &&
pattern == this.pattern && this.strategy.Equals(strategy) &&
ignoreCase == this.ignoreCase && this.location.EqualsWithoutSelection(location);
matchWholeWords == this.matchWholeWords &&
mode == this.mode &&
target == this.target &&
baseDirectory == this.baseDirectory &&
filter == this.filter &&
searchSubdirs == this.searchSubdirs;
} }
} }
#endregion #endregion
@ -443,6 +406,17 @@ namespace SearchAndReplace
return null; return null;
} }
} }
public static ISegment GetActiveSelection()
{
ITextEditor editor = GetActiveTextEditor();
if (editor != null) {
var document = new TextDocument(DocumentUtilitites.GetTextSource(editor.Document));
return new AnchorSegment(document, editor.SelectionStart, editor.SelectionLength);
}
return null;
}
#endregion #endregion
#region Show Messages #region Show Messages
@ -512,45 +486,5 @@ namespace SearchAndReplace
SearchResultsPad.Instance.BringToFront(); SearchResultsPad.Instance.BringToFront();
} }
#endregion #endregion
static IEnumerable<FileName> GenerateFileList(SearchTarget target, string baseDirectory = null, string filter = "*.*", bool searchSubdirs = false)
{
List<FileName> files = new List<FileName>();
switch (target) {
case SearchTarget.CurrentDocument:
case SearchTarget.CurrentSelection:
ITextEditorProvider vc = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;
if (vc != null)
files.Add(vc.TextEditor.FileName);
break;
case SearchTarget.AllOpenFiles:
foreach (ITextEditorProvider editor in WorkbenchSingleton.Workbench.ViewContentCollection.OfType<ITextEditorProvider>())
files.Add(editor.TextEditor.FileName);
break;
case SearchTarget.WholeProject:
if (ProjectService.CurrentProject == null)
break;
foreach (FileProjectItem item in ProjectService.CurrentProject.Items.OfType<FileProjectItem>())
files.Add(new FileName(item.FileName));
break;
case SearchTarget.WholeSolution:
if (ProjectService.OpenSolution == null)
break;
foreach (var item in ProjectService.OpenSolution.SolutionFolderContainers.Select(f => f.SolutionItems).SelectMany(si => si.Items))
files.Add(new FileName(Path.Combine(ProjectService.OpenSolution.Directory, item.Location)));
foreach (var item in ProjectService.OpenSolution.Projects.SelectMany(p => p.Items).OfType<FileProjectItem>())
files.Add(new FileName(item.FileName));
break;
case SearchTarget.Directory:
if (!Directory.Exists(baseDirectory))
break;
return FileUtility.LazySearchDirectory(baseDirectory, filter, searchSubdirs);
default:
throw new Exception("Invalid value for FileListType");
}
return files.Distinct();
}
} }
} }

20
src/AddIns/Misc/SearchAndReplace/Project/Gui/SearchAndReplacePanel.cs

@ -95,7 +95,9 @@ namespace SearchAndReplace
void FindNextButtonClicked(object sender, EventArgs e) void FindNextButtonClicked(object sender, EventArgs e)
{ {
WritebackOptions(); WritebackOptions();
lastMatch = SearchManager.FindNext(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode, SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, selection);
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
lastMatch = SearchManager.FindNext(strategy, location);
SearchManager.SelectResult(lastMatch); SearchManager.SelectResult(lastMatch);
Focus(); Focus();
} }
@ -106,7 +108,9 @@ namespace SearchAndReplace
var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor(); var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor();
monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"); monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}");
try { try {
var results = SearchManager.FindAllParallel(monitor, SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode, SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, selection); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, selection);
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
var results = SearchManager.FindAllParallel(strategy, location, monitor);
SearchManager.ShowSearchResults(SearchOptions.FindPattern, results); SearchManager.ShowSearchResults(SearchOptions.FindPattern, results);
} catch (OperationCanceledException) {} } catch (OperationCanceledException) {}
} }
@ -117,7 +121,9 @@ namespace SearchAndReplace
var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor(); var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor();
monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"); monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}");
try { try {
var results = SearchManager.FindAllParallel(monitor, SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode, SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, selection);
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
var results = SearchManager.FindAllParallel(strategy, location, monitor);
SearchManager.MarkAll(results); SearchManager.MarkAll(results);
} catch (OperationCanceledException) {} } catch (OperationCanceledException) {}
} }
@ -129,7 +135,9 @@ namespace SearchAndReplace
AsynchronousWaitDialog.RunInCancellableWaitDialog( AsynchronousWaitDialog.RunInCancellableWaitDialog(
StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"), null, StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"), null,
monitor => { monitor => {
var results = SearchManager.FindAll(monitor, SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode, SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, selection); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, selection);
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
var results = SearchManager.FindAll(strategy, location, monitor);
count = SearchManager.ReplaceAll(results, SearchOptions.ReplacePattern, monitor.CancellationToken); count = SearchManager.ReplaceAll(results, SearchOptions.ReplacePattern, monitor.CancellationToken);
}); });
if (count != -1) if (count != -1)
@ -141,7 +149,9 @@ namespace SearchAndReplace
WritebackOptions(); WritebackOptions();
if (SearchManager.IsResultSelected(lastMatch)) if (SearchManager.IsResultSelected(lastMatch))
SearchManager.Replace(lastMatch, SearchOptions.ReplacePattern); SearchManager.Replace(lastMatch, SearchOptions.ReplacePattern);
lastMatch = SearchManager.FindNext(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode, SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories); var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, selection);
var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
lastMatch = SearchManager.FindNext(strategy, location);
SearchManager.SelectResult(lastMatch); SearchManager.SelectResult(lastMatch);
Focus(); Focus();
} }

1
src/AddIns/Misc/SearchAndReplace/Project/SearchAndReplace.csproj

@ -70,6 +70,7 @@
<Compile Include="Commands\SearchMainMenuCommands.cs" /> <Compile Include="Commands\SearchMainMenuCommands.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" /> <Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Engine\Enums.cs" /> <Compile Include="Engine\Enums.cs" />
<Compile Include="Engine\SearchLocation.cs" />
<Compile Include="Engine\SearchManager.cs" /> <Compile Include="Engine\SearchManager.cs" />
<Compile Include="Gui\DefaultSearchResult.cs" /> <Compile Include="Gui\DefaultSearchResult.cs" />
<Compile Include="Gui\ObserverSearchResult.cs" /> <Compile Include="Gui\ObserverSearchResult.cs" />

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Search/ISearchStrategy.cs

@ -12,7 +12,7 @@ namespace ICSharpCode.AvalonEdit.Search
/// <summary> /// <summary>
/// Basic interface for search algorithms. /// Basic interface for search algorithms.
/// </summary> /// </summary>
public interface ISearchStrategy public interface ISearchStrategy : IEquatable<ISearchStrategy>
{ {
/// <summary> /// <summary>
/// Finds all matches in the given ITextSource and the given range. /// Finds all matches in the given ITextSource and the given range.

11
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Search/RegexSearchStrategy.cs

@ -17,6 +17,8 @@ namespace ICSharpCode.AvalonEdit.Search
public RegexSearchStrategy(Regex searchPattern) public RegexSearchStrategy(Regex searchPattern)
{ {
if (searchPattern == null)
throw new ArgumentNullException("searchPattern");
this.searchPattern = searchPattern; this.searchPattern = searchPattern;
} }
@ -33,6 +35,15 @@ namespace ICSharpCode.AvalonEdit.Search
{ {
return FindAll(document, offset, length).FirstOrDefault(); return FindAll(document, offset, length).FirstOrDefault();
} }
public bool Equals(ISearchStrategy other)
{
var strategy = other as RegexSearchStrategy;
return strategy != null &&
strategy.searchPattern.ToString() == searchPattern.ToString() &&
strategy.searchPattern.Options == searchPattern.Options &&
strategy.searchPattern.RightToLeft == searchPattern.RightToLeft;
}
} }
class SearchResult : TextSegment, ISearchResult class SearchResult : TextSegment, ISearchResult

Loading…
Cancel
Save