RedactionContentViewModel.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using ComPDFKitViewer.AnnotEvent;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Office.CustomControl;
  4. using PDF_Office.EventAggregators;
  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.Windows;
  15. using System.Windows.Media;
  16. namespace PDF_Office.ViewModels.EditTools.Redaction
  17. {
  18. public class RedactionContentViewModel : BindableBase,INavigationAware
  19. {
  20. public IEventAggregator eventAggregator;
  21. public IRegionManager redactionRegion;
  22. public IDialogService dialogs;
  23. private CPDFViewer PDFViewer;
  24. private ViewContentViewModel viewContentViewModel;
  25. public string RedactionDocumentRegionName { get; set; }
  26. public string RedactionBottomBarRegionName { get; set; }
  27. public string RedactionDocumentName = "RedactionDocumentContent";
  28. public string Unicode = null;
  29. public DelegateCommand CloseEditToolCommand { get; set; }
  30. public DelegateCommand ApplyCommmand { get; set; }
  31. public DelegateCommand RemoveCommand { get; set; }
  32. public DelegateCommand PageRedactionCommand { get; set; }
  33. public RedactionContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator,IDialogService dialogService)
  34. {
  35. this.redactionRegion = regionManager;
  36. this.eventAggregator = eventAggregator;
  37. this.dialogs = dialogService;
  38. RedactionDocumentRegionName = Guid.NewGuid().ToString();
  39. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  40. CloseEditToolCommand = new DelegateCommand(CloseEditTool);
  41. ApplyCommmand = new DelegateCommand(apply);
  42. RemoveCommand = new DelegateCommand(remove);
  43. PageRedactionCommand = new DelegateCommand(pageMark);
  44. }
  45. /// <summary>
  46. /// 应用
  47. /// </summary>
  48. private void apply()
  49. {
  50. AlertsMessage alertsMessage = new AlertsMessage();
  51. alertsMessage.ShowDialog("Apply Redactions", "Use blank blocks to remove selected sensitive content."+
  52. "This action will permanently delete the marked ciphertext information from this document and you will not be able to retrieve the marked ciphertext information.","Cancel","Apply & Save As");
  53. if(alertsMessage.result== ContentResult.Ok)
  54. {
  55. viewContentViewModel.saveAsFile(true);
  56. }
  57. }
  58. /// <summary>
  59. /// 擦除
  60. /// </summary>
  61. private void remove()
  62. {
  63. }
  64. private void pageMark()
  65. {
  66. dialogs.ShowDialog(DialogNames.PageMarkDialog);
  67. }
  68. public void CloseEditTool()
  69. {
  70. PDFViewer.SetMouseMode(MouseModes.Default);
  71. redactionRegion.Regions[RegionNames.ViwerRegionName].Remove(PDFViewer);
  72. redactionRegion.Regions[RedactionDocumentRegionName].Remove(PDFViewer);
  73. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = this.Unicode, Status = EnumCloseMode.StatusCancel });
  74. }
  75. #region Navigation
  76. public bool IsNavigationTarget(NavigationContext navigationContext)
  77. {
  78. return true;
  79. }
  80. public void OnNavigatedFrom(NavigationContext navigationContext)
  81. {
  82. }
  83. public void OnNavigatedTo(NavigationContext navigationContext)
  84. {
  85. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  86. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  87. if (!redactionRegion.Regions[RedactionDocumentRegionName].Views.Contains(PDFViewer))
  88. {
  89. RedactionAnnotArgs redactionArgs = new RedactionAnnotArgs();
  90. AnnotHandlerEventArgs annotArgs = null;
  91. redactionArgs.LineColor = ((SolidColorBrush)Brushes.Black).Color;
  92. redactionArgs.BgColor = ((SolidColorBrush)Brushes.Black).Color;
  93. redactionArgs.FontColor = ((SolidColorBrush)Brushes.Red).Color;
  94. //redactionArgs.LineColor = Settings.Default.RedactionsSettings.LineColor;
  95. //redactionArgs.BgColor = Settings.Default.RedactionsSettings.BgColor;
  96. //redactionArgs.FontColor = Settings.Default.RedactionsSettings.FontColor;
  97. //redactionArgs.Align = Settings.Default.RedactionsSettings.Align;
  98. //redactionArgs.FontSize = Settings.Default.RedactionsSettings.FontSize;
  99. //redactionArgs.Content = Settings.Default.RedactionsSettings.Content;
  100. //if (!Settings.Default.RedactionsSettings.isUseText)
  101. //{
  102. // redactionArgs.Content = "";
  103. //}
  104. annotArgs = redactionArgs;
  105. if (annotArgs != null)
  106. {
  107. //annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  108. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  109. PDFViewer.SetToolParam(annotArgs);
  110. }
  111. redactionRegion.AddToRegion(RedactionDocumentRegionName, PDFViewer);
  112. }
  113. }
  114. #endregion
  115. }
  116. }