private void loadNotePreview(string id) { try { var note = PNStatic.Notes.Note(id); if (note == null) { return; } var path = Path.Combine(PNPaths.Instance.DataDir, note.ID + PNStrings.NOTE_EXTENSION); if (File.Exists(path)) { PNNotesOperations.LoadNoteFile(_Edit, path); if (!PNStatic.Settings.GeneralSettings.UseSkins) { _EditControl.WinForm.BackColor = note.DrawingColor(); } } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void findInNoteAtLeastOneWord(PNote note, string searchString, System.Windows.Forms.RichTextBoxFinds options, ref int count) { try { var foundTitle = false; PNRichEditBox edit; var strings = searchString.Split(' '); var counter = 0; var key = PNNotesOperations.GetNoteImage(note); var tn = new PNTreeItem(key, note.Name, note.ID); switch (_Scope) { case SearchScope.Titles: if (!strings.Any(s => note.Name.Contains(s))) { return; } count++; _FoundItems.Add(tn); return; case SearchScope.TextAndTitles: if (strings.Any(s => note.Name.Contains(s))) { count++; foundTitle = true; } break; } 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; foreach (var s in strings) { var start = 0; var index = edit.Find(s, start, options); if (index <= -1) { continue; } counter++; var current = 0; while (index > -1 && current <= index) { count++; current = index; var line = edit.GetLineFromCharIndex(index); var col = index - edit.GetFirstCharIndexFromLine(line); var t = new PNTreeItem("searchloc", s + " (" + _Line + " " + (line + 1).ToString(CultureInfo.InvariantCulture) + ", " + _Column + " " + (col + 1).ToString(CultureInfo.InvariantCulture) + ")", new[] { index, s.Length }); tn.Items.Add(t); if (s.Length > 1) { start = index + s.Length - 1; } else { start = index + s.Length; } if (start >= stop) { break; } index = edit.Find(s, start, options); } } if (counter > 0 || foundTitle) { if (_Scope == SearchScope.TextAndTitles) { if (counter > 0 && foundTitle) { tn.Text += @" " + _TextAndTitle; } else if (counter > 0) { tn.Text += @" " + _TextOnly; } else { tn.Text += @" " + _TitleOnly; } } _FoundItems.Add(tn); return; } count = 0; } catch (Exception ex) { PNStatic.LogException(ex); } }
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); } }