ToolsBarContentViewModel.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Office.CustomControl;
  3. using PDF_Office.EventAggregators;
  4. using PDF_Office.Helper;
  5. using PDF_Office.Model;
  6. using Prism.Commands;
  7. using Prism.Events;
  8. using Prism.Mvvm;
  9. using Prism.Regions;
  10. using Prism.Services.Dialogs;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Security.Cryptography.X509Certificates;
  15. using System.Windows;
  16. using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  17. namespace PDF_Office.ViewModels.Tools
  18. {
  19. public class ToolsBarContentViewModel : BindableBase, INavigationAware
  20. {
  21. private CPDFViewer PDFViewer;
  22. private ViewContentViewModel viewContentViewModel;
  23. public IDialogService dialogs;
  24. public IEventAggregator eventAggregator;
  25. public string unicode = null;
  26. /// <summary>
  27. /// 是否是第一次加载
  28. /// </summary>
  29. private bool isFirstLoad = true;
  30. public DelegateCommand CompressCommand { get; set; }
  31. public DelegateCommand MergeCommand { get; set; }
  32. public DelegateCommand SetPasswordCommand { get; set; }
  33. public DelegateCommand CancelPasswordCommand { get; set; }
  34. public DelegateCommand<object> SetEditToolsCommand { get; set; }
  35. public DelegateCommand SetWatermarkCommand { get; set; }
  36. public ToolsBarContentViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
  37. {
  38. dialogs = dialogService;
  39. this.eventAggregator = eventAggregator;
  40. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  41. CompressCommand = new DelegateCommand(OpenCompressDialog);
  42. MergeCommand = new DelegateCommand(MergeDialog);
  43. SetPasswordCommand = new DelegateCommand(OpenSetPasswordDialog);
  44. CancelPasswordCommand = new DelegateCommand(OpenCancelPasswordDialog);
  45. SetEditToolsCommand = new DelegateCommand<object>(SetEditTools);
  46. }
  47. private void SetEditTools(object e)
  48. {
  49. var args = e as System.Windows.Controls.Button;
  50. if (args != null)
  51. {
  52. this.eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Publish(new StringWithUnicode() { Unicode = unicode, EditToolsContentName = args.Name });
  53. }
  54. }
  55. private void OpenCompressDialog()
  56. {
  57. DialogParameters value = new DialogParameters();
  58. value.Add(ParameterNames.PDFViewer, PDFViewer);
  59. dialogs.ShowDialog(DialogNames.CompressDialog, value, e => { });
  60. }
  61. private void MergeDialog()
  62. {
  63. DialogParameters value = new DialogParameters();
  64. value.Add(ParameterNames.PDFViewer, PDFViewer);
  65. dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
  66. }
  67. private void OpenSetPasswordDialog()
  68. {
  69. if (SecurityHelper.VerifyPassword(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs))
  70. {
  71. DialogParameters value = new DialogParameters();
  72. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  73. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e => { });
  74. }
  75. }
  76. private void OpenCancelPasswordDialog()
  77. {
  78. if (!PDFViewer.Document.IsEncrypted)
  79. {
  80. MessageBoxEx.Show("No security settings available ");
  81. }
  82. else
  83. {
  84. if (SecurityHelper.VerifyPassword(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs))
  85. {
  86. DialogParameters value = new DialogParameters();
  87. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  88. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { });
  89. }
  90. }
  91. }
  92. public bool IsNavigationTarget(NavigationContext navigationContext)
  93. {
  94. return true;
  95. }
  96. public void OnNavigatedFrom(NavigationContext navigationContext)
  97. {
  98. }
  99. public void OnNavigatedTo(NavigationContext navigationContext)
  100. {
  101. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  102. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  103. if (PDFViewer != null)
  104. {
  105. isFirstLoad = false;
  106. }
  107. }
  108. }
  109. }