BackgroundContentViewModel.cs 8.3 KB

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