BackgroundContentViewModel.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using Dropbox.Api.Sharing;
  2. using PDF_Office.EventAggregators;
  3. using Prism.Commands;
  4. using Prism.Events;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using System;
  8. using System.Windows;
  9. using System.Linq;
  10. using System.Windows.Controls;
  11. using Visibility = System.Windows.Visibility;
  12. using Dropbox.Api.FileProperties;
  13. using ComPDFKitViewer.PdfViewer;
  14. using PDF_Office.Model;
  15. using PDF_Office.Model.EditTools.Background;
  16. using PDFSettings;
  17. namespace PDF_Office.ViewModels.EditTools.Background
  18. {
  19. public class BackgroundContentViewModel : BindableBase, INavigationAware
  20. {
  21. public IEventAggregator eventAggregator;
  22. public IRegionManager backgroundRegion;
  23. private CPDFViewer PDFViewer;
  24. private ViewContentViewModel viewContentViewModel;
  25. public string TemplateListBaseName = "BackgroundTemplateListBaseContent";
  26. public string CreateBaseName = "BackgroundCreateBaseContent";
  27. public string CreateModColorName = "BackgroundCreateColorContent";
  28. public string CreateModFileName = "BackgroundCreateFileContent";
  29. public string TemplateListModColorName = "BackgroundTemplateListColorContent";
  30. public string TemplateListModFileName = "BackgroundTemplateListFileContent";
  31. public string BackgroundDocumentName = "BackgroundDocumentContent";
  32. private string _backgroundSettingsRegionName;
  33. /// <summary>
  34. /// 属性设置Region
  35. /// </summary>
  36. public string BackgroundSettingsRegionName
  37. {
  38. get { return _backgroundSettingsRegionName; }
  39. set { _backgroundSettingsRegionName = value; }
  40. }
  41. private Visibility _backgroundSettingsVisible = Visibility.Collapsed;
  42. /// <summary>
  43. /// 属性设置Region可见
  44. /// </summary>
  45. public Visibility BackgroundSettingsVisible
  46. {
  47. get { return _backgroundSettingsVisible; }
  48. set { _backgroundSettingsVisible = value; }
  49. }
  50. private string _backgroundDocumentRegionName;
  51. /// <summary>
  52. /// 持有Document的Region,负责渲染和保存
  53. /// </summary>
  54. public string BackgroundDocumentRegionName
  55. {
  56. get { return _backgroundDocumentRegionName; }
  57. set { _backgroundDocumentRegionName = value; }
  58. }
  59. private Visibility _backgroundDocumentVisible = Visibility.Visible;
  60. /// <summary>
  61. /// 持有Document的Region可见
  62. /// </summary>
  63. public Visibility BackgroundDocumentVisible
  64. {
  65. get { return _backgroundDocumentVisible; }
  66. set { _backgroundDocumentVisible = value; }
  67. }
  68. private EnumColorOrFile _currentCreateMod;
  69. public EnumColorOrFile CurrentCreateMod
  70. {
  71. get { return _currentCreateMod; }
  72. set { _currentCreateMod = value; }
  73. }
  74. private EnumColorOrFile _currentTemplateListMod;
  75. public EnumColorOrFile CurrentTemplateListMod
  76. {
  77. get { return _currentTemplateListMod; }
  78. set { _currentTemplateListMod = value; }
  79. }
  80. /// <summary>
  81. /// 退出EditTool
  82. /// </summary>
  83. public DelegateCommand CloseEditToolCommand { get; set; }
  84. public DelegateCommand ConfirmEditToolCommand { get; set; }
  85. public DelegateCommand<string> EnterSelectedContentCommand { get; set; }
  86. public BackgroundContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  87. {
  88. this.eventAggregator = eventAggregator;
  89. this.backgroundRegion = regionManager;
  90. BackgroundSettingsVisible = Visibility.Visible;
  91. BackgroundSettingsRegionName = Guid.NewGuid().ToString();
  92. BackgroundDocumentRegionName = Guid.NewGuid().ToString();
  93. CloseEditToolCommand = new DelegateCommand(CloseEditTool);
  94. ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool);
  95. EnterSelectedContentCommand = new DelegateCommand<string>(EnterSelectedContent);
  96. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate);
  97. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod);
  98. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Subscribe(SetCurrentTemplateListMod);
  99. eventAggregator.GetEvent<EditBackgroundTemplateItemEvent>().Subscribe(EditBackgroundTemplateItem);
  100. }
  101. public void CloseEditTool()
  102. {
  103. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(EnumCloseMode.StatusCancel);
  104. }
  105. public void ConfirmEditTool()
  106. {
  107. this.eventAggregator.GetEvent<ConfirmEditToolsBackgroundEvent>().Publish();
  108. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(EnumCloseMode.StatusConfirm);
  109. }
  110. public void EnterTemplateListOrCreate(EnumTemplateListOrCreate enumTemplateListOrCreate)
  111. {
  112. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  113. {
  114. EnterSelectedContent(TemplateListBaseName);
  115. }
  116. else
  117. {
  118. EnterSelectedContent(CreateBaseName);
  119. }
  120. }
  121. public void SetCurrentCreateMod(string currentCreateModName)
  122. {
  123. if (currentCreateModName == CreateModColorName)
  124. {
  125. CurrentCreateMod = EnumColorOrFile.StatusColor;
  126. }
  127. else if (currentCreateModName == CreateModFileName)
  128. {
  129. CurrentCreateMod = EnumColorOrFile.StatusFile;
  130. }
  131. }
  132. public void EditBackgroundTemplateItem(BackgroundItem backgroundItem)
  133. {
  134. NavigationParameters param = new NavigationParameters();
  135. param.Add(ParameterNames.PDFViewer, PDFViewer);
  136. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  137. param.Add("BackgroundItem", backgroundItem);
  138. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, CreateBaseName, param);
  139. BackgroundSettingsVisible = Visibility.Visible;
  140. }
  141. public void SetCurrentTemplateListMod(string currentTemplateListModName)
  142. {
  143. if (currentTemplateListModName == TemplateListModColorName)
  144. {
  145. CurrentTemplateListMod = EnumColorOrFile.StatusColor;
  146. }
  147. else if (currentTemplateListModName == TemplateListModFileName)
  148. {
  149. CurrentTemplateListMod = EnumColorOrFile.StatusFile;
  150. }
  151. }
  152. public void EnterSelectedContent(string SelectedContentName)
  153. {
  154. NavigationParameters param = new NavigationParameters();
  155. param.Add(ParameterNames.PDFViewer, PDFViewer);
  156. if (SelectedContentName == TemplateListBaseName)
  157. {
  158. param.Add("CurrentCreateModName", CurrentCreateMod);
  159. }
  160. else if (SelectedContentName == CreateBaseName)
  161. {
  162. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  163. }
  164. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, SelectedContentName, param);
  165. BackgroundSettingsVisible = Visibility.Visible;
  166. }
  167. public void EnterDocumentContent()
  168. {
  169. NavigationParameters param = new NavigationParameters();
  170. param.Add(ParameterNames.PDFViewer, PDFViewer);
  171. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  172. backgroundRegion.RequestNavigate(BackgroundDocumentRegionName, BackgroundDocumentName, param);
  173. BackgroundDocumentVisible = Visibility.Visible;
  174. }
  175. public void OnNavigatedTo(NavigationContext navigationContext)
  176. {
  177. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  178. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  179. EnterSelectedContent(TemplateListBaseName);
  180. EnterDocumentContent();
  181. }
  182. public bool IsNavigationTarget(NavigationContext navigationContext)
  183. {
  184. return true;
  185. }
  186. public void OnNavigatedFrom(NavigationContext navigationContext)
  187. {
  188. }
  189. }
  190. }