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; namespace PDF_Master.ViewModels.BOTA { public class BOTAContentViewModel : BindableBase, INavigationAware { private CPDFViewer pdfViewer { get; set; } private IRegionManager regions { get; set; } private IDialogService dialogs { get; set; } public ViewContentViewModel viewContentViewModel { get; set; } private Dictionary 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); } } public string CurrentBar = ""; public DelegateCommand TabControlSelectionChangedCommand { get; set; } public BOTAContentViewModel(IRegionManager regionManager, IDialogService dialogService) { regions = regionManager; dialogs = dialogService; BOTAContentRegionName = Guid.NewGuid().ToString(); TabControlSelectionChangedCommand = new DelegateCommand(TabControlSelectionChangedEvent); viewNameByTabItem = new Dictionary(); InitDictionartViewNameByTabItem(ref viewNameByTabItem); } 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)) { EnterSelectedBar((args.AddedItems[0] as TabItem).Name); viewContentViewModel.OpenBOTA = true; } } } /// /// 初始化名称-视图字典 /// private void InitDictionartViewNameByTabItem(ref Dictionary 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", ""); } /// /// 导航至目标TabItem /// /// private void EnterSelectedBar(string 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); } regions.RequestNavigate(BOTAContentRegionName, viewNameByTabItem[currentBar], param); var info = SettingHelper.GetFileInfo(pdfViewer.Document.FilePath); if (info != null) { info.BOTASelectedTab = currentBar; info.BOTASelectedInex = SelectedIndex; SettingHelper.SetFileInfo(info); } } #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; } 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展开情况 if(Settings.Default.AppProperties.InitialVIew.RememberBOTA) { var info = SettingHelper.GetFileInfo(pdfview.Document.FilePath); SelectedIndex = info.BOTASelectedInex; EnterSelectedBar(info.BOTASelectedTab); viewContentViewModel.OpenBOTA = true; } } #endregion Navigate } }