StickyNotePopupViewModel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using ComPDFKitViewer.AnnotEvent;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Master.Model;
  4. using PDF_Master.Properties;
  5. using Prism.Commands;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
  14. {
  15. internal class StickyNotePopupViewModel : BindableBase, INavigationAware
  16. {
  17. private string authorText;
  18. public string AuthorText
  19. {
  20. get { return authorText; }
  21. set
  22. {
  23. SetProperty(ref authorText, value);
  24. }
  25. }
  26. private string dateText;
  27. public string DateText
  28. {
  29. get { return dateText; }
  30. set
  31. {
  32. SetProperty(ref dateText, value);
  33. }
  34. }
  35. private string contentText;
  36. public string ContentText
  37. {
  38. get { return contentText; }
  39. set
  40. {
  41. SetProperty(ref contentText, value);
  42. }
  43. }
  44. private ViewContentViewModel ViewContentViewModel;
  45. private StickyAnnotArgs StickyAnnotArgs;
  46. private AnnotCommandArgs AnnotCommandArgs;
  47. private CPDFViewer PDFViewer;
  48. public DelegateCommand<object> ContentTextLostFocus { get; set; }
  49. public StickyNotePopupViewModel()
  50. {
  51. ContentTextLostFocus = new DelegateCommand<object>(ContentText_LostFocus);
  52. }
  53. private void ContentText_LostFocus(object obj)
  54. {
  55. if (ViewContentViewModel == null || StickyAnnotArgs == null || PDFViewer == null || AnnotCommandArgs == null)
  56. {
  57. return;
  58. }
  59. if (string.IsNullOrEmpty(ContentText))
  60. {
  61. ViewContentViewModel.IsNoteAdd = false;
  62. return;
  63. }
  64. StickyAnnotArgs.StickyNote = ContentText;
  65. PDFViewer.CreatePageAnnot(AnnotCommandArgs.PageIndex, StickyAnnotArgs);
  66. ViewContentViewModel.IsNoteAdd = false;
  67. }
  68. public bool IsNavigationTarget(NavigationContext navigationContext)
  69. {
  70. return true;
  71. }
  72. public void OnNavigatedFrom(NavigationContext navigationContext)
  73. {
  74. if(StickyAnnotArgs != null && string.IsNullOrEmpty(StickyAnnotArgs.Content))
  75. {
  76. PDFViewer.RemovePageAnnot(StickyAnnotArgs.PageIndex, StickyAnnotArgs.AnnotIndex);
  77. }
  78. }
  79. public void OnNavigatedTo(NavigationContext navigationContext)
  80. {
  81. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out ViewContentViewModel);
  82. navigationContext.Parameters.TryGetValue<StickyAnnotArgs>(ParameterNames.StickyAnnotArgs, out StickyAnnotArgs);
  83. navigationContext.Parameters.TryGetValue<AnnotCommandArgs>(ParameterNames.AnnotCommandArgs, out AnnotCommandArgs);
  84. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  85. SetToolParam();
  86. AuthorText = Settings.Default.AppProperties.Description.Author;
  87. DateText = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss");
  88. }
  89. private void SetToolParam()
  90. {
  91. if(PDFViewer != null && StickyAnnotArgs != null && string.IsNullOrEmpty(StickyAnnotArgs.Content))
  92. {
  93. PDFViewer.SetToolParam(StickyAnnotArgs);
  94. }
  95. }
  96. }
  97. }