123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using ComPDFKitViewer.PdfViewer;
- using PDF_Master.CustomControl;
- using PDF_Master.Helper;
- using PDF_Master.Model;
- using PDF_Master.Model.HomePageToolsDialogs;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
- {
- public class SplitDialogViewModel : BindableBase, IDialogAware
- {
- public string Title => "";
- private CPDFViewer pdfViewer;
- private int listSelectedIndex;
- private double pageCount;
- private string pageEditSelectedItems;
- //页面总数
- public double PageCount
- {
- get { return pageCount; }
- set
- {
- SetProperty(ref pageCount, value);
- }
- }
- private string customPageText;
- /// <summary>
- /// 自定义的输入内容
- /// </summary>
- public string CustomPageText
- {
- get { return customPageText; }
- set
- {
- SetProperty(ref customPageText, value);
- }
- }
- private HomePageSplitDialogModel model;
- public HomePageSplitDialogModel Model
- {
- get { return model; }
- set
- {
- SetProperty(ref model, value);
- }
- }
- public event Action<IDialogResult> RequestClose;
- public DelegateCommand CancelCommand { get; set; }
- public DelegateCommand SplitCommnad { get; set; }
- public SplitDialogViewModel()
- {
- CancelCommand = new DelegateCommand(cancel);
- SplitCommnad = new DelegateCommand(split);
- Model = new HomePageSplitDialogModel();
- }
- private void cancel()
- {
- RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
- }
- private void split()
- {
- List<int> pages = new List<int>();
- Model.PageRange = model.CustomPageText;
- DialogParameters valuePairs = new DialogParameters();
- valuePairs.Add(ParameterNames.DataModel, Model);
- RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
- }
- #region
- public bool CanCloseDialog()
- {
- return true;
- }
- public void OnDialogClosed()
- {
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
- parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
- parameters.TryGetValue<int>(ParameterNames.PageEditSelectedIndex, out listSelectedIndex);
- parameters.TryGetValue<string>(ParameterNames.PageEditSelectedItems, out pageEditSelectedItems);
- if (pdfViewer != null)
- {
- PageCount = pdfViewer.Document.PageCount;
- Model.SourceFileName = System.IO.Path.GetFileName(pdfViewer.Document.FileName);
- //"拆分方式
- //若未选择要拆分的页面,则默认选中【平均每X页拆分为一个PDF文件】,默认参数为 1
- //若先选择了页面再点击【拆分】,则默认选中【按页面范围拆分】,默认参数为当前所选页面范围"
- if (listSelectedIndex == -1)
- {
- Model.IsAveragePages = true;
- }
- else
- {
- Model.IsCustomRange = true;
- if (pageEditSelectedItems != null)
- {
- model.CustomPageText = pageEditSelectedItems;
- }
- Model.PageSelectedIndex = 3;
- }
- }
- }
- #endregion
- }
- }
|