|
@@ -1,5 +1,6 @@
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
|
using Microsoft.Win32;
|
|
|
+using PDF_Office.CustomControl;
|
|
|
using PDF_Office.EventAggregators;
|
|
|
using PDF_Office.Views;
|
|
|
using Prism.Commands;
|
|
@@ -7,6 +8,7 @@ using Prism.Events;
|
|
|
using Prism.Ioc;
|
|
|
using Prism.Mvvm;
|
|
|
using Prism.Regions;
|
|
|
+using Prism.Services.Dialogs;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
@@ -15,6 +17,7 @@ using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
+using PDF_Office.Model;
|
|
|
|
|
|
namespace PDF_Office.ViewModels
|
|
|
{
|
|
@@ -85,11 +88,14 @@ namespace PDF_Office.ViewModels
|
|
|
|
|
|
public IContainerProvider container;
|
|
|
|
|
|
- public MainContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IContainerProvider containerProvider)
|
|
|
+ public IDialogService dialogs;
|
|
|
+
|
|
|
+ public MainContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IContainerProvider containerProvider,IDialogService dialogService)
|
|
|
{
|
|
|
toolregion = regionManager;
|
|
|
eventer = eventAggregator;
|
|
|
container = containerProvider;
|
|
|
+ dialogs = dialogService;
|
|
|
|
|
|
CloseTab = new DelegateCommand<object>(CloseTabItem);
|
|
|
|
|
@@ -117,23 +123,80 @@ namespace PDF_Office.ViewModels
|
|
|
|
|
|
public void OpenFile(string filePath)
|
|
|
{
|
|
|
+ var result = LoadFileFormPath(filePath);
|
|
|
+ if (!result)
|
|
|
+ {
|
|
|
+ IsLoading = Visibility.Collapsed;
|
|
|
+ return;
|
|
|
+ }
|
|
|
FilePath = filePath;
|
|
|
- NavigationParameters parameters = new NavigationParameters { { "MainViewModel", this } };
|
|
|
+
|
|
|
+ NavigationParameters parameters = new NavigationParameters {
|
|
|
+ { ParameterNames.MainViewModel, this },
|
|
|
+ { ParameterNames.PDFViewer,PDFViewer}
|
|
|
+ };
|
|
|
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
|
|
|
{
|
|
|
if (toolregion.Regions.ContainsRegionWithName(MainContentRegionName))
|
|
|
toolregion.RequestNavigate(MainContentRegionName, "ViewContent", parameters);
|
|
|
+ }));
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 从文件路径创建PDFViewer对象,已包含文档解密逻辑
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="path"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private bool LoadFileFormPath(string path)
|
|
|
+ {
|
|
|
+ PDFViewer = new CPDFViewer();
|
|
|
+ PDFViewer.InitDocument(path);
|
|
|
+ if (PDFViewer.Document == null)
|
|
|
+ {
|
|
|
+ //MessageBoxEx.Show(App.MainPageLoader.GetString("Main_OpenFileFailedWarning"));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (PDFViewer.Document.IsLocked)
|
|
|
+ {
|
|
|
+ DialogParameters value = new DialogParameters();
|
|
|
+ value.Add(ParameterNames.PDFDocument,PDFViewer.Document);
|
|
|
+ dialogs.ShowDialog(DialogNames.VerifyPassWordDialog,value,e=> {
|
|
|
+ if(e.Result== ButtonResult.OK)
|
|
|
+ {
|
|
|
+ if(e.Parameters.ContainsKey(ParameterNames.PassWord)&&e.Parameters.GetValue<string>(ParameterNames.PassWord) !=null)
|
|
|
+ {
|
|
|
+ PDFViewer.Tag = e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (PDFViewer.Document.IsLocked)
|
|
|
+ {
|
|
|
+ //未成功解密文档时,释放Document对象,返回
|
|
|
+ PDFViewer.Document.Release();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ PDFViewer.Load();
|
|
|
|
|
|
- }));
|
|
|
+ if (App.mainWindowViewModel != null)
|
|
|
+ {
|
|
|
+ App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
|
|
|
+ }
|
|
|
+ App.OpenedFileList.Add(path);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|
|
{
|
|
|
if (navigationContext.Parameters.Count <= 0)
|
|
|
return;
|
|
|
- var filepath = navigationContext.Parameters["filePath"];
|
|
|
+ var filepath = navigationContext.Parameters[ParameterNames.FilePath];
|
|
|
if (filepath != null)
|
|
|
{
|
|
|
OpenFile(filepath.ToString());
|