BackgroundContentViewModel.cs 7.7 KB

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