1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
4
using ICSharpCode.SharpDevelop.Editor.Search;
6
using System.Collections.Generic;
7
using ICSharpCode.Core;
8
using ICSharpCode.SharpDevelop;
9
using ICSharpCode.SharpDevelop.Gui;
11
namespace SearchAndReplace
13
public static class SearchInFilesManager
15
static Search find = new Search();
17
static string currentFileName = String.Empty;
19
static SearchInFilesManager()
21
find.TextIteratorBuilder = new ForwardTextIteratorBuilder();
24
static void SetSearchOptions(IProgressMonitor monitor)
26
find.SearchStrategy = SearchReplaceUtilities.CreateSearchStrategy(SearchOptions.SearchStrategyType);
27
find.DocumentIterator = SearchReplaceUtilities.CreateDocumentIterator(SearchOptions.DocumentIteratorType, monitor);
30
static bool InitializeSearchInFiles(IProgressMonitor monitor)
32
SetSearchOptions(monitor);
35
if (!find.SearchStrategy.CompilePattern(monitor))
38
currentFileName = String.Empty;
42
static void FinishSearchInFiles(List<SearchResultMatch> results)
44
ShowSearchResults(SearchOptions.FindPattern, results);
47
public static void ShowSearchResults(string pattern, List<SearchResultMatch> results)
49
string title = StringParser.Parse("${res:MainWindow.Windows.SearchResultPanel.OccurrencesOf}",
50
new StringTagPair("Pattern", pattern));
51
SearchResultsPad.Instance.ShowSearchResults(title, results);
52
SearchResultsPad.Instance.BringToFront();
55
public static void FindAll(IProgressMonitor monitor)
57
if (!InitializeSearchInFiles(monitor)) {
61
List<SearchResultMatch> results = new List<SearchResultMatch>();
63
SearchResultMatch result = find.FindNext(monitor);
69
FinishSearchInFiles(results);
72
public static void FindAll(int offset, int length, IProgressMonitor monitor)
74
if (!InitializeSearchInFiles(monitor)) {
78
List<SearchResultMatch> results = new List<SearchResultMatch>();
80
SearchResultMatch result = find.FindNext(offset, length);
86
FinishSearchInFiles(results);