BackgroundContentViewModel.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 TemplateListName = "BackgroundTemplateListBaseContent";
  24. public string CreateName = "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(TemplateListName);
  111. }
  112. else
  113. {
  114. EnterSelectedContent(CreateName);
  115. }
  116. }
  117. public void SetCurrentCreateMod(string currentCreateModName)
  118. {
  119. if (currentCreateModName == CreateModColorName)
  120. {
  121. CurrentCreateMod = EnumColorOrFile.StatusColor;
  122. }
  123. else if (currentCreateModName == CreateModFileName)
  124. {
  125. CurrentCreateMod = EnumColorOrFile.StatusFile;
  126. }
  127. }
  128. public void SetCurrentTemplateListMod(string currentTemplateListModName)
  129. {
  130. if (currentTemplateListModName == TemplateListModColorName)
  131. {
  132. CurrentTemplateListMod = EnumColorOrFile.StatusColor;
  133. }
  134. else if (currentTemplateListModName == TemplateListModFileName)
  135. {
  136. CurrentTemplateListMod = EnumColorOrFile.StatusFile;
  137. }
  138. }
  139. public void EnterSelectedContent(string SelectedContentName)
  140. {
  141. NavigationParameters param = new NavigationParameters();
  142. param.Add(ParameterNames.PDFViewer, PDFViewer);
  143. if (SelectedContentName == TemplateListName)
  144. {
  145. param.Add("CurrentCreateModName", CurrentCreateMod);
  146. }
  147. else if (SelectedContentName == CreateName)
  148. {
  149. param.Add("CurrentTemplateListModName", CurrentTemplateListMod);
  150. }
  151. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, SelectedContentName, param);
  152. BackgroundSettingsVisible = Visibility.Visible;
  153. }
  154. public void EnterDocumentContent()
  155. {
  156. NavigationParameters param = new NavigationParameters();
  157. param.Add(ParameterNames.PDFViewer, PDFViewer);
  158. backgroundRegion.RequestNavigate(BackgroundDocumentRegionName, BackgroundDocumentName, param);
  159. BackgroundDocumentVisible = Visibility.Visible;
  160. }
  161. public void OnNavigatedTo(NavigationContext navigationContext)
  162. {
  163. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  164. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  165. EnterSelectedContent(TemplateListName);
  166. EnterDocumentContent();
  167. }
  168. public bool IsNavigationTarget(NavigationContext navigationContext)
  169. {
  170. return true;
  171. }
  172. public void OnNavigatedFrom(NavigationContext navigationContext)
  173. {
  174. }
  175. }
  176. }