BackgroundContentViewModel.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. using PDF_Office.CustomControl;
  18. namespace PDF_Office.ViewModels.EditTools.Background
  19. {
  20. public class BackgroundContentViewModel : BindableBase, INavigationAware
  21. {
  22. public IEventAggregator eventAggregator;
  23. public IRegionManager backgroundRegion;
  24. private CPDFViewer PDFViewer;
  25. private ViewContentViewModel viewContentViewModel;
  26. public string TemplateListBaseName = "BackgroundTemplateListBaseContent";
  27. public string CreateBaseName = "BackgroundCreateBaseContent";
  28. public string CreateModColorName = "BackgroundCreateColorContent";
  29. public string CreateModFileName = "BackgroundCreateFileContent";
  30. public string TemplateListModColorName = "BackgroundTemplateListColorContent";
  31. public string TemplateListModFileName = "BackgroundTemplateListFileContent";
  32. public string BackgroundDocumentName = "BackgroundDocumentContent";
  33. private string _backgroundSettingsRegionName;
  34. /// <summary>
  35. /// 属性设置Region
  36. /// </summary>
  37. public string BackgroundSettingsRegionName
  38. {
  39. get { return _backgroundSettingsRegionName; }
  40. set { _backgroundSettingsRegionName = value; }
  41. }
  42. private Visibility _backgroundSettingsVisible = Visibility.Collapsed;
  43. /// <summary>
  44. /// 属性设置Region可见
  45. /// </summary>
  46. public Visibility BackgroundSettingsVisible
  47. {
  48. get { return _backgroundSettingsVisible; }
  49. set { _backgroundSettingsVisible = value; }
  50. }
  51. private string _backgroundDocumentRegionName;
  52. /// <summary>
  53. /// 持有Document的Region,负责渲染和保存
  54. /// </summary>
  55. public string BackgroundDocumentRegionName
  56. {
  57. get { return _backgroundDocumentRegionName; }
  58. set { _backgroundDocumentRegionName = value; }
  59. }
  60. private Visibility _backgroundDocumentVisible = Visibility.Visible;
  61. /// <summary>
  62. /// 持有Document的Region可见
  63. /// </summary>
  64. public Visibility BackgroundDocumentVisible
  65. {
  66. get { return _backgroundDocumentVisible; }
  67. set { _backgroundDocumentVisible = value; }
  68. }
  69. private EnumColorOrFile _currentCreateMod;
  70. public EnumColorOrFile CurrentCreateMod
  71. {
  72. get { return _currentCreateMod; }
  73. set { _currentCreateMod = value; }
  74. }
  75. private EnumColorOrFile _currentTemplateListMod;
  76. public EnumColorOrFile CurrentTemplateListMod
  77. {
  78. get { return _currentTemplateListMod; }
  79. set { _currentTemplateListMod = value; }
  80. }
  81. /// <summary>
  82. /// 退出EditTool
  83. /// </summary>
  84. public DelegateCommand CloseEditToolCommand { get; set; }
  85. public DelegateCommand ConfirmEditToolCommand { get; set; }
  86. public DelegateCommand<string> EnterSelectedContentCommand { get; set; }
  87. public DelegateCommand DeleteBackgroundCommand { get; set; }
  88. public string Unicode = null;
  89. public BackgroundContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  90. {
  91. this.eventAggregator = eventAggregator;
  92. this.backgroundRegion = regionManager;
  93. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  94. BackgroundSettingsVisible = Visibility.Visible;
  95. BackgroundSettingsRegionName = Guid.NewGuid().ToString();
  96. BackgroundDocumentRegionName = Guid.NewGuid().ToString();
  97. CloseEditToolCommand = new DelegateCommand(CloseEditTool);
  98. ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool);
  99. EnterSelectedContentCommand = new DelegateCommand<string>(EnterSelectedContent);
  100. DeleteBackgroundCommand = new DelegateCommand(DeleteBackground);
  101. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode);
  102. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod, e => e.Unicode == Unicode);
  103. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Subscribe(SetCurrentTemplateListMod, e => e.Unicode == Unicode);
  104. eventAggregator.GetEvent<EditBackgroundTemplateItemEvent>().Subscribe(EditBackgroundTemplateItem, e => e.Unicode == Unicode);
  105. }
  106. public void CloseEditTool()
  107. {
  108. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusCancel });
  109. }
  110. public void ConfirmEditTool()
  111. {
  112. this.eventAggregator.GetEvent<ConfirmEditToolsBackgroundEvent>().Publish();
  113. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode=Unicode,Status= EnumCloseMode.StatusConfirm });
  114. }
  115. public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
  116. {
  117. EnumTemplateListOrCreate enumTemplateListOrCreate= enumTemplateListOrCreateunicode.Status;
  118. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  119. {
  120. EnterSelectedContent(TemplateListBaseName);
  121. }
  122. else
  123. {
  124. EnterSelectedContent(CreateBaseName);
  125. }
  126. }
  127. public void SetCurrentCreateMod(stringUnicode currentCreateModNameunicode)
  128. {
  129. string currentCreateModName = currentCreateModNameunicode.Status;
  130. if (currentCreateModName == CreateModColorName)
  131. {
  132. CurrentCreateMod = EnumColorOrFile.StatusColor;
  133. }
  134. else if (currentCreateModName == CreateModFileName)
  135. {
  136. CurrentCreateMod = EnumColorOrFile.StatusFile;
  137. }
  138. }
  139. public void EditBackgroundTemplateItem(BackgroundItemUnicode backgroundItemunicode)
  140. {
  141. BackgroundItem backgroundItem = backgroundItemunicode.Status;
  142. NavigationParameters param = new NavigationParameters();
  143. param.Add(ParameterNames.PDFViewer, PDFViewer);
  144. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  145. param.Add("BackgroundItem", backgroundItem);
  146. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, CreateBaseName, param);
  147. BackgroundSettingsVisible = Visibility.Visible;
  148. }
  149. public void SetCurrentTemplateListMod(stringUnicode currentTemplateListModNameunicode)
  150. {
  151. string currentTemplateListModName = currentTemplateListModNameunicode.Status;
  152. if (currentTemplateListModName == TemplateListModColorName)
  153. {
  154. CurrentTemplateListMod = EnumColorOrFile.StatusColor;
  155. }
  156. else if (currentTemplateListModName == TemplateListModFileName)
  157. {
  158. CurrentTemplateListMod = EnumColorOrFile.StatusFile;
  159. }
  160. }
  161. public void EnterSelectedContent(string SelectedContentName)
  162. {
  163. NavigationParameters param = new NavigationParameters();
  164. param.Add(ParameterNames.PDFViewer, PDFViewer);
  165. if (SelectedContentName == TemplateListBaseName)
  166. {
  167. param.Add("CurrentCreateModName", CurrentCreateMod);
  168. }
  169. else if (SelectedContentName == CreateBaseName)
  170. {
  171. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  172. }
  173. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, SelectedContentName, param);
  174. BackgroundSettingsVisible = Visibility.Visible;
  175. }
  176. private void DeleteBackground()
  177. {
  178. AlertsMessage alertsMessage = new AlertsMessage();
  179. alertsMessage.ShowDialog("确定要删除背景吗?", "", "取消", "删除");
  180. if (alertsMessage.result == ContentResult.Ok)
  181. {
  182. this.eventAggregator.GetEvent<DeleteBackgroundEvent>().Publish(new EnumDeleteUnicode
  183. {
  184. Unicode = Unicode,
  185. Status = EnumDelete.StatusDeleteAll
  186. });
  187. }
  188. else
  189. {
  190. this.eventAggregator.GetEvent<DeleteBackgroundEvent>().Publish(new EnumDeleteUnicode
  191. {
  192. Unicode = Unicode,
  193. Status = EnumDelete.StatusCreate
  194. });
  195. }
  196. }
  197. public void EnterDocumentContent()
  198. {
  199. NavigationParameters param = new NavigationParameters();
  200. param.Add(ParameterNames.PDFViewer, PDFViewer);
  201. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  202. backgroundRegion.RequestNavigate(BackgroundDocumentRegionName, BackgroundDocumentName, param);
  203. BackgroundDocumentVisible = Visibility.Visible;
  204. }
  205. public void OnNavigatedTo(NavigationContext navigationContext)
  206. {
  207. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  208. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  209. EnterSelectedContent(TemplateListBaseName);
  210. EnterDocumentContent();
  211. }
  212. public bool IsNavigationTarget(NavigationContext navigationContext)
  213. {
  214. return true;
  215. }
  216. public void OnNavigatedFrom(NavigationContext navigationContext)
  217. {
  218. }
  219. }
  220. }