~ubuntu-branches/ubuntu/warty/monodevelop/warty

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/SourceEditor/Search/DefaultFind.cs

  • Committer: Bazaar Package Importer
  • Author(s): Brandon Hale
  • Date: 2004-10-07 11:51:11 UTC
  • Revision ID: james.westby@ubuntu.com-20041007115111-pxcqnwfxyq5mhcx5
Tags: 0.5.1-3
Use dh_netdeps in debian/rules and debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// <file>
 
2
//     <copyright see="prj:///doc/copyright.txt"/>
 
3
//     <license see="prj:///doc/license.txt"/>
 
4
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
 
5
//     <version value="$version"/>
 
6
// </file>
 
7
using System;
 
8
using System.Collections;
 
9
using System.Diagnostics;
 
10
 
 
11
using MonoDevelop.Gui;
 
12
 
 
13
namespace MonoDevelop.TextEditor.Document
 
14
{
 
15
        public class DefaultFind : IFind
 
16
        {
 
17
                ISearchStrategy             searchStrategy      = null;
 
18
                IDocumentIterator           documentIterator    = null;
 
19
                ITextIterator               textIterator        = null;
 
20
                IDocumentInformation        info = null;
 
21
                bool                                            cancelled;
 
22
                int                                                     searchedFiles;
 
23
                int                                                     matches;
 
24
                
 
25
                public IDocumentInformation CurrentDocumentInformation {
 
26
                        get {
 
27
                                return info;
 
28
                        }
 
29
                }
 
30
                
 
31
                public ITextIterator TextIterator {
 
32
                        get {
 
33
                                return textIterator;
 
34
                        }
 
35
                }
 
36
                
 
37
                public ISearchStrategy SearchStrategy {
 
38
                        get {
 
39
                                return searchStrategy;
 
40
                        }
 
41
                        set {
 
42
                                searchStrategy = value;
 
43
                        }
 
44
                }
 
45
                
 
46
                public IDocumentIterator DocumentIterator {
 
47
                        get {
 
48
                                return documentIterator;
 
49
                        }
 
50
                        set {
 
51
                                documentIterator = value;
 
52
                        }
 
53
                }
 
54
                
 
55
                public int SearchedFileCount {
 
56
                        get { return searchedFiles; }
 
57
                }
 
58
                
 
59
                public int MatchCount {
 
60
                        get { return matches; }
 
61
                }
 
62
                
 
63
                ISearchResult CreateNamedSearchResult(ISearchResult pos)
 
64
                {
 
65
                        if (info == null || pos == null) {
 
66
                                return null;
 
67
                        }
 
68
                        pos.DocumentInformation = info;
 
69
                        return pos;
 
70
                }
 
71
                
 
72
                public void Reset()
 
73
                {
 
74
                        documentIterator.Reset();
 
75
                        textIterator = null;
 
76
                        cancelled = false;
 
77
                        searchedFiles = 0;
 
78
                        matches = 0;
 
79
                }
 
80
                
 
81
                public void Replace (ISearchResult result, string pattern)
 
82
                {
 
83
                        if (CurrentDocumentInformation != null && TextIterator != null) {
 
84
                                TextIterator.Position = result.Offset;
 
85
                                TextIterator.Replace (result.Length, pattern);
 
86
                        }
 
87
                }
 
88
                
 
89
                public ISearchResult FindNext(SearchOptions options) 
 
90
                {
 
91
                        // insanity check
 
92
                        Debug.Assert(searchStrategy      != null);
 
93
                        Debug.Assert(documentIterator    != null);
 
94
                        Debug.Assert(options             != null);
 
95
                        
 
96
                        while (!cancelled)
 
97
                        {
 
98
                                if (info != null && textIterator != null && documentIterator.CurrentFileName != null) {
 
99
                                        if (info.FileName != documentIterator.CurrentFileName) { // create new iterator, if document changed
 
100
                                                info         = documentIterator.Current;
 
101
                                                textIterator = info.GetTextIterator ();
 
102
                                        } 
 
103
 
 
104
                                        ISearchResult result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator, options));
 
105
                                        if (result != null) {
 
106
                                                matches++;
 
107
                                                return result;
 
108
                                        }
 
109
                                }
 
110
                                
 
111
                                if (textIterator != null) textIterator.Close ();
 
112
                                        
 
113
                                // not found or first start -> move forward to the next document
 
114
                                if (documentIterator.MoveForward()) {
 
115
                                        searchedFiles++;
 
116
                                        info = documentIterator.Current;
 
117
                                        textIterator = info.GetTextIterator ();
 
118
                                }
 
119
                                else
 
120
                                        cancelled = true;
 
121
                        }
 
122
                        cancelled = false;
 
123
                        return null;
 
124
                }
 
125
                
 
126
                public void Cancel ()
 
127
                {
 
128
                        cancelled = true;
 
129
                }
 
130
        }
 
131
}