ConverterTextDialogViewModel.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
  16. using DialogResult = Prism.Services.Dialogs.DialogResult;
  17. namespace PDF_Office.ViewModels.Dialog.ConverterDialogs
  18. {
  19. public class ConverterTextDialogViewModel : BindableBase, IDialogAware
  20. {
  21. public ConverterTextDialogModel ConverterTextModel = new ConverterTextDialogModel();
  22. public CPDFViewer currentViewer;
  23. public IDialogService dialogs;
  24. public string CurrentPageIndex = "1";
  25. public string PageRangeText { set; get; } = "0";
  26. public string PageRangeSelectIndex { set; get; } = "0";
  27. public DelegateCommand CancelCommand { get; set; }
  28. public DelegateCommand ConverterCommnad { get; set; }
  29. public ConverterTextDialogViewModel(IDialogService dialogService)
  30. {
  31. CancelCommand = new DelegateCommand(cancel);
  32. ConverterCommnad = new DelegateCommand(converter);
  33. dialogs = dialogService;
  34. }
  35. private void cancel()
  36. {
  37. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  38. }
  39. private void converter()
  40. {
  41. FolderBrowserDialog dlg = new FolderBrowserDialog();
  42. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  43. {
  44. ConverterTextModel.OutputPath = dlg.SelectedPath.Trim();
  45. }
  46. HomePageEditHelper.GetPagerange(PageRangeSelectIndex, currentViewer, ref ConverterTextModel.PageRange, PageRangeText,true, CurrentPageIndex);
  47. char[] enumerationSeparator = new char[] { ',' };
  48. char[] rangeSeparator = new char[] { '-' };
  49. if (!CommonHelper.GetPagesInRange(ref ConverterTextModel.PageIndexLists, ConverterTextModel.PageRange, currentViewer.Document.PageCount, enumerationSeparator, rangeSeparator))
  50. { //TODO
  51. Trace.WriteLine("输入不对");
  52. MessageBoxEx.Show("输入不对");
  53. return;
  54. }
  55. DialogParameters value = new DialogParameters();
  56. value.Add(ParameterNames.ConverterType, "Text");
  57. value.Add(ParameterNames.ConverterTypeModel, ConverterTextModel);
  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. ConverterTextModel.InputPath = pdfViewer.Document.FilePath;
  83. FileInfo fileinfo = new FileInfo(ConverterTextModel.InputPath);
  84. ConverterTextModel.OutputPath=fileinfo.DirectoryName;
  85. }
  86. }
  87. }
  88. }