ToolsBarContentViewModel.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 MergeCommand { get; set; }
  28. public DelegateCommand SetPasswordCommand { get; set; }
  29. public DelegateCommand CancelPasswordCommand { get; set; }
  30. public DelegateCommand<object> SetEditToolsCommand { get; set; }
  31. public DelegateCommand SetWatermarkCommand { get; set; }
  32. public ToolsBarContentViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
  33. {
  34. dialogs= dialogService;
  35. this.eventAggregator= eventAggregator;
  36. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  37. CompressCommand = new DelegateCommand(OpenCompressDialog);
  38. MergeCommand = new DelegateCommand(MergeDialog);
  39. SetPasswordCommand = new DelegateCommand(OpenSetPasswordDialog);
  40. CancelPasswordCommand = new DelegateCommand(OpenCancelPasswordDialog);
  41. SetEditToolsCommand = new DelegateCommand<object>(SetEditTools);
  42. }
  43. private void SetEditTools(object e)
  44. {
  45. var args = e as System.Windows.Controls.Button;
  46. if (args != null)
  47. {
  48. this.eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Publish(new StringWithUnicode() { Unicode=unicode,EditToolsContentName=args.Name}) ;
  49. }
  50. }
  51. private void OpenCompressDialog()
  52. {
  53. DialogParameters value = new DialogParameters();
  54. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  55. dialogs.ShowDialog(DialogNames.CompressDialog, value, e => { });
  56. }
  57. private void MergeDialog()
  58. {
  59. dialogs.ShowDialog(DialogNames.MergeDialog, null, e => { });
  60. }
  61. private void OpenSetPasswordDialog()
  62. {
  63. DialogParameters value = new DialogParameters();
  64. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  65. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e => { });
  66. }
  67. private void OpenCancelPasswordDialog()
  68. {
  69. DialogParameters value = new DialogParameters();
  70. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  71. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e => { });
  72. }
  73. public bool IsNavigationTarget(NavigationContext navigationContext)
  74. {
  75. return true;
  76. }
  77. public void OnNavigatedFrom(NavigationContext navigationContext)
  78. {
  79. }
  80. public void OnNavigatedTo(NavigationContext navigationContext)
  81. {
  82. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  83. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  84. if (PDFViewer != null)
  85. {
  86. isFirstLoad = false;
  87. }
  88. }
  89. }
  90. }