Beispiel #1
0
        private void btnReplaceAll_Click(object sender, EventArgs e)
        {
            if (txtFindR.Text == string.Empty)
            {
                return;
            }

            AddReplaceMru();
            lblStatus.Text = string.Empty;
            int foundCount = 0;

            #region RegEx

            if (rdoRegexR.Checked)
            {
                Regex rr = null;
                try
                {
                    rr = new Regex(txtFindR.Text, GetRegexOptions());
                }
                catch (ArgumentException ex)
                {
                    lblStatus.Text = "Error in Regular Expression: " + ex.Message;
                    return;
                }

                if (chkSearchSelectionR.Checked)
                {
                    if (_searchRange.cpMin == _searchRange.cpMax)
                    {
                        _searchRange = new CharacterRange(_scintilla.Selections[0].Start, _scintilla.Selections[0].End);
                    }

                    foundCount = FindReplace.ReplaceAll(_searchRange, rr, txtReplace.Text, false, false);
                }
                else
                {
                    _searchRange = new CharacterRange();
                    foundCount   = FindReplace.ReplaceAll(rr, txtReplace.Text, false, false);
                }
            }

            #endregion

            #region Non-RegEx

            if (!rdoRegexR.Checked)
            {
                if (chkSearchSelectionR.Checked)
                {
                    if (_searchRange.cpMin == _searchRange.cpMax)
                    {
                        _searchRange = new CharacterRange(_scintilla.Selections[0].Start, _scintilla.Selections[0].End);
                    }

                    string textToFind    = rdoExtendedR.Checked ? FindReplace.Transform(txtFindR.Text) : txtFindR.Text;
                    string textToReplace = rdoExtendedR.Checked ? FindReplace.Transform(txtReplace.Text) : txtReplace.Text;
                    foundCount = FindReplace.ReplaceAll(_searchRange, textToFind, textToReplace, GetSearchFlags(), false, false);
                }
                else
                {
                    _searchRange = new CharacterRange();
                    string textToFind    = rdoExtendedR.Checked ? FindReplace.Transform(txtFindR.Text) : txtFindR.Text;
                    string textToReplace = rdoExtendedR.Checked ? FindReplace.Transform(txtReplace.Text) : txtReplace.Text;
                    foundCount = FindReplace.ReplaceAll(textToFind, textToReplace, GetSearchFlags(), false, false);
                }
            }

            #endregion

            lblStatus.Text = "Total Replaced: " + foundCount.ToString();
        }
Beispiel #2
0
        private CharacterRange ReplaceNext(bool searchUp)
        {
            Regex          rr       = null;
            CharacterRange selRange = new CharacterRange(_scintilla.Selections[0].Start, _scintilla.Selections[0].End);

            //	We only do the actual replacement if the current selection exactly
            //	matches the find.
            if (selRange.cpMax - selRange.cpMin > 0)
            {
                if (rdoRegexR.Checked)
                {
                    rr = new Regex(txtFindR.Text, GetRegexOptions());
                    string selRangeText = Scintilla.GetTextRange(selRange.cpMin, selRange.cpMax - selRange.cpMin + 1);

                    if (selRange.Equals(FindReplace.Find(selRange, rr, false)))
                    {
                        //	If searching up we do the replacement using the range object.
                        //	Otherwise we use the selection object. The reason being if
                        //	we use the range the caret is positioned before the replaced
                        //	text. Conversely if we use the selection object the caret will
                        //	be positioned after the replaced text. This is very important
                        //	becuase we don't want the new text to be potentially matched
                        //	in the next search.
                        if (searchUp)
                        {
                            _scintilla.SelectionStart = selRange.cpMin;
                            _scintilla.SelectionEnd   = selRange.cpMax;
                            _scintilla.ReplaceSelection(rr.Replace(selRangeText, txtReplace.Text));
                            _scintilla.GotoPosition(selRange.cpMin);
                        }
                        else
                        {
                            Scintilla.ReplaceSelection(rr.Replace(selRangeText, txtReplace.Text));
                        }
                    }
                }
                else
                {
                    string textToFind = rdoExtendedR.Checked ? FindReplace.Transform(txtFindR.Text) : txtFindR.Text;
                    if (selRange.Equals(FindReplace.Find(selRange, textToFind, false)))
                    {
                        //	If searching up we do the replacement using the range object.
                        //	Otherwise we use the selection object. The reason being if
                        //	we use the range the caret is positioned before the replaced
                        //	text. Conversely if we use the selection object the caret will
                        //	be positioned after the replaced text. This is very important
                        //	becuase we don't want the new text to be potentially matched
                        //	in the next search.
                        if (searchUp)
                        {
                            string textToReplace = rdoExtendedR.Checked ? FindReplace.Transform(txtReplace.Text) : txtReplace.Text;
                            _scintilla.SelectionStart = selRange.cpMin;
                            _scintilla.SelectionEnd   = selRange.cpMax;
                            _scintilla.ReplaceSelection(textToReplace);

                            _scintilla.GotoPosition(selRange.cpMin);
                        }
                        else
                        {
                            string textToReplace = rdoExtendedR.Checked ? FindReplace.Transform(txtReplace.Text) : txtReplace.Text;
                            Scintilla.ReplaceSelection(textToReplace);
                        }
                    }
                }
            }
            return(FindNextR(searchUp, ref rr));
        }
