using ComPDFKitViewer.PdfViewer; using PDF_Office.CustomControl; using PDF_Office.EventAggregators; using PDF_Office.Helper; using PDF_Office.Model; using Prism.Commands; using Prism.Events; using Prism.Mvvm; using Prism.Regions; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Windows; using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel; namespace PDF_Office.ViewModels.Tools { public class ToolsBarContentViewModel : BindableBase, INavigationAware { private CPDFViewer PDFViewer; private ViewContentViewModel viewContentViewModel; public IDialogService dialogs; public IEventAggregator eventAggregator; public string unicode = null; /// /// 是否是第一次加载 /// private bool isFirstLoad = true; public DelegateCommand CompressCommand { get; set; } public DelegateCommand MergeCommand { get; set; } public DelegateCommand SetPasswordCommand { get; set; } public DelegateCommand CancelPasswordCommand { get; set; } public DelegateCommand SetEditToolsCommand { get; set; } public DelegateCommand SetWatermarkCommand { get; set; } public ToolsBarContentViewModel(IDialogService dialogService, IEventAggregator eventAggregator) { dialogs = dialogService; this.eventAggregator = eventAggregator; unicode = App.mainWindowViewModel.SelectedItem.Unicode; CompressCommand = new DelegateCommand(OpenCompressDialog); MergeCommand = new DelegateCommand(MergeDialog); SetPasswordCommand = new DelegateCommand(OpenSetPasswordDialog); CancelPasswordCommand = new DelegateCommand(OpenCancelPasswordDialog); SetEditToolsCommand = new DelegateCommand(SetEditTools); } private void SetEditTools(object e) { var args = e as System.Windows.Controls.Button; if (args != null) { this.eventAggregator.GetEvent().Publish(new StringWithUnicode() { Unicode = unicode, EditToolsContentName = args.Name }); } } private void OpenCompressDialog() { DialogParameters value = new DialogParameters(); value.Add(ParameterNames.PDFViewer, PDFViewer); dialogs.ShowDialog(DialogNames.CompressDialog, value, e => { }); } private void MergeDialog() { DialogParameters value = new DialogParameters(); value.Add(ParameterNames.PDFViewer, PDFViewer); dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { }); } private void OpenSetPasswordDialog() { if (SecurityHelper.VerifyPassword(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs)) { DialogParameters value = new DialogParameters(); value.Add(ParameterNames.PDFDocument, PDFViewer.Document); dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e => { }); } } private void OpenCancelPasswordDialog() { if (!PDFViewer.Document.IsEncrypted) { MessageBoxEx.Show("No security settings available "); } else { if (SecurityHelper.VerifyPassword(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs)) { DialogParameters value = new DialogParameters(); value.Add(ParameterNames.PDFDocument, PDFViewer.Document); dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { }); } } } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.ViewContentViewModel, out viewContentViewModel); navigationContext.Parameters.TryGetValue(ParameterNames.PDFViewer, out PDFViewer); if (PDFViewer != null) { isFirstLoad = false; } } } }