BackgroundCreateBaseContentViewModel.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. using ComPDFKitViewer.PdfViewer;
  2. using DryIoc;
  3. using PDF_Master.EventAggregators;
  4. using PDF_Master.Model;
  5. using PDF_Master.Model.EditTools.Background;
  6. using PDF_Master.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_Master.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. SelectContentVisibility = Visibility.Collapsed;
  45. CreateBaseVisible = Visibility.Collapsed;
  46. }
  47. else if (value == EnumCreateOrEdit.StatusCreate)
  48. {
  49. CreateBaseVisible = Visibility.Visible;
  50. SelectContentVisibility= Visibility.Visible;
  51. EditBaseVisible = Visibility.Collapsed;
  52. }
  53. }
  54. }
  55. private string backgroundCreateRegionName;
  56. public string BackgroundCreateRegionName
  57. {
  58. get => backgroundCreateRegionName;
  59. set => SetProperty(ref backgroundCreateRegionName, value);
  60. }
  61. private string _currentCreateModName;
  62. public string CurrentCreateModName
  63. {
  64. get => _currentCreateModName;
  65. set => _currentCreateModName = value;
  66. }
  67. private System.Windows.Visibility backgroundCreateVisible;
  68. public System.Windows.Visibility BackgroundCreateVisible
  69. {
  70. get => backgroundCreateVisible;
  71. set => SetProperty(ref backgroundCreateVisible, value);
  72. }
  73. private bool isFirstEnter = true;
  74. public bool IsFirstEnter
  75. {
  76. get => isFirstEnter;
  77. set => isFirstEnter = value;
  78. }
  79. private Visibility _createBaseVisible;
  80. public Visibility CreateBaseVisible
  81. {
  82. get => _createBaseVisible;
  83. set => SetProperty(ref _createBaseVisible, value);
  84. }
  85. private Visibility _editBaseVisible;
  86. public Visibility EditBaseVisible
  87. {
  88. get => _editBaseVisible;
  89. set => SetProperty(ref _editBaseVisible, value);
  90. }
  91. private Visibility _selectContentVisibility;
  92. public Visibility SelectContentVisibility
  93. {
  94. get => _selectContentVisibility;
  95. set => SetProperty(ref _selectContentVisibility, value);
  96. }
  97. public EnumColorOrFile CurrentTemplateListMod;
  98. public DelegateCommand<object> ChangeCreateModCommand { get; set; }
  99. public DelegateCommand EnterTemplateListCommand { get; set; }
  100. public DelegateCommand SaveToTemplateListCommand { get; set; }
  101. public DelegateCommand SaveToCurrentTemplateListCommand { get; set; }
  102. public string unicode = null;
  103. public string Unicode = null;
  104. public BackgroundCreateBaseContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  105. {
  106. this.eventAggregator = eventAggregator;
  107. this.backgroundCreateRegion = regionManager;
  108. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  109. BackgroundCreateRegionName = Guid.NewGuid().ToString();
  110. ChangeCreateModCommand = new DelegateCommand<object>(ChangeCreateMod);
  111. EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
  112. SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
  113. SaveToCurrentTemplateListCommand = new DelegateCommand(SaveToCurrentTemplateList);
  114. }
  115. public void SaveToTemplateList()
  116. {
  117. if (CurrentCreateModName == "BackgroundCreateColorContent")
  118. {
  119. this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(new EnumColorOrFileUnicode { Unicode = Unicode, Status = EnumColorOrFile.StatusColor });
  120. }
  121. if (CurrentCreateModName == "BackgroundCreateFileContent")
  122. {
  123. this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(new EnumColorOrFileUnicode
  124. {
  125. Unicode = Unicode,
  126. Status = EnumColorOrFile.StatusFile
  127. });
  128. }
  129. }
  130. public void SaveToCurrentTemplateList()
  131. {
  132. if (CurrentCreateModName == "BackgroundCreateColorContent")
  133. {
  134. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Publish(new EnumColorOrFileUnicode {
  135. Unicode = Unicode, Status = EnumColorOrFile.StatusColor});
  136. }
  137. if (CurrentCreateModName == "BackgroundCreateFileContent")
  138. {
  139. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Publish(new EnumColorOrFileUnicode {
  140. Unicode = Unicode, Status = EnumColorOrFile.StatusFile});
  141. }
  142. }
  143. public void EnterTemplateList()
  144. {
  145. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode {Unicode = Unicode, Status = EnumTemplateListOrCreate.StatusTemplate});
  146. }
  147. public void EnterSelectedCreateMod(string currentCreateName)
  148. {
  149. NavigationParameters param = new NavigationParameters();
  150. param.Add(ParameterNames.PDFViewer, PDFViewer);
  151. backgroundCreateRegion.RequestNavigate(BackgroundCreateRegionName, currentCreateName, param);
  152. backgroundCreateVisible = System.Windows.Visibility.Visible;
  153. }
  154. public void EditSelectedTemplateItem(string currentCreateName)
  155. {
  156. NavigationParameters param = new NavigationParameters();
  157. param.Add(ParameterNames.PDFViewer, PDFViewer);
  158. param.Add("BackgroundItem", BackgroundItem);
  159. backgroundCreateRegion.RequestNavigate(BackgroundCreateRegionName, currentCreateName, param);
  160. backgroundCreateVisible = System.Windows.Visibility.Visible;
  161. }
  162. public void ChangeCreateMod(object e)
  163. {
  164. var args = e as Button;
  165. if (args != null)
  166. {
  167. if (CreateOrEdit == EnumCreateOrEdit.StatusCreate)
  168. {
  169. CurrentCreateModName = args.Name;
  170. EnterSelectedCreateMod(CurrentCreateModName);
  171. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode {
  172. Unicode = Unicode, Status = CurrentCreateModName});
  173. }
  174. else if (CreateOrEdit == EnumCreateOrEdit.StatusEdit)
  175. {
  176. CurrentCreateModName = args.Name;
  177. EditSelectedTemplateItem(CurrentCreateModName);
  178. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  179. {
  180. Unicode = Unicode,
  181. Status = CurrentCreateModName
  182. });
  183. }
  184. }
  185. }
  186. public bool IsNavigationTarget(NavigationContext navigationContext)
  187. {
  188. return true;
  189. }
  190. public void OnNavigatedFrom(NavigationContext navigationContext)
  191. {
  192. }
  193. public void OnNavigatedTo(NavigationContext navigationContext)
  194. {
  195. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  196. navigationContext.Parameters.TryGetValue<EnumColorOrFile>("CurrentTemplateListModName", out CurrentTemplateListMod);
  197. if (CurrentTemplateListMod == EnumColorOrFile.StatusColor)
  198. {
  199. CurrentCreateModName = "BackgroundCreateColorContent";
  200. }
  201. else
  202. {
  203. CurrentCreateModName = "BackgroundCreateFileContent";
  204. }
  205. if (navigationContext.Parameters.TryGetValue<BackgroundItem>("BackgroundItem", out BackgroundItem))
  206. {
  207. EditSelectedTemplateItem(CurrentCreateModName);
  208. CreateOrEdit = EnumCreateOrEdit.StatusEdit;
  209. }
  210. else
  211. {
  212. EnterSelectedCreateMod(CurrentCreateModName);
  213. CreateOrEdit = EnumCreateOrEdit.StatusCreate;
  214. }
  215. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(new stringUnicode
  216. {
  217. Unicode = Unicode,
  218. Status = CurrentCreateModName
  219. });
  220. }
  221. }
  222. }