BOTAContentViewModel.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using Prism.Mvvm;
  2. using Prism.Regions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using ComPDFKitViewer.PdfViewer;
  9. using PDF_Master.Model;
  10. using Prism.Commands;
  11. using System.Windows.Controls;
  12. using DryIoc;
  13. using Prism.Services.Dialogs;
  14. using PDF_Master.Views.PageEdit;
  15. using PDF_Master.Properties;
  16. using PDF_Master.Helper;
  17. namespace PDF_Master.ViewModels.BOTA
  18. {
  19. public class BOTAContentViewModel : BindableBase, INavigationAware
  20. {
  21. private CPDFViewer pdfViewer { get; set; }
  22. private IRegionManager regions { get; set; }
  23. private IDialogService dialogs { get; set; }
  24. public ViewContentViewModel viewContentViewModel { get; set; }
  25. private Dictionary<string, string> viewNameByTabItem;
  26. private string botaContentRegionName;
  27. public string BOTAContentRegionName
  28. {
  29. get { return botaContentRegionName; }
  30. set
  31. {
  32. SetProperty(ref botaContentRegionName, value);
  33. }
  34. }
  35. private int selectedIndex;
  36. public int SelectedIndex
  37. {
  38. get { return selectedIndex; }
  39. set
  40. {
  41. SetProperty(ref selectedIndex, value);
  42. }
  43. }
  44. public string CurrentBar = "";
  45. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  46. public BOTAContentViewModel(IRegionManager regionManager, IDialogService dialogService)
  47. {
  48. regions = regionManager;
  49. dialogs = dialogService;
  50. BOTAContentRegionName = Guid.NewGuid().ToString();
  51. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectionChangedEvent);
  52. viewNameByTabItem = new Dictionary<string, string>();
  53. InitDictionartViewNameByTabItem(ref viewNameByTabItem);
  54. }
  55. private void TabControlSelectionChangedEvent(object e)
  56. {
  57. var args = e as SelectionChangedEventArgs;
  58. if (args != null&&args.AddedItems.Count>0)
  59. {
  60. if (!string.IsNullOrEmpty((args.AddedItems[0] as TabItem).Name))
  61. {
  62. EnterSelectedBar((args.AddedItems[0] as TabItem).Name);
  63. viewContentViewModel.OpenBOTA = true;
  64. }
  65. }
  66. }
  67. /// <summary>
  68. /// 初始化名称-视图字典
  69. /// </summary>
  70. private void InitDictionartViewNameByTabItem(ref Dictionary<string, string> viewNameByTabItem)
  71. {
  72. //绑定tabitem名字和对应的View控件名称
  73. viewNameByTabItem.Add("TabItemThumbnail", "PageEditContent");
  74. viewNameByTabItem.Add("TabItemOutLine", "OutLineControl");
  75. viewNameByTabItem.Add("TabItemBookMark", "BookmarkContent");
  76. viewNameByTabItem.Add("TabItemAnnotation", "AnnotationContent");
  77. viewNameByTabItem.Add("TabItemSearch", "SearchContent");
  78. viewNameByTabItem.Add("TabItemForm", "");
  79. viewNameByTabItem.Add("TabItemSign", "");
  80. }
  81. /// <summary>
  82. /// 导航至目标TabItem
  83. /// </summary>
  84. /// <param name="currentBar"></param>
  85. private void EnterSelectedBar(string currentBar)
  86. {
  87. CurrentBar = currentBar;
  88. NavigationParameters param = new NavigationParameters();
  89. param.Add(ParameterNames.PDFViewer, pdfViewer);
  90. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  91. if (currentBar == "TabItemThumbnail")
  92. {
  93. param.Add(ParameterNames.BOTAThumb, true);
  94. }
  95. regions.RequestNavigate(BOTAContentRegionName, viewNameByTabItem[currentBar], param);
  96. var info = SettingHelper.GetFileInfo(pdfViewer.Document.FilePath);
  97. if (info != null)
  98. {
  99. info.BOTASelectedTab = currentBar;
  100. info.BOTASelectedInex = SelectedIndex;
  101. SettingHelper.SetFileInfo(info);
  102. }
  103. }
  104. #region Navigate
  105. public bool IsNavigationTarget(NavigationContext navigationContext)
  106. {
  107. return true;
  108. }
  109. public void OnNavigatedFrom(NavigationContext navigationContext)
  110. {
  111. }
  112. public void OnNavigatedTo(NavigationContext navigationContext)
  113. {
  114. var contentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
  115. if (contentViewModel != null)
  116. {
  117. viewContentViewModel = contentViewModel;
  118. }
  119. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  120. if (pdfview != null)
  121. {
  122. pdfViewer = pdfview;
  123. }
  124. //大纲和文档同时打开
  125. if (Settings.Default.AppProperties.InitialVIew.ShowOutLine && pdfViewer.Document.GetOutlineList().Count > 0)
  126. {
  127. SelectedIndex = 2;
  128. EnterSelectedBar("TabItemOutLine");
  129. viewContentViewModel.OpenBOTA = true;
  130. }
  131. //记录上一次BOTA展开情况
  132. if(Settings.Default.AppProperties.InitialVIew.RememberBOTA)
  133. {
  134. var info = SettingHelper.GetFileInfo(pdfview.Document.FilePath);
  135. SelectedIndex = info.BOTASelectedInex;
  136. EnterSelectedBar(info.BOTASelectedTab);
  137. viewContentViewModel.OpenBOTA = true;
  138. }
  139. }
  140. #endregion Navigate
  141. }
  142. }