BackgroundContentViewModel.cs 11 KB

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