This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
/
WholeProjectDocumentIterator.cs
99 lines (89 loc) · 2.54 KB
/
WholeProjectDocumentIterator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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 ICSharpCode.SharpDevelop;
using System;
using System.Collections;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.Search;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Refactoring;
namespace SearchAndReplace
{
public class WholeProjectDocumentIterator : IDocumentIterator
{
ArrayList files = new ArrayList();
int curIndex = -1;
public WholeProjectDocumentIterator()
{
Reset();
}
public string CurrentFileName {
get {
if (curIndex < 0 || curIndex >= files.Count) {
return null;
}
return files[curIndex].ToString();;
}
}
public ProvidedDocumentInformation Current {
get {
if (curIndex < 0 || curIndex >= files.Count) {
return null;
}
if (!File.Exists(files[curIndex].ToString())) {
++curIndex;
return Current;
}
IDocument document;
string fileName = files[curIndex].ToString();
foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) {
if (content.PrimaryFileName != null &&
FileUtility.IsEqualFileName(content.PrimaryFileName, fileName) &&
content is ITextEditorProvider)
{
document = (((ITextEditorProvider)content).TextEditor).Document;
return new ProvidedDocumentInformation(document,
fileName,
0);
}
}
ITextBuffer fileContent;
try {
fileContent = ParserService.GetParseableFileContent(fileName);
} catch (Exception) {
return null;
}
return new ProvidedDocumentInformation(fileContent,
fileName,
0);
}
}
public bool MoveForward()
{
return ++curIndex < files.Count;
}
public bool MoveBackward()
{
if (curIndex == -1) {
curIndex = files.Count - 1;
return true;
}
return --curIndex >= -1;
}
public void Reset()
{
files.Clear();
if (ProjectService.CurrentProject != null) {
foreach (ProjectItem item in ProjectService.CurrentProject.Items) {
if (item is FileProjectItem && SearchReplaceUtilities.IsSearchable(item.FileName)) {
files.Add(item.FileName);
}
}
}
curIndex = -1;
}
}
}