Esempio n. 1
0
        public SearchResultMatch FindNext(IProgressMonitor monitor)
        {
            // insanity check
            Debug.Assert(searchStrategy != null);
            Debug.Assert(documentIterator != null);
            Debug.Assert(textIteratorBuilder != null);

            if (monitor != null && monitor.CancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            if (info != null && textIterator != null && documentIterator.CurrentFileName != null)
            {
                ProvidedDocumentInformation currentInfo = documentIterator.Current;
                if (currentInfo != null)
                {
                    if (!info.Equals(currentInfo))                       // create new iterator, if document changed
                    {
                        info         = currentInfo;
                        textIterator = textIteratorBuilder.BuildTextIterator(info);
                    }
                    else                         // old document -> initialize iterator position to caret pos
                    {
                        textIterator.Position = info.CurrentOffset;
                    }

                    SearchResultMatch result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator));
                    if (result != null)
                    {
                        info.CurrentOffset = textIterator.Position;
                        return(result);
                    }
                }
            }

            // not found or first start -> move forward to the next document
            if (documentIterator.MoveForward())
            {
                info = documentIterator.Current;
                // document is valid for searching -> set iterator & fileName
                if (info != null && info.EndOffset >= 0 && info.EndOffset <= info.Document.TextLength)
                {
                    textIterator = textIteratorBuilder.BuildTextIterator(info);
                }
                else
                {
                    textIterator = null;
                }

                return(FindNext(monitor));
            }
            return(null);
        }
Esempio n. 2
0
        public SearchResult FindNext()
        {
            // insanity check
            Debug.Assert(searchStrategy != null);
            Debug.Assert(documentIterator != null);
            Debug.Assert(textIteratorBuilder != null);

            if (info != null && textIterator != null && documentIterator.CurrentFileName != null)
            {
                if (info.FileName != documentIterator.CurrentFileName)                   // create new iterator, if document changed
                {
                    info         = documentIterator.Current;
                    textIterator = textIteratorBuilder.BuildTextIterator(info);
                }
                else                     // old document -> initialize iterator position to caret pos
                {
                    textIterator.Position = info.CurrentOffset;
                }

                SearchResult result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator));
                if (result != null)
                {
                    info.CurrentOffset = textIterator.Position;
                    return(result);
                }
            }

            // not found or first start -> move forward to the next document
            if (documentIterator.MoveForward())
            {
                info = documentIterator.Current;
                // document is valid for searching -> set iterator & fileName
                if (info != null && info.TextBuffer != null && info.EndOffset >= 0 && info.EndOffset < info.TextBuffer.Length)
                {
                    textIterator = textIteratorBuilder.BuildTextIterator(info);
                }
                else
                {
                    textIterator = null;
                }

                return(FindNext());
            }
            return(null);
        }
Esempio n. 3
0
            SearchResultMatch Find(FileName file, IDocument document, int searchOffset, int length)
            {
                var result = strategy.FindNext(DocumentUtilitites.GetTextSource(document), searchOffset, length);

                if (result != null)
                {
                    var start = document.OffsetToPosition(result.Offset);
                    var end   = document.OffsetToPosition(result.EndOffset);
                    return(new AvalonEditSearchResultMatch(file, start, end, result.Offset, result.Length, null, null, result));
                }
                return(null);
            }
Esempio n. 4
0
        public void FindNext()
        {
            if (fStrategy == null)
            {
                return;
            }

            if (!fStrategy.HasResults())
            {
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_NoMatchesFound));
                return;
            }

            ISearchResult result = fStrategy.FindNext();

            if (result != null)
            {
                SelectResult(result as SearchResult);
            }
        }
        public void Build(ISearchStrategy strategy, ITextIterator it, SearchOptions options)
        {
            int startPos = it.Position;
            it.Reset ();

            ISearchResult res = strategy.FindNext (it, options, false);
            while (res != null) {
                matches.Add (res);
                res = strategy.FindNext (it, options, false);
            }
            it.Position = startPos;
        }