BackgroundCreateBaseContentViewModel.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using ComPDFKitViewer.PdfViewer;
  2. using DryIoc;
  3. using PDF_Office.EventAggregators;
  4. using PDF_Office.Model;
  5. using PDF_Office.Model.EditTools.Background;
  6. using PDF_Office.Views.EditTools.Background;
  7. using PDFSettings;
  8. using Prism.Commands;
  9. using Prism.Common;
  10. using Prism.Events;
  11. using Prism.Mvvm;
  12. using Prism.Regions;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. namespace PDF_Office.ViewModels.EditTools.Background
  21. {
  22. public class BackgroundCreateBaseContentViewModel : BindableBase, INavigationAware
  23. {
  24. IEventAggregator eventAggregator;
  25. IRegionManager backgroundCreateRegion;
  26. private CPDFViewer PDFViewer;
  27. public BackgroundItem BackgroundItem;
  28. public enum EnumCreateOrEdit
  29. {
  30. None,
  31. StatusCreate,
  32. StatusEdit
  33. }
  34. private EnumCreateOrEdit _createOrEdit;
  35. public EnumCreateOrEdit CreateOrEdit
  36. {
  37. get { return _createOrEdit; }
  38. set
  39. {
  40. _createOrEdit = value;
  41. if (value == EnumCreateOrEdit.StatusEdit)
  42. {
  43. EditBaseVisible = Visibility.Visible;
  44. CreateBaseVisible = Visibility.Collapsed;
  45. }
  46. else if (value == EnumCreateOrEdit.StatusCreate)
  47. {
  48. CreateBaseVisible = Visibility.Visible;
  49. EditBaseVisible = Visibility.Collapsed;
  50. }
  51. }
  52. }
  53. private string backgroundCreateRegionName;
  54. public string BackgroundCreateRegionName
  55. {
  56. get => backgroundCreateRegionName;
  57. set => SetProperty(ref backgroundCreateRegionName, value);
  58. }
  59. private string _currentCreateModName;
  60. public string CurrentCreateModName
  61. {
  62. get => _currentCreateModName;
  63. set => _currentCreateModName = value;
  64. }
  65. private System.Windows.Visibility backgroundCreateVisible;
  66. public System.Windows.Visibility BackgroundCreateVisible
  67. {
  68. get => backgroundCreateVisible;
  69. set => SetProperty(ref backgroundCreateVisible, value);
  70. }
  71. private bool isFirstEnter = true;
  72. public bool IsFirstEnter
  73. {
  74. get => isFirstEnter;
  75. set => isFirstEnter = value;
  76. }
  77. private Visibility _createBaseVisible;
  78. public Visibility CreateBaseVisible
  79. {
  80. get => _createBaseVisible;
  81. set => SetProperty(ref _createBaseVisible, value);
  82. }
  83. private Visibility _editBaseVisible;
  84. public Visibility EditBaseVisible
  85. {
  86. get => _editBaseVisible;
  87. set => SetProperty(ref _editBaseVisible, value);
  88. }
  89. public EnumColorOrFile CurrentTemplateListMod;
  90. public DelegateCommand<object> ChangeCreateModCommand { get; set; }
  91. public DelegateCommand EnterTemplateListCommand { get; set; }
  92. public DelegateCommand SaveToTemplateListCommand { get; set; }
  93. public DelegateCommand SaveToCurrentTemplateListCommand { get; set; }
  94. public string unicode = null;
  95. public string Unicode = null;
  96. public BackgroundCreateBaseContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  97. {
  98. this.eventAggregator = eventAggregator;
  99. this.backgroundCreateRegion = regionManager;
  100. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  101. BackgroundCreateRegionName = Guid.NewGuid().ToString();
  102. ChangeCreateModCommand = new DelegateCommand<object>(ChangeCreateMod);
  103. EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
  104. SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
  105. SaveToCurrentTemplateListCommand = new DelegateCommand(SaveToCurrentTemplateList);
  106. }
  107. public void SaveToTemplateList()
  108. {
  109. if (CurrentCreateModName == "BackgroundCreateColorContent")
  110. {
  111. this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(new EnumColorOrFileUnicode { Unicode = Unicode, Status = EnumColorOrFile.StatusColor });
  112. }
  113. if (CurrentCreateModName == "BackgroundCreateFileContent")
  114. {
  115. this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(new EnumColorOrFileUnicode
  116. {
  117. Unicode = Unicode,
  118. Status = EnumColorOrFile.StatusFile
  119. });
  120. }
  121. }
  122. public void SaveToCurrentTemplateList()
  123. {
  124. if (CurrentCreateModName == "BackgroundCreateColorContent")
  125. {
  126. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Publish(new EnumColorOrFileUnicode {
  127. Unicode = Unicode, Status = EnumColorOrFile.StatusColor});
  128. }
  129. if (CurrentCreateModName == "BackgroundCreateFileContent")
  130. {
  131. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Publish(new EnumColorOrFileUnicode {
  132. Unicode = Unicode, Status = EnumColorOrFile.StatusFile});
  133. }
  134. }
  135. public void EnterTemplateList()
  136. {
  137. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode {Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate});
  138. }
  139. public void EnterSelectedCreateMod(string currentCreateName)
  140. {
  141. NavigationParameters param = new NavigationParameters();
  142. param.Add(ParameterNames.PDFViewer, PDFViewer);
  143. backgroundCreateRegion.RequestNavigate(BackgroundCreateRegionName, currentCreateName, param);
  144. backgroundCreateVisible = System.Windows.Visibility.Visible;
  145. }
  146. public void EditSelectedTemplateItem(string currentCreateName)
  147. {
  148. NavigationParameters param = new NavigationParameters();
  149. param.Add(ParameterNames.PDFViewer, PDFViewer);
  150. param.Add("BackgroundItem", BackgroundItem);
  151. backgroundCreateRegion.RequestNavigate(BackgroundCreateRegionName, currentCreateName, param);
  152. backgroundCreateVisible = System.Windows.Visibility.Visible;
  153. }
  154. public void ChangeCreateMod(object e)
  155. {
  156. var args = e as Button;
  157. if (args != null)
  158. {
  159. if (CreateOrEdit == EnumCreateOrEdit.StatusCreate)
  160. {
  161. CurrentCreateModName = args.Name;
  162. EnterSelectedCreateMod(CurrentCreateModName);
  163. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode {
  164. Unicode = Unicode, Status = CurrentCreateModName});
  165. }
  166. else if (CreateOrEdit == EnumCreateOrEdit.StatusEdit)
  167. {
  168. CurrentCreateModName = args.Name;
  169. EditSelectedTemplateItem(CurrentCreateModName);
  170. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  171. {
  172. Unicode = Unicode,
  173. Status = CurrentCreateModName
  174. });
  175. }
  176. }
  177. }
  178. public bool IsNavigationTarget(NavigationContext navigationContext)
  179. {
  180. return true;
  181. }
  182. public void OnNavigatedFrom(NavigationContext navigationContext)
  183. {
  184. }
  185. public void OnNavigatedTo(NavigationContext navigationContext)
  186. {
  187. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  188. navigationContext.Parameters.TryGetValue<EnumColorOrFile>("CurrentTemplateListModName", out CurrentTemplateListMod);
  189. if (CurrentTemplateListMod == EnumColorOrFile.StatusColor)
  190. {
  191. CurrentCreateModName = "BackgroundCreateColorContent";
  192. }
  193. else
  194. {
  195. CurrentCreateModName = "BackgroundCreateFileContent";
  196. }
  197. if (navigationContext.Parameters.TryGetValue<BackgroundItem>("BackgroundItem", out BackgroundItem))
  198. {
  199. EditSelectedTemplateItem(CurrentCreateModName);
  200. CreateOrEdit = EnumCreateOrEdit.StatusEdit;
  201. }
  202. else
  203. {
  204. EnterSelectedCreateMod(CurrentCreateModName);
  205. CreateOrEdit = EnumCreateOrEdit.StatusCreate;
  206. }
  207. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  208. {
  209. Unicode = Unicode,
  210. Status = CurrentCreateModName
  211. });
  212. }
  213. }
  214. }