ToolsBarContentViewModel.cs 3.6 KB

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