コード例 #1
0
ファイル: ConsoleSearchForm.cs プロジェクト: rizwan3d/elalang
        private void search_Click(object sender, EventArgs e)
        {
            App.GetService<IStatusBarService>().ClearStatusString();
            var sm = new SearchManager(Sci.GetText());
            var flags = caseSensitive.Checked ? SearchFlags.MatchCase : SearchFlags.None;
            lastResult = lastText != textBox.Text ? null : lastResult;

            lastResult = sm.Search(flags, textBox.Text,
                lastResult != null ? lastResult.EndPosition : 0, Sci.GetTextLength());

            if (lastResult.Found)
            {
                lastText = textBox.Text;
                Sci.Select(lastResult.StartPosition, lastResult.EndPosition - lastResult.StartPosition, SelectionFlags.MakeOnlySelection | SelectionFlags.ScrollToCaret);
            }
            else
            {
                lastResult = null;
                App.GetService<IStatusBarService>().SetStatusString(StatusType.Warning, "There are no more occurences of '{0}' in the document.", textBox.Text);
            }
        }
コード例 #2
0
ファイル: SearchService.cs プロジェクト: rizwan3d/elalang
        private bool Search(string textToFind, Document doc, SearchFlags flags, SearchScope scope, Func<Document,SearchResult,Boolean> foundAction, bool silent, 
            int startPosition, int endPosition, SearchManager sm)
        {
            lastSettings = null;
            var editor = (ITextEditor)App.Editor(doc.GetType());
            sm = sm ?? new SearchManager(editor.GetContent(doc));

            var sp = startPosition;
            var ep = endPosition;

            var res = sm.Search(flags, textToFind, sp, ep);

            if (res.Found)
            {
                lastSettings = new SearchSettings
                {
                    Text = textToFind,
                    Flags = flags,
                    Scope = scope,
                    LastEndPosition = res.EndPosition,
                    LastDocument = doc,
                    MaxPosition = ep,
                    SearchManager = silent ? sm : null
                };

                if (!silent)
                    sm.Dispose();

                return foundAction(doc, res);
            }
            else if (scope == SearchScope.AllDocuments)
            {
                sm.Dispose();
                sm = null;

                var srv = App.GetService<IDocumentService>();
                var newDoc = GetNextDocument(doc);

                if (newDoc != null)
                {
                    if (scanned == null)
                        scanned = new List<Document>();

                    if (scanned.IndexOf(newDoc) != -1)
                        return false;
                    else
                        scanned.Add(newDoc);

                    if (!silent)
                        srv.SetActiveDocument(newDoc);

                    if (silent)
                        sm = new SearchManager(editor.GetContent(newDoc));

                    return Search(textToFind, newDoc, flags, scope, foundAction, silent, 0, 0, sm);
                }

                return false;
            }
            else
            {
                sm.Dispose();
                return false;
            }
        }