Beispiel #1
0
        public void ShowFor(TextEditX dad, TextEditorControl editor, bool replaceMode)
        {
            Editor = editor;
            Dad    = dad;

            _search.ClearScanRegion();
            var sm = editor.ActiveTextAreaControl.SelectionManager;

            if (sm.HasSomethingSelected && sm.SelectionCollection.Count == 1)
            {
                var sel = sm.SelectionCollection[0];
                if (sel.StartPosition.Line == sel.EndPosition.Line)
                {
                    TxtSearch.Text = sm.SelectedText;
                }
                else
                {
                    _search.SetScanRegion(sel);
                }
            }
            else
            {
                // Get the current word that the caret is on
                Caret caret = editor.ActiveTextAreaControl.Caret;
                int   start = TextUtilities.FindWordStart(editor.Document, caret.Offset);
                int   endAt = TextUtilities.FindWordEnd(editor.Document, caret.Offset);
                TxtSearch.Text = editor.Document.GetText(start, endAt - start);
            }

            //ReplaceMode = replaceMode;

            this.Owner = (Form)editor.TopLevelControl;
            this.Show();

            TxtSearch.SelectAll();
            TxtSearch.Focus();

            if (!_highlightGroups.ContainsKey(_editor))
            {
                _highlightGroups[_editor] = new HighlightGroup(_editor);
            }
            HighlightGroup group = _highlightGroups[_editor];

            group.ClearMarkers();
        }
Beispiel #2
0
        private void btnHighlightAll_Click(object sender, EventArgs e)
        {
            if (!_highlightGroups.ContainsKey(_editor))
            {
                _highlightGroups[_editor] = new HighlightGroup(_editor);
            }
            HighlightGroup group = _highlightGroups[_editor];

            if (string.IsNullOrEmpty(LookFor))
            {
                // Clear highlights
                group.ClearMarkers();
            }
            else
            {
                _search.LookFor            = TxtSearch.Text;
                _search.MatchCase          = CaseSensitive.Checked;
                _search.MatchWholeWordOnly = WholeWords.Checked;

                bool looped = false;
                int  offset = 0, count = 0;
                for (; ;)
                {
                    TextRange range = _search.FindNext(offset, false, out looped);
                    if (range == null || looped)
                    {
                        break;
                    }
                    offset = range.Offset + range.Length;
                    count++;

                    var m = new TextMarker(range.Offset, range.Length,
                                           TextMarkerType.SolidBlock, panel1.BackColor, Color.Black);
                    group.AddMarker(m);
                }
                if (count == 0)
                {
                    MessageBox.Show("Cadena buscada no encontrada.");
                }
                // else
                //   Close();
            }
        }