WatermarkContentViewModel.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Office.EventAggregators;
  3. using PDF_Office.Model;
  4. using Prism.Commands;
  5. using Prism.Events;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Windows;
  12. namespace PDF_Office.ViewModels.EditTools.Watermark
  13. {
  14. public class WatermarkContentViewModel : BindableBase, INavigationAware
  15. {
  16. public IEventAggregator eventAggregator;
  17. public IRegionManager watermarkRegion;
  18. private CPDFViewer PDFViewer;
  19. private ViewContentViewModel viewContentViewModel;
  20. public string TemplateListName = "WatermarkTemplateListBaseContent";
  21. public string CreateName = "WatermarkCreateBaseContent";
  22. public string CreateModTextName = "WatermarkCreateTextContent";
  23. public string CreateModFileName = "WatermarkCreateFileContent";
  24. public string TemplateListModTextName = "WatermarkTemplateListTextContent";
  25. public string TemplateListModFileName = "WatermarkTemplateListFileContent";
  26. public string WatermarkDocumentName = "WatermarkDocumentContent";
  27. private string _watermarkSettingsRegionName;
  28. public string WatermarkSettingsRegionName
  29. {
  30. get { return _watermarkSettingsRegionName; }
  31. set { _watermarkSettingsRegionName = value; }
  32. }
  33. private Visibility _watermarkSettingsVisible = Visibility.Collapsed;
  34. public Visibility WatermarkSettingsVisible
  35. {
  36. get { return _watermarkSettingsVisible; }
  37. set { _watermarkSettingsVisible = value; }
  38. }
  39. private string _watermarkDocumentRegionName;
  40. /// <summary>
  41. /// 持有Document的Region,负责渲染和保存
  42. /// </summary>
  43. public string WatermarkDocumentRegionName
  44. {
  45. get { return _watermarkDocumentRegionName; }
  46. set { _watermarkDocumentRegionName = value; }
  47. }
  48. private Visibility _watermarkDocumentVisible = Visibility.Visible;
  49. /// <summary>
  50. /// 持有Document的Region可见
  51. /// </summary>
  52. public Visibility WatermarkDocumentVisible
  53. {
  54. get { return _watermarkDocumentVisible; }
  55. set { _watermarkDocumentVisible = value; }
  56. }
  57. private EnumTextOrFile _currentCreateMod;
  58. public EnumTextOrFile CurrentCreateMod
  59. {
  60. get { return _currentCreateMod; }
  61. set { _currentCreateMod = value; }
  62. }
  63. private EnumTextOrFile _currentTemplateListMod;
  64. public EnumTextOrFile CurrentTemplateListMod
  65. {
  66. get { return _currentTemplateListMod; }
  67. set { _currentTemplateListMod = value; }
  68. }
  69. public DelegateCommand CloseEditToolCommand { get; set; }
  70. public DelegateCommand ConfirmEditToolCommand { get; set; }
  71. public DelegateCommand<string> EnterSelectedContentCommand { get; set; }
  72. public WatermarkContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  73. {
  74. this.eventAggregator = eventAggregator;
  75. this.watermarkRegion = regionManager;
  76. WatermarkSettingsVisible = Visibility.Visible;
  77. WatermarkSettingsRegionName = Guid.NewGuid().ToString();
  78. WatermarkDocumentRegionName = Guid.NewGuid().ToString();
  79. CloseEditToolCommand = new DelegateCommand(CloseEditTool);
  80. ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool);
  81. EnterSelectedContentCommand = new DelegateCommand<string>(EnterSelectedContent);
  82. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate);
  83. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod);
  84. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Subscribe(SetCurrentTemplateListMod);
  85. }
  86. public void CloseEditTool()
  87. {
  88. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish();
  89. }
  90. public void ConfirmEditTool()
  91. {
  92. this.eventAggregator.GetEvent<ConfirmEditToolsWatermarkEvent>().Publish();
  93. }
  94. public void EnterTemplateListOrCreate(EnumTemplateListOrCreate enumTemplateListOrCreate)
  95. {
  96. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  97. {
  98. EnterSelectedContent(TemplateListName);
  99. }
  100. else
  101. {
  102. EnterSelectedContent(CreateName);
  103. }
  104. }
  105. public void SetCurrentCreateMod(string currentCreateModName)
  106. {
  107. if (currentCreateModName == CreateModTextName)
  108. {
  109. CurrentCreateMod = EnumTextOrFile.StatusText;
  110. }
  111. else if (currentCreateModName == CreateModFileName)
  112. {
  113. CurrentCreateMod = EnumTextOrFile.StatusFile;
  114. }
  115. }
  116. public void SetCurrentTemplateListMod(string currentTemplateListModName)
  117. {
  118. if (currentTemplateListModName == TemplateListModTextName)
  119. {
  120. CurrentTemplateListMod = EnumTextOrFile.StatusText;
  121. }
  122. else if (currentTemplateListModName == TemplateListModFileName)
  123. {
  124. CurrentTemplateListMod = EnumTextOrFile.StatusFile;
  125. }
  126. }
  127. public void EnterSelectedContent(string SelectedContentName)
  128. {
  129. NavigationParameters param = new NavigationParameters();
  130. param.Add(ParameterNames.PDFViewer, PDFViewer);
  131. if (SelectedContentName == TemplateListName)
  132. {
  133. param.Add("CurrentCreateModName", CurrentCreateMod);
  134. }
  135. else if (SelectedContentName == CreateName)
  136. {
  137. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  138. }
  139. watermarkRegion.RequestNavigate(WatermarkSettingsRegionName, SelectedContentName, param);
  140. WatermarkSettingsVisible = Visibility.Visible;
  141. }
  142. public void EnterDocumentContent()
  143. {
  144. NavigationParameters param = new NavigationParameters();
  145. param.Add(ParameterNames.PDFViewer, PDFViewer);
  146. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  147. watermarkRegion.RequestNavigate(WatermarkDocumentRegionName, WatermarkDocumentName, param);
  148. WatermarkDocumentVisible = Visibility.Visible;
  149. }
  150. public void OnNavigatedTo(NavigationContext navigationContext)
  151. {
  152. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  153. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  154. EnterSelectedContent(TemplateListName);
  155. EnterDocumentContent();
  156. }
  157. public bool IsNavigationTarget(NavigationContext navigationContext)
  158. {
  159. return true;
  160. }
  161. public void OnNavigatedFrom(NavigationContext navigationContext)
  162. {
  163. }
  164. }
  165. }