Пример #1
0
        private void cmdFindNext_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                setFindOptions();
                saveFind();
                PNStatic.FindString = cboFind.Text.Trim();
                int position;
                switch (PNStatic.SearchMode)
                {
                case SearchMode.Normal:
                    position = _Edit.SelectionStart == _Edit.TextLength
                            ? PNStatic.FindEditString(_Edit, 0)
                            : PNStatic.FindEditString(_Edit, _Edit.SelectionStart + 1);
                    if (position == -1)
                    {
                        PNMessageBox.Show(PNLang.Instance.GetMessageText("nothing_found", "Nothing found"), PNStrings.PROG_NAME, MessageBoxButton.OK);
                    }
                    break;

                case SearchMode.RegularExp:
                    position = _Edit.SelectionStart == _Edit.TextLength
                            ? PNStatic.FindEditStringByRegExp(_Edit, 0,
                                                              (PNStatic.FindOptions & System.Windows.Forms.RichTextBoxFinds.Reverse) ==
                                                              System.Windows.Forms.RichTextBoxFinds.Reverse)
                            : PNStatic.FindEditStringByRegExp(_Edit, _Edit.SelectionStart + 1,
                                                              (PNStatic.FindOptions & System.Windows.Forms.RichTextBoxFinds.Reverse) ==
                                                              System.Windows.Forms.RichTextBoxFinds.Reverse);
                    if (position == -1)
                    {
                        PNMessageBox.Show(PNLang.Instance.GetMessageText("nothing_found", "Nothing found"),
                                          PNStrings.PROG_NAME, MessageBoxButton.OK);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
Пример #2
0
        private int replaceEditString()
        {
            try
            {
                var position = 0;
                switch (PNStatic.SearchMode)
                {
                case SearchMode.Normal:
                    position = PNStatic.FindEditString(_Edit, _Edit.SelectionStart);
                    if (position > -1)
                    {
                        _Edit.SelectedText = PNStatic.ReplaceString;
                        position           = PNStatic.FindEditString(_Edit, _Edit.SelectionStart);
                        if (position > -1)
                        {
                            _Edit.Select(position, PNStatic.FindString.Length);
                        }
                    }
                    break;

                case SearchMode.RegularExp:
                    var reverse = (PNStatic.FindOptions & System.Windows.Forms.RichTextBoxFinds.Reverse) == System.Windows.Forms.RichTextBoxFinds.Reverse;
                    position = PNStatic.FindEditStringByRegExp(_Edit, _Edit.SelectionStart, reverse);
                    if (position > -1)
                    {
                        _Edit.SelectedText = PNStatic.ReplaceString;
                        position           = PNStatic.FindEditStringByRegExp(_Edit, _Edit.SelectionStart, reverse);
                    }
                    break;
                }

                return(position);
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return(-1);
            }
        }
Пример #3
0
        private int replaceAllEditStrings()
        {
            try
            {
                var count = 0;
                int position;
                switch (PNStatic.SearchMode)
                {
                case SearchMode.Normal:
                    position = PNStatic.FindEditString(_Edit, 0);
                    while (position > -1)
                    {
                        count++;
                        _Edit.SelectedText = PNStatic.ReplaceString;
                        position           = PNStatic.FindEditString(_Edit, _Edit.SelectionStart);
                    }
                    break;

                case SearchMode.RegularExp:
                    position = PNStatic.FindEditStringByRegExp(_Edit, 0, false);
                    while (position > -1)
                    {
                        count++;
                        _Edit.SelectedText = PNStatic.ReplaceString;
                        position           = PNStatic.FindEditStringByRegExp(_Edit, _Edit.SelectionStart, false);
                    }
                    break;
                }

                return(count);
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return(-1);
            }
        }