BackgroundContentViewModel.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 string Unicode = null;
  87. public BackgroundContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  88. {
  89. this.eventAggregator = eventAggregator;
  90. this.backgroundRegion = regionManager;
  91. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  92. BackgroundSettingsVisible = Visibility.Visible;
  93. BackgroundSettingsRegionName = Guid.NewGuid().ToString();
  94. BackgroundDocumentRegionName = Guid.NewGuid().ToString();
  95. CloseEditToolCommand = new DelegateCommand(CloseEditTool);
  96. ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool);
  97. EnterSelectedContentCommand = new DelegateCommand<string>(EnterSelectedContent);
  98. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate, e => e.Unicode == Unicode);
  99. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod, e => e.Unicode == Unicode);
  100. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Subscribe(SetCurrentTemplateListMod, e => e.Unicode == Unicode);
  101. eventAggregator.GetEvent<EditBackgroundTemplateItemEvent>().Subscribe(EditBackgroundTemplateItem, e => e.Unicode == Unicode);
  102. }
  103. public void CloseEditTool()
  104. {
  105. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = Unicode, Status = EnumCloseMode.StatusCancel });
  106. }
  107. public void ConfirmEditTool()
  108. {
  109. this.eventAggregator.GetEvent<ConfirmEditToolsBackgroundEvent>().Publish();
  110. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode=Unicode,Status= EnumCloseMode.StatusConfirm });
  111. }
  112. public void EnterTemplateListOrCreate(EnumTemplateListOrCreateUnicode enumTemplateListOrCreateunicode)
  113. {
  114. EnumTemplateListOrCreate enumTemplateListOrCreate= enumTemplateListOrCreateunicode.Status;
  115. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  116. {
  117. EnterSelectedContent(TemplateListBaseName);
  118. }
  119. else
  120. {
  121. EnterSelectedContent(CreateBaseName);
  122. }
  123. }
  124. public void SetCurrentCreateMod(stringUnicode currentCreateModNameunicode)
  125. {
  126. string currentCreateModName = currentCreateModNameunicode.Status;
  127. if (currentCreateModName == CreateModColorName)
  128. {
  129. CurrentCreateMod = EnumColorOrFile.StatusColor;
  130. }
  131. else if (currentCreateModName == CreateModFileName)
  132. {
  133. CurrentCreateMod = EnumColorOrFile.StatusFile;
  134. }
  135. }
  136. public void EditBackgroundTemplateItem(BackgroundItemUnicode backgroundItemunicode)
  137. {
  138. BackgroundItem backgroundItem = backgroundItemunicode.Status;
  139. NavigationParameters param = new NavigationParameters();
  140. param.Add(ParameterNames.PDFViewer, PDFViewer);
  141. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  142. param.Add("BackgroundItem", backgroundItem);
  143. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, CreateBaseName, param);
  144. BackgroundSettingsVisible = Visibility.Visible;
  145. }
  146. public void SetCurrentTemplateListMod(stringUnicode currentTemplateListModNameunicode)
  147. {
  148. string currentTemplateListModName = currentTemplateListModNameunicode.Status;
  149. if (currentTemplateListModName == TemplateListModColorName)
  150. {
  151. CurrentTemplateListMod = EnumColorOrFile.StatusColor;
  152. }
  153. else if (currentTemplateListModName == TemplateListModFileName)
  154. {
  155. CurrentTemplateListMod = EnumColorOrFile.StatusFile;
  156. }
  157. }
  158. public void EnterSelectedContent(string SelectedContentName)
  159. {
  160. NavigationParameters param = new NavigationParameters();
  161. param.Add(ParameterNames.PDFViewer, PDFViewer);
  162. if (SelectedContentName == TemplateListBaseName)
  163. {
  164. param.Add("CurrentCreateModName", CurrentCreateMod);
  165. }
  166. else if (SelectedContentName == CreateBaseName)
  167. {
  168. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  169. }
  170. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, SelectedContentName, param);
  171. BackgroundSettingsVisible = Visibility.Visible;
  172. }
  173. public void EnterDocumentContent()
  174. {
  175. NavigationParameters param = new NavigationParameters();
  176. param.Add(ParameterNames.PDFViewer, PDFViewer);
  177. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  178. backgroundRegion.RequestNavigate(BackgroundDocumentRegionName, BackgroundDocumentName, param);
  179. BackgroundDocumentVisible = Visibility.Visible;
  180. }
  181. public void OnNavigatedTo(NavigationContext navigationContext)
  182. {
  183. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  184. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  185. EnterSelectedContent(TemplateListBaseName);
  186. EnterDocumentContent();
  187. }
  188. public bool IsNavigationTarget(NavigationContext navigationContext)
  189. {
  190. return true;
  191. }
  192. public void OnNavigatedFrom(NavigationContext navigationContext)
  193. {
  194. }
  195. }
  196. }