123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Master.Model;
- using Prism.Commands;
- using System.Windows.Controls;
- using DryIoc;
- using Prism.Services.Dialogs;
- using PDF_Master.Views.PageEdit;
- using PDF_Master.Properties;
- using PDF_Master.Helper;
- using PDFReader_WPF.Helper;
- namespace PDF_Master.ViewModels.BOTA
- {
- public class BOTAContentViewModel : BindableBase, INavigationAware
- {
- public CPDFViewer pdfViewer { get; set; }
- private IRegionManager regions { get; set; }
- private IDialogService dialogs { get; set; }
- public ViewContentViewModel viewContentViewModel { get; set; }
- private Dictionary<string, string> viewNameByTabItem;
- private string botaContentRegionName;
- public string BOTAContentRegionName
- {
- get { return botaContentRegionName; }
- set
- {
- SetProperty(ref botaContentRegionName, value);
- }
- }
- private int selectedIndex;
- public int SelectedIndex
- {
- get { return selectedIndex; }
- set
- {
- SetProperty(ref selectedIndex, value);
- }
- }
- private string tip_Thumbnail;
- public string Tip_Thumbnail
- {
- get { return tip_Thumbnail; }
- set
- {
- SetProperty(ref tip_Thumbnail, value);
- }
- }
- private string tip_OutLine;
- public string Tip_OutLine
- {
- get { return tip_OutLine; }
- set
- {
- SetProperty(ref tip_OutLine, value);
- }
- }
- private string tip_BookMark;
- public string Tip_BookMark
- {
- get { return tip_BookMark; }
- set
- {
- SetProperty(ref tip_BookMark, value);
- }
- }
- private string tip_Search;
- public string Tip_Search
- {
- get { return tip_Search; }
- set
- {
- SetProperty(ref tip_Search, value);
- }
- }
- private string tip_Annote;
- public string Tip_Annote
- {
- get { return tip_Annote; }
- set
- {
- SetProperty(ref tip_Annote, value);
- }
- }
- public string CurrentBar = "";
- public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
- public BOTAContentViewModel(IRegionManager regionManager, IDialogService dialogService)
- {
- regions = regionManager;
- dialogs = dialogService;
- BOTAContentRegionName = Guid.NewGuid().ToString();
- TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectionChangedEvent);
- viewNameByTabItem = new Dictionary<string, string>();
- InitDictionartViewNameByTabItem(ref viewNameByTabItem);
- InitString();
- }
- private void TabControlSelectionChangedEvent(object e)
- {
- var args = e as SelectionChangedEventArgs;
- if (args != null && args.AddedItems.Count > 0)
- {
- if (!string.IsNullOrEmpty((args.AddedItems[0] as TabItem).Name))
- {
- TabControlDataTracking((args.AddedItems[0] as TabItem).Name);
- EnterSelectedBar((args.AddedItems[0] as TabItem).Name);
- if ((args.AddedItems[0] as TabItem).IsSelected)
- {
- viewContentViewModel.OpenBOTA = true;
- }
- }
- }
- }
- /// <summary>
- /// 侧边按钮埋点
- /// </summary>
- /// <param name="tag">按钮名字</param>
- private void TabControlDataTracking(string tag)
- {
- switch (tag)
- {
- case "TabItemOutLine":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.LeftSideBar, "LeftSideBar_Btn", "Btn_LeftSideBar_Outline");
- break;
- case "TabItemThumbnail":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.LeftSideBar, "LeftSideBar_Btn", "Btn_LeftSideBar_Thumbnail");
- break;
- case "TabItemBookMark":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.LeftSideBar, "LeftSideBar_Btn", "Btn_LeftSideBar_BookMark");
- break;
- case "TabItemAnnotation":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.LeftSideBar, "LeftSideBar_Btn", "Btn_LeftSideBar_Annotation");
- break;
- case "TabItemSearch":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.LeftSideBar, "LeftSideBar_Btn", "Btn_LeftSideBar_Search");
- break;
- }
- }
- private void InitString()
- {
- Tip_Annote = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
- Tip_OutLine = App.MainPageLoader.GetString("Outline_Title");
- Tip_BookMark = App.MainPageLoader.GetString("Bookmark_Title");
- Tip_Search = App.MainPageLoader.GetString("ViewRightMenu_Search");
- Tip_Thumbnail = App.MainPageLoader.GetString("Thumbnails_Title");
- }
- /// <summary>
- /// 初始化名称-视图字典
- /// </summary>
- private void InitDictionartViewNameByTabItem(ref Dictionary<string, string> viewNameByTabItem)
- {
- //绑定tabitem名字和对应的View控件名称
- viewNameByTabItem.Add("TabItemThumbnail", "PageEditContent");
- viewNameByTabItem.Add("TabItemOutLine", "OutLineControl");
- viewNameByTabItem.Add("TabItemBookMark", "BookmarkContent");
- viewNameByTabItem.Add("TabItemAnnotation", "AnnotationContent");
- viewNameByTabItem.Add("TabItemSearch", "SearchContent");
- viewNameByTabItem.Add("TabItemForm", "");
- viewNameByTabItem.Add("TabItemSign", "");
- }
- /// <summary>
- /// 导航至目标TabItem
- /// </summary>
- /// <param name="currentBar"></param>
- private void EnterSelectedBar(string currentBar)
- {
- //增加判空逻辑
- if (!string.IsNullOrEmpty(currentBar))
- {
- CurrentBar = currentBar;
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, pdfViewer);
- param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
- if (currentBar == "TabItemThumbnail")
- {
- param.Add(ParameterNames.BOTAThumb, true);
- }
- if (viewNameByTabItem.ContainsKey(currentBar))
- {
- regions.RequestNavigate(BOTAContentRegionName, viewNameByTabItem[currentBar], param);
- }
- //增加判空逻辑
- if (pdfViewer != null && pdfViewer.Document != null)
- {
- var info = SettingHelper.GetFileInfo(pdfViewer.Document.FilePath);
- if (info != null)
- {
- info.BOTASelectedTab = currentBar;
- info.BOTASelectedInex = SelectedIndex;
- SettingHelper.SetFileInfo(info);
- }
- }
- }
- }
- /// <summary>
- /// 根据缓存判断,如果记录需要展开BOTA 则还原上一次的展开状态
- /// </summary>
- public void OpenBOTA()
- {
- //记录上一次BOTA展开情况
- if (Settings.Default.AppProperties.InitialVIew.RememberBOTA)
- {
- //如果是加密文档 则先不展开,解密后再展开
- if (pdfViewer.Document.IsLocked)
- {
- return;
- }
- var info = SettingHelper.GetFileInfo(pdfViewer.Document.FilePath);
- //避免新文档因打开文件没有selectedTab信息导致崩溃
- if (info != null && !string.IsNullOrEmpty(info.BOTASelectedTab))
- {
- SelectedIndex = info.BOTASelectedInex;
- EnterSelectedBar(info.BOTASelectedTab);
- viewContentViewModel.OpenBOTA = true;
- }
- }
- }
- #region Navigate
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- var contentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
- if (contentViewModel != null)
- {
- viewContentViewModel = contentViewModel;
- contentViewModel.botaViewModel = this;
- }
- var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
- if (pdfview != null)
- {
- pdfViewer = pdfview;
- }
- //大纲和文档同时打开
- if (Settings.Default.AppProperties.InitialVIew.ShowOutLine && pdfViewer.Document.GetOutlineList().Count > 0)
- {
- SelectedIndex = 2;
- EnterSelectedBar("TabItemOutLine");
- viewContentViewModel.OpenBOTA = true;
- }
- //确认是否要展开BOTA
- OpenBOTA();
- }
- #endregion Navigate
- }
- }
|