ConverterRTFDialogViewModel.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Office.CustomControl;
  3. using PDF_Office.Helper;
  4. using PDF_Office.Model;
  5. using PDF_Office.Model.Dialog.ConverterDialogs;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using Prism.Services.Dialogs;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Windows.Forms;
  15. using DialogResult = Prism.Services.Dialogs.DialogResult;
  16. namespace PDF_Office.ViewModels.Dialog.ConverterDialogs
  17. {
  18. public class ConverterRTFDialogViewModel : BindableBase, IDialogAware
  19. {
  20. public ConverterRTFDialogModel ConverterRTFModel = new ConverterRTFDialogModel();
  21. public CPDFViewer currentViewer;
  22. public IDialogService dialogs;
  23. public string CurrentPageIndex = "1";
  24. public string PageRangeText { set; get; } = "0";
  25. public string PageRangeSelectIndex { set; get; } = "0";
  26. public DelegateCommand CancelCommand { get; set; }
  27. public DelegateCommand ConverterCommnad { get; set; }
  28. public ConverterRTFDialogViewModel(IDialogService dialogService)
  29. {
  30. CancelCommand = new DelegateCommand(cancel);
  31. ConverterCommnad = new DelegateCommand(converter);
  32. dialogs = dialogService;
  33. }
  34. private void cancel()
  35. {
  36. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  37. }
  38. private void converter()
  39. {
  40. FolderBrowserDialog dlg = new FolderBrowserDialog();
  41. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  42. {
  43. ConverterRTFModel.OutputPath = dlg.SelectedPath.Trim();
  44. }
  45. HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref ConverterRTFModel.PageRange, PageRangeText, true, CurrentPageIndex);
  46. char[] enumerationSeparator = new char[] { ',' };
  47. char[] rangeSeparator = new char[] { '-' };
  48. if (!CommonHelper.GetPagesInRange(ref ConverterRTFModel.PageIndexLists, ConverterRTFModel.PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
  49. { //TODO
  50. Trace.WriteLine("输入不对");
  51. MessageBoxEx.Show("输入不对");
  52. return;
  53. }
  54. //result = await ConverterHelper.TxtConvert(ConverterTextModel.InputPath, ConverterTextModel.OutputPath, ConverterTextModel.GetProgress, ConverterTextModel.PageIndexLists, ConverterTextModel.Pawssword);
  55. DialogParameters value = new DialogParameters();
  56. value.Add(ParameterNames.ConverterType, "RTF");
  57. value.Add(ParameterNames.ConverterTypeModel, ConverterRTFModel);
  58. RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
  59. dialogs.ShowDialog(DialogNames.ConverterProgressBarDialog, value, e =>
  60. {
  61. });
  62. }
  63. private void SetProgress(int pageIndex)
  64. {
  65. }
  66. public string Title => "";
  67. public event Action<IDialogResult> RequestClose;
  68. public bool CanCloseDialog()
  69. {
  70. return true;
  71. }
  72. public void OnDialogClosed()
  73. {
  74. }
  75. public void OnDialogOpened(IDialogParameters parameters)
  76. {
  77. CPDFViewer pdfViewer = null;
  78. parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
  79. if (pdfViewer != null)
  80. {
  81. currentViewer = pdfViewer;
  82. ConverterRTFModel.InputPath = pdfViewer.Document.FilePath;
  83. FileInfo fileinfo = new FileInfo(ConverterRTFModel.InputPath);
  84. ConverterRTFModel.OutputPath = fileinfo.DirectoryName;
  85. }
  86. }
  87. }
  88. }