Beispiel #1
0
        private void replaceEntireString(PNote note, string searchString, string replaceString, System.Windows.Forms.RichTextBoxFinds options,
                                         ref int count)
        {
            try
            {
                var           start     = 0;
                var           foundText = false;
                PNRichEditBox edit;

                if (note.Visible)
                {
                    edit = note.Dialog.Edit;
                }
                else
                {
                    var path = Path.Combine(PNPaths.Instance.DataDir, note.ID + PNStrings.NOTE_EXTENSION);
                    _HiddenEdit.Size = note.EditSize;
                    PNNotesOperations.LoadNoteFile(_HiddenEdit, path);
                    edit = _HiddenEdit;
                }

                var stop  = edit.TextLength;
                var index = edit.Find(searchString, start, options);
                if (index > -1)
                {
                    foundText = true;
                    var current = 0;
                    while (index > -1 && current <= index)
                    {
                        count++;
                        current = index;

                        edit.Select(index, searchString.Length);
                        edit.SelectedText = replaceString;

                        if (searchString.Length > 1)
                        {
                            start = index + searchString.Length - 1;
                        }
                        else
                        {
                            start = index + searchString.Length;
                        }
                        if (start >= stop)
                        {
                            break;
                        }
                        index = edit.Find(searchString, start, options);
                    }
                }
                //save hidden note
                if (foundText && !note.Visible)
                {
                    var path = Path.Combine(PNPaths.Instance.DataDir, note.ID + PNStrings.NOTE_EXTENSION);
                    PNNotesOperations.SaveNoteFile(edit, path);
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }