WatermarkTemplateListBaseContentViewModel.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Master.CustomControl;
  3. using PDF_Master.EventAggregators;
  4. using PDF_Master.Model;
  5. using PDF_Master.ViewModels.Tools;
  6. using Prism.Commands;
  7. using Prism.Events;
  8. using Prism.Mvvm;
  9. using Prism.Regions;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Windows.Controls;
  14. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  15. using Button = System.Windows.Controls.Button;
  16. namespace PDF_Master.ViewModels.EditTools.Watermark
  17. {
  18. public class WatermarkTemplateListBaseContentViewModel : BindableBase, INavigationAware
  19. {
  20. public IRegionManager watermarkTemplateListRegion;
  21. private readonly IEventAggregator eventAggregator;
  22. private CPDFViewer CurrentPDFViewer;
  23. private string WatermarkTemplateListTextContentName = "WatermarkTemplateListTextContent";
  24. private string WatermarkTemplateListFileContentName = "WatermarkTemplateListFileContent";
  25. public bool IsFirstEnter = true;
  26. public EnumTextOrFile CurrentCreateMod;
  27. private string _currentTemplateListModName;
  28. public string CurrentTemplateListModName
  29. {
  30. get { return _currentTemplateListModName; }
  31. set { _currentTemplateListModName = value; }
  32. }
  33. private string watermarkTemplateListRegionName;
  34. public string WatermarkTemplateListRegionName
  35. {
  36. get => watermarkTemplateListRegionName;
  37. set => SetProperty(ref watermarkTemplateListRegionName, value);
  38. }
  39. private System.Windows.Visibility watermarkTemplateListVisible;
  40. public System.Windows.Visibility WatermarkTemplateListVisible
  41. {
  42. get => watermarkTemplateListVisible;
  43. set => SetProperty(ref watermarkTemplateListVisible, value);
  44. }
  45. public DelegateCommand<object> ChangeTemplateListModCommand { get; set; }
  46. public DelegateCommand EnterCreateCommand { get; set; }
  47. public string Unicode = null;
  48. public WatermarkTemplateListBaseContentViewModel(IRegionManager watermarkTemplateListRegion, IEventAggregator eventAggregator)
  49. {
  50. this.watermarkTemplateListRegion = watermarkTemplateListRegion;
  51. this.eventAggregator = eventAggregator;
  52. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  53. WatermarkTemplateListRegionName = Guid.NewGuid().ToString();
  54. ChangeTemplateListModCommand = new DelegateCommand<object>(ChangeTemplateListMod);
  55. EnterCreateCommand = new DelegateCommand(EnterCreate);
  56. EnterSelectedTemplateListMod("WatermarkTemplateListColorContent");
  57. eventAggregator.GetEvent<CurrentWatermarkPDFViewerEvent>().Subscribe(CurrentWatermarkPDFViewer, e => e.Unicode == Unicode);
  58. }
  59. public void CurrentWatermarkPDFViewer(CPDFViewerUnicode cPDFViewerunicode)
  60. {
  61. CurrentPDFViewer = cPDFViewerunicode.Status;
  62. }
  63. public void EnterCreate()
  64. {
  65. AlertsMessage alertsMessage = new AlertsMessage();
  66. if (CurrentPDFViewer.Document.GetWatermarkCount() > 0)
  67. {
  68. alertsMessage.ShowDialog("文件中已添加水印,您要替换现有的水印吗?", "", "取消", "确定");
  69. if (alertsMessage.result == ContentResult.Ok)
  70. {
  71. this.eventAggregator.GetEvent<DeleteWatermarkEvent>().Publish(new EnumDeleteUnicode
  72. {
  73. Unicode = Unicode,
  74. Status = EnumDelete.StatusDeleteInitial
  75. });
  76. }
  77. else
  78. {
  79. //this.eventAggregator.GetEvent<DeleteWatermarkEvent>().Publish(new EnumDeleteUnicode
  80. //{
  81. // Unicode = Unicode,
  82. // Status = EnumDelete.StatusCreate
  83. //});
  84. return;
  85. }
  86. }
  87. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode
  88. {
  89. Unicode = Unicode,
  90. Status = EnumTemplateListOrCreate.StatusCreate
  91. });
  92. }
  93. public void EnterSelectedTemplateListMod(string currentTemplateListName)
  94. {
  95. NavigationParameters param = new NavigationParameters();
  96. param.Add(ParameterNames.PDFViewer, CurrentPDFViewer);
  97. watermarkTemplateListRegion.RequestNavigate(WatermarkTemplateListRegionName, currentTemplateListName, param);
  98. eventAggregator.GetEvent<CurrentWatermarkPDFViewerEvent>().Publish(new CPDFViewerUnicode
  99. {
  100. Unicode = Unicode,
  101. Status = CurrentPDFViewer
  102. });
  103. watermarkTemplateListVisible = System.Windows.Visibility.Visible;
  104. }
  105. public void ChangeTemplateListMod(object e)
  106. {
  107. var args = e as Button;
  108. if (args != null)
  109. {
  110. CurrentTemplateListModName = args.Name;
  111. EnterSelectedTemplateListMod(CurrentTemplateListModName);
  112. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(new stringUnicode
  113. {
  114. Unicode = Unicode,
  115. Status = CurrentTemplateListModName
  116. });
  117. }
  118. }
  119. public bool IsNavigationTarget(NavigationContext navigationContext)
  120. {
  121. return true;
  122. }
  123. public void OnNavigatedFrom(NavigationContext navigationContext)
  124. {
  125. }
  126. public void OnNavigatedTo(NavigationContext navigationContext)
  127. {
  128. if (IsFirstEnter)
  129. {
  130. CurrentTemplateListModName = WatermarkTemplateListTextContentName;
  131. EnterSelectedTemplateListMod(CurrentTemplateListModName);
  132. IsFirstEnter = false;
  133. }
  134. else
  135. {
  136. navigationContext.Parameters.TryGetValue<EnumTextOrFile>("CurrentCreateModName", out CurrentCreateMod);
  137. if (CurrentCreateMod == EnumTextOrFile.StatusText)
  138. {
  139. CurrentTemplateListModName = WatermarkTemplateListTextContentName;
  140. }
  141. else
  142. {
  143. CurrentTemplateListModName = WatermarkTemplateListFileContentName;
  144. }
  145. EnterSelectedTemplateListMod(CurrentTemplateListModName);
  146. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(new stringUnicode
  147. {
  148. Unicode = Unicode,
  149. Status = CurrentTemplateListModName
  150. });
  151. }
  152. }
  153. }
  154. }