Beispiel #3
0
        private void btnFindAll_Click(object sender, EventArgs e)
        {
            if (txtFindF.Text == string.Empty)
            {
                return;
            }

            AddFindMru();

            lblStatus.Text = string.Empty;

            btnClear_Click(null, null);
            int foundCount = 0;

            #region RegEx

            if (rdoRegexF.Checked)
            {
                Regex rr = null;
                try
                {
                    rr = new Regex(txtFindF.Text, GetRegexOptions());
                }
                catch (ArgumentException ex)
                {
                    lblStatus.Text = "Error in Regular Expression: " + ex.Message;
                    return;
                }

                if (chkSearchSelectionF.Checked)
                {
                    if (_searchRange.cpMin == _searchRange.cpMax)
                    {
                        _searchRange = new CharacterRange(_scintilla.Selections[0].Start, _scintilla.Selections[0].End);
                    }

                    foundCount = FindReplace.FindAll(_searchRange, rr, chkMarkLine.Checked, chkHighlightMatches.Checked).Count;
                }
                else
                {
                    _searchRange = new CharacterRange();
                    foundCount   = FindReplace.FindAll(rr, chkMarkLine.Checked, chkHighlightMatches.Checked).Count;
                }
            }

            #endregion

            #region Non-RegEx

            if (!rdoRegexF.Checked)
            {
                if (chkSearchSelectionF.Checked)
                {
                    if (_searchRange.cpMin == _searchRange.cpMax)
                    {
                        _searchRange = new CharacterRange(_scintilla.Selections[0].Start, _scintilla.Selections[0].End);
                    }

                    string textToFind = rdoExtendedF.Checked ? FindReplace.Transform(txtFindF.Text) : txtFindF.Text;
                    foundCount = FindReplace.FindAll(_searchRange, textToFind, GetSearchFlags(), chkMarkLine.Checked, chkHighlightMatches.Checked).Count;
                }
                else
                {
                    _searchRange = new CharacterRange();
                    string textToFind = rdoExtendedF.Checked ? FindReplace.Transform(txtFindF.Text) : txtFindF.Text;
                    foundCount = FindReplace.FindAll(textToFind, GetSearchFlags(), chkMarkLine.Checked, chkHighlightMatches.Checked).Count;
                }
            }

            #endregion

            lblStatus.Text = "Total found: " + foundCount.ToString();
        }
Beispiel #4
0
        private CharacterRange FindNextR(bool searchUp, ref Regex rr)
        {
            CharacterRange foundRange;

            if (rdoRegexR.Checked)
            {
                if (rr == null)
                {
                    rr = new Regex(txtFindR.Text, GetRegexOptions());
                }

                if (chkSearchSelectionR.Checked)
                {
                    if (_searchRange.cpMin == _searchRange.cpMax)
                    {
                        _searchRange = new CharacterRange(_scintilla.Selections[0].Start, _scintilla.Selections[0].End);
                    }

                    if (searchUp)
                    {
                        foundRange = FindReplace.FindPrevious(rr, chkWrapR.Checked, _searchRange);
                    }
                    else
                    {
                        foundRange = FindReplace.FindNext(rr, chkWrapR.Checked, _searchRange);
                    }
                }
                else
                {
                    _searchRange = new CharacterRange();
                    if (searchUp)
                    {
                        foundRange = FindReplace.FindPrevious(rr, chkWrapR.Checked);
                    }
                    else
                    {
                        foundRange = FindReplace.FindNext(rr, chkWrapR.Checked);
                    }
                }
            }
            else
            {
                if (chkSearchSelectionF.Checked)
                {
                    if (_searchRange.cpMin == _searchRange.cpMax)
                    {
                        _searchRange = new CharacterRange(_scintilla.Selections[0].Start, _scintilla.Selections[0].End);
                    }

                    if (searchUp)
                    {
                        string textToFind = rdoExtendedR.Checked ? FindReplace.Transform(txtFindR.Text) : txtFindR.Text;
                        foundRange = FindReplace.FindPrevious(textToFind, chkWrapR.Checked, GetSearchFlags(), _searchRange);
                    }
                    else
                    {
                        string textToFind = rdoExtendedR.Checked ? FindReplace.Transform(txtFindR.Text) : txtFindR.Text;
                        foundRange = FindReplace.FindNext(textToFind, chkWrapR.Checked, GetSearchFlags(), _searchRange);
                    }
                }
                else
                {
                    _searchRange = new CharacterRange();
                    if (searchUp)
                    {
                        string textToFind = rdoExtendedR.Checked ? FindReplace.Transform(txtFindR.Text) : txtFindR.Text;
                        foundRange = FindReplace.FindPrevious(textToFind, chkWrapF.Checked, GetSearchFlags());
                    }
                    else
                    {
                        string textToFind = rdoExtendedR.Checked ? FindReplace.Transform(txtFindR.Text) : txtFindR.Text;
                        foundRange = FindReplace.FindNext(textToFind, chkWrapF.Checked, GetSearchFlags());
                    }
                }
            }
            return(foundRange);
        }