private void removeThumbnail(ThumbnailButton thb) { try { var note = PNStatic.Notes.FirstOrDefault(n => n.ID == thb.Id); thb.Click -= Thumbnail_Click; thb.MouseEnter -= Thumbnail_MouseEnter; thb.MouseLeave -= Thumbnail_MouseLeave; thb.MouseDoubleClick -= Thumbnail_MouseDoubleClick; Thumbnails.Remove(thb); if (note == null) { return; } note.Thumbnail = false; PNNotesOperations.SaveNoteThumbnail(note); if (note.Dialog == null) { return; } note.PlaceOnScreen(); } catch (Exception ex) { PNStatic.LogException(ex); } }
private void Path_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { try { switch (DockDirection) { case DockArrow.LeftUp: case DockArrow.RightUp: PNNotesOperations.ShiftDockDown(DockDirection); break; case DockArrow.LeftDown: case DockArrow.RightDown: PNNotesOperations.ShiftDockUp(DockDirection); break; case DockArrow.TopLeft: case DockArrow.BottomLeft: PNNotesOperations.ShiftDockRight(DockDirection); break; case DockArrow.TopRight: case DockArrow.BottomRight: PNNotesOperations.ShiftDockLeft(DockDirection); break; } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void FormMain_NoteTagsChanged(object sender, EventArgs e) { try { var note = sender as PNote; if (note == null || _Notes.Count == 0) { return; } var item = _Notes.FirstOrDefault(n => n.Id == note.ID); var tags = _Tags.Where(t => t.Selected).Select(t => t.Tag); if (item == null) //note was not in list { if (!note.Tags.Any(nt => tags.Any(t => t == nt))) { return; } var key = PNNotesOperations.GetNoteImage(note); _Notes.Add(new FoundNote(key, note.Name, note.Tags.ToCommaSeparatedString(), note.ID)); } else //note was in list { if (!note.Tags.Any(nt => tags.Any(t => t == nt))) { _Notes.Remove(item); } } } catch (Exception ex) { PNStatic.LogException(ex); } }
internal int RemoveThumbnail(PNote note, bool resetProperty = true) { try { var index = 0; var thb = Thumbnails.FirstOrDefault(t => t.Id == note.ID); if (thb != null) { index = Thumbnails.IndexOf(thb); thb.Click -= Thumbnail_Click; thb.MouseEnter -= Thumbnail_MouseEnter; thb.MouseLeave -= Thumbnail_MouseLeave; thb.MouseDoubleClick -= Thumbnail_MouseDoubleClick; Thumbnails.Remove(thb); } if (resetProperty) { note.Thumbnail = false; PNNotesOperations.SaveNoteThumbnail(note); } if (note.Dialog == null) { return(index); } note.PlaceOnScreen(); return(index); } catch (Exception ex) { PNStatic.LogException(ex); return(0); } }
private void cmdOK_Click(object sender, RoutedEventArgs e) { try { setUpSchedule(); _Note.Schedule = (PNNoteSchedule)_Schedule.Clone(); if (_Schedule.CloseOnNotification && _Schedule.Type != ScheduleType.None && _Note.Visible) { PNNotesOperations.ShowHideSpecificNote(_Note, false); } DialogResult = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
private void changeNodeImage(PNote note) { try { foreach ( var tn in tvwResults.Items.OfType <PNTreeItem>().Where(tn => tn.Tag != null && (string)tn.Tag == note.ID)) { tn.SetImageResource(PNNotesOperations.GetNoteImage(note)); break; } } catch (Exception ex) { PNStatic.LogException(ex); } }
internal static void PlaceOnScreen(this PNote note) { var size = PNStatic.AllScreensSize(); var rect = PNStatic.AllScreensBounds(); if (PNStatic.Settings.Behavior.RelationalPositioning) { note.Dialog.SetLocation(new Point((int)Math.Floor(size.Width * note.XFactor), (int)Math.Floor(size.Height * note.YFactor))); while (note.Dialog.Left + note.Dialog.Width > size.Width) { note.Dialog.Left--; } if (rect.X >= 0) { while (note.Dialog.Left < 0) { note.Dialog.Left++; } } while (note.Dialog.Top + note.Dialog.Height > size.Height) { note.Dialog.Top--; } if (rect.Y >= 0) { while (note.Dialog.Top < 0) { note.Dialog.Top++; } } } else { if (rect.IntersectsWith(new Rect(note.NoteLocation, note.NoteSize))) { note.Dialog.SetLocation(note.NoteLocation); } else { PNNotesOperations.CentralizeNotes(new[] { note }); } } }
private void PNTreeView_PNTreeViewLeftMouseDoubleClick(object sender, MouseButtonEventArgs e) { try { var item = tvwResults.GetHierarchyObjectAtPoint <PNTreeItem>(e.GetPosition(tvwResults)) as PNTreeItem; if (item == null) { return; } if (item.Parent == null) { var note = PNStatic.Notes.Note((string)item.Tag); if (note != null) { PNNotesOperations.ShowHideSpecificNote(note, true); } } else if (item.Tag != null) { var parent = item.Parent as PNTreeItem; if (parent == null) { return; } var note = PNStatic.Notes.Note((string)parent.Tag); if (note == null) { return; } if (PNNotesOperations.ShowHideSpecificNote(note, true) != ShowHideResult.Success) { return; } var range = (int[])item.Tag; note.Dialog.Edit.SelectionStart = range[0]; note.Dialog.Edit.SelectionLength = range[1]; } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void cmdOK_Click(object sender, RoutedEventArgs e) { try { if (Directory.Exists(PNPaths.Instance.TempDir)) { Directory.Delete(PNPaths.Instance.TempDir, true); } Directory.CreateDirectory(PNPaths.Instance.TempDir); var zipPath = Path.Combine(PNPaths.Instance.TempDir, txtArchName.Text.Trim() + ".zip"); using (var package = Package.Open(zipPath, FileMode.OpenOrCreate)) { foreach (string f in _Files) { var fileName = Path.GetFileName(f); if (fileName == null) { continue; } var partUriFile = PackUriHelper.CreatePartUri(new Uri(fileName, UriKind.Relative)); var packagePartFile = package.CreatePart(partUriFile, MediaTypeNames.Text.RichText, CompressionOption.Normal); if (packagePartFile == null) { continue; } package.CreateRelationship(partUriFile, TargetMode.Internal, fileName); using (var fileStream = new FileStream(f, FileMode.Open, FileAccess.Read)) { PNStatic.CopyStream(fileStream, packagePartFile.GetStream()); } } } var archives = new List <string> { zipPath }; PNNotesOperations.SendNotesAsAttachments(archives); DialogResult = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
private void grdTagsResults_MouseDoubleClick(object sender, MouseButtonEventArgs e) { try { var item = grdTagsResults.GetObjectAtPoint <ListViewItem>(e.GetPosition(grdTagsResults)) as FoundNote; if (item == null) { return; } var note = PNStatic.Notes.Note(item.Id); if (note != null) { PNNotesOperations.ShowHideSpecificNote(note, true); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void grdOverdue_MouseDoubleClick(object sender, MouseButtonEventArgs e) { try { var item = grdOverdue.SelectedItem as OverdueNote; if (item == null) { return; } var note = PNStatic.Notes.Note(item.Id); if (note != null) { PNNotesOperations.AdjustNoteSchedule(note, this); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void FormMain_NoteBooleanChanged(object sender, NoteBooleanChangedEventArgs e) { try { var note = sender as PNote; if (note == null || _Notes.Count == 0) { return; } var item = _Notes.FirstOrDefault(n => n.Id == note.ID); if (item == null) { return; } item.IconSource = PNNotesOperations.GetNoteImage(note); } catch (Exception ex) { PNStatic.LogException(ex); } }
private void findNotes() { try { _Notes.Clear(); var tags = _Tags.Where(t => t.Selected).Select(t => t.Tag); var notes = PNStatic.Notes.Where(n => n.GroupID != (int)SpecialGroups.RecycleBin); foreach (var note in notes) { if (!note.Tags.Any(nt => tags.Any(t => t == nt))) { continue; } var key = PNNotesOperations.GetNoteImage(note); _Notes.Add(new FoundNote(key, note.Name, note.Tags.ToCommaSeparatedString(), note.ID)); } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void addNote(PNote note) { try { var key = PNNotesOperations.GetNoteImage(note); _Notes.Add(new Result { IconSource = key, Created = note.DateCreated, Saved = note.DateSaved, Deleted = note.DateDeleted, Name = note.Name, Received = note.DateReceived, Sent = note.DateSent, Id = note.ID }); } catch (Exception ex) { PNStatic.LogException(ex); } }
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 cmdOK_Click(object sender, RoutedEventArgs e) { try { var note = PNStatic.Notes.Note(_ID); if (note != null) { switch (_Mode) { case ExchangeLists.Tags: note.Tags.Clear(); foreach (var n in lstCurrent.Items.OfType <KeyValuePair <string, TextBlock> >()) { note.Tags.Add(n.Value.Text); } PNNotesOperations.SaveNoteTags(note); note.RaiseTagsChangedEvent(); break; case ExchangeLists.LinkedNotes: note.LinkedNotes.Clear(); foreach (var n in lstCurrent.Items.OfType <KeyValuePair <string, TextBlock> >()) { note.LinkedNotes.Add((string)n.Value.Tag); } PNNotesOperations.SaveLinkedNotes(note); break; } } DialogResult = true; } catch (Exception ex) { PNStatic.LogException(ex); } }
private void _Timer_Elapsed(object sender, ElapsedEventArgs e) { bool continueNext = true; try { var now = e.SignalTime; _Timer.Stop(); var doAlarm = false; long seconds; DateTime start, alarmDate; var changeZone = _Schedule.TimeZone != TimeZoneInfo.Local; switch (_Schedule.Type) { case ScheduleType.Once: alarmDate = changeZone ? TimeZoneInfo.ConvertTime(_Schedule.AlarmDate, TimeZoneInfo.Local, _Schedule.TimeZone) : _Schedule.AlarmDate; if (alarmDate.IsDateEqual(now)) { doAlarm = true; continueNext = false; } break; case ScheduleType.After: start = _Schedule.StartFrom == ScheduleStart.ExactTime ? (changeZone ? TimeZoneInfo.ConvertTime(_Schedule.StartDate, TimeZoneInfo.Local, _Schedule.TimeZone) : _Schedule.StartDate) : PNStatic.StartTime; PNStatic.NormalizeStartDate(ref start); seconds = (now - start).Ticks / TimeSpan.TicksPerSecond; if (seconds == _Schedule.AlarmAfter.TotalSeconds) { doAlarm = true; continueNext = false; } break; case ScheduleType.RepeatEvery: if (_Schedule.LastRun == DateTime.MinValue) { start = _Schedule.StartFrom == ScheduleStart.ExactTime ? (changeZone ? TimeZoneInfo.ConvertTime(_Schedule.StartDate, TimeZoneInfo.Local, _Schedule.TimeZone) : _Schedule.StartDate) : PNStatic.StartTime; } else { start = _Schedule.LastRun; } PNStatic.NormalizeStartDate(ref start); seconds = (now - start).Ticks / TimeSpan.TicksPerSecond; if (seconds == _Schedule.AlarmAfter.TotalSeconds || (seconds > 0 && seconds % _Schedule.AlarmAfter.TotalSeconds == 0)) { doAlarm = true; } break; case ScheduleType.EveryDay: alarmDate = changeZone ? TimeZoneInfo.ConvertTime(_Schedule.AlarmDate, TimeZoneInfo.Local, _Schedule.TimeZone) : _Schedule.AlarmDate; if (alarmDate.IsTimeEqual(now) && (_Schedule.LastRun == DateTime.MinValue || _Schedule.LastRun <= now.AddDays(-1))) { doAlarm = true; } break; case ScheduleType.Weekly: alarmDate = changeZone ? TimeZoneInfo.ConvertTime(_Schedule.AlarmDate, TimeZoneInfo.Local, _Schedule.TimeZone) : _Schedule.AlarmDate; if (alarmDate.IsTimeEqual(now)) { if (_Schedule.Weekdays.Contains(now.DayOfWeek) && (_Schedule.LastRun == DateTime.MinValue || _Schedule.LastRun <= now.AddDays(-1))) { doAlarm = true; } } break; case ScheduleType.MonthlyExact: alarmDate = changeZone ? TimeZoneInfo.ConvertTime(_Schedule.AlarmDate, TimeZoneInfo.Local, _Schedule.TimeZone) : _Schedule.AlarmDate; if (alarmDate.Day == now.Day) { if (alarmDate.IsTimeEqual(now)) { if (_Schedule.LastRun == DateTime.MinValue || _Schedule.LastRun.Month < now.Month || _Schedule.LastRun.Year < now.Year) { doAlarm = true; } } } break; case ScheduleType.MonthlyDayOfWeek: if (now.DayOfWeek == _Schedule.MonthDay.WeekDay) { alarmDate = changeZone ? TimeZoneInfo.ConvertTime(_Schedule.AlarmDate, TimeZoneInfo.Local, _Schedule.TimeZone) : _Schedule.AlarmDate; if (alarmDate.IsTimeEqual(now)) { bool isLast = false; int ordinal = PNStatic.WeekdayOrdinal(now, _Schedule.MonthDay.WeekDay, ref isLast); if (_Schedule.MonthDay.OrdinalNumber == DayOrdinal.Last) { if (isLast) { if (_Schedule.LastRun == DateTime.MinValue || _Schedule.LastRun.Month < now.Month || _Schedule.LastRun.Year < now.Year) { doAlarm = true; } } } else { if ((int)_Schedule.MonthDay.OrdinalNumber == ordinal) { if (_Schedule.LastRun == DateTime.MinValue || _Schedule.LastRun.Month < now.Month || _Schedule.LastRun.Year < now.Year) { doAlarm = true; } } } } } break; case ScheduleType.MultipleAlerts: foreach (var ma in _Schedule.MultiAlerts.Where(a => !a.Raised)) { alarmDate = changeZone ? TimeZoneInfo.ConvertTime(ma.Date, TimeZoneInfo.Local, _Schedule.TimeZone) : ma.Date; if (!alarmDate.IsDateEqual(now)) continue; ma.Checked = true; doAlarm = true; break; } break; } if (doAlarm) { if (!PNStatic.FormMain.Dispatcher.CheckAccess()) { _ElapsedDelegate d = _Timer_Elapsed; PNStatic.FormMain.Dispatcher.Invoke(d, sender, e); } else { bool save = false; switch (_Schedule.Type) { case ScheduleType.EveryDay: case ScheduleType.RepeatEvery: case ScheduleType.Weekly: case ScheduleType.MonthlyExact: case ScheduleType.MonthlyDayOfWeek: _Schedule.LastRun = now; save = true; break; case ScheduleType.MultipleAlerts: var ma = _Schedule.MultiAlerts.FirstOrDefault(a => a.Checked); if (ma != null) { ma.Checked = false; ma.Raised = true; } save = true; break; } PNStatic.FormMain.ApplyDoAlarm(this); if (save) { PNNotesOperations.SaveNoteSchedule(this); } if (!continueNext) { PNNotesOperations.DeleteNoteSchedule(this); } } } } catch (Exception ex) { PNStatic.LogException(ex); } finally { if (continueNext) { _Timer.Start(); } } }
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); } }
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); } }