SplitDialogViewModel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Master.CustomControl;
  3. using PDF_Master.Helper;
  4. using PDF_Master.Model;
  5. using PDF_Master.Model.HomePageToolsDialogs;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Services.Dialogs;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
  15. {
  16. public class SplitDialogViewModel : BindableBase, IDialogAware
  17. {
  18. public string Title => "";
  19. private CPDFViewer pdfViewer;
  20. private int listSelectedIndex;
  21. private double pageCount;
  22. //页面总数
  23. public double PageCount
  24. {
  25. get { return pageCount; }
  26. set
  27. {
  28. SetProperty(ref pageCount, value);
  29. }
  30. }
  31. private string customPageText;
  32. /// <summary>
  33. /// 自定义的输入内容
  34. /// </summary>
  35. public string CustomPageText
  36. {
  37. get { return customPageText; }
  38. set
  39. {
  40. SetProperty(ref customPageText, value);
  41. }
  42. }
  43. private HomePageSplitDialogModel model;
  44. public HomePageSplitDialogModel Model
  45. {
  46. get { return model; }
  47. set
  48. {
  49. SetProperty(ref model, value);
  50. }
  51. }
  52. public event Action<IDialogResult> RequestClose;
  53. public DelegateCommand CancelCommand { get; set; }
  54. public DelegateCommand SplitCommnad { get; set; }
  55. public SplitDialogViewModel()
  56. {
  57. CancelCommand = new DelegateCommand(cancel);
  58. SplitCommnad = new DelegateCommand(split);
  59. Model = new HomePageSplitDialogModel();
  60. }
  61. private void cancel()
  62. {
  63. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  64. }
  65. private void split()
  66. {
  67. List<int> pages = new List<int>();
  68. Model.PageRange = customPageText;
  69. DialogParameters valuePairs = new DialogParameters();
  70. valuePairs.Add(ParameterNames.DataModel, Model);
  71. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  72. }
  73. #region
  74. public bool CanCloseDialog()
  75. {
  76. return true;
  77. }
  78. public void OnDialogClosed()
  79. {
  80. }
  81. public void OnDialogOpened(IDialogParameters parameters)
  82. {
  83. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  84. parameters.TryGetValue<int>(ParameterNames.ListSelectedIndex, out listSelectedIndex);
  85. if (pdfViewer != null)
  86. {
  87. PageCount = pdfViewer.Document.PageCount;
  88. Model.SourceFileName = System.IO.Path.GetFileName(pdfViewer.Document.FileName);
  89. //"拆分方式
  90. //若未选择要拆分的页面,则默认选中【平均每X页拆分为一个PDF文件】,默认参数为 1
  91. //若先选择了页面再点击【拆分】,则默认选中【按页面范围拆分】,默认参数为当前所选页面范围"
  92. if (listSelectedIndex == -1)
  93. {
  94. Model.IsAveragePages = true;
  95. }
  96. else
  97. {
  98. Model.IsCustomRange = true;
  99. }
  100. }
  101. }
  102. #endregion
  103. }
  104. }