|
@@ -21,6 +21,7 @@ using System.Threading.Tasks;
|
|
|
using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
|
|
|
using Task = System.Threading.Tasks.Task;
|
|
|
using PDF_Office.Model.Dialog.ToolsDialogs;
|
|
|
+using ComPDFKitViewer;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.Tools
|
|
|
{
|
|
@@ -31,13 +32,13 @@ namespace PDF_Office.ViewModels.Tools
|
|
|
private ViewContentViewModel viewContentViewModel;
|
|
|
|
|
|
public IDialogService dialogs;
|
|
|
-
|
|
|
+ public CropPageUndoManager UndoManager=new CropPageUndoManager();
|
|
|
public IEventAggregator eventAggregator;
|
|
|
-
|
|
|
+ List<int> cropCurrentPageList = new List<int>();
|
|
|
+
|
|
|
|
|
|
-
|
|
|
private CPDFDocument.GetPageIndexDelegate indexDelegate = null;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
public string unicode = null;
|
|
|
|
|
@@ -60,8 +61,8 @@ namespace PDF_Office.ViewModels.Tools
|
|
|
// App.mainWindowViewModel.Value = int.Parse(PageIndex);
|
|
|
// }
|
|
|
//}
|
|
|
- //private CPDFDocument tempDocument;
|
|
|
- //private IntPtr compressingIntpr = IntPtr.Zero;
|
|
|
+ //private CPDFDocument tempDocument;
|
|
|
+ //private IntPtr compressingIntpr = IntPtr.Zero;
|
|
|
//private string _pageNumber = "";
|
|
|
///// <value>
|
|
|
///// 总页数
|
|
@@ -81,7 +82,8 @@ namespace PDF_Office.ViewModels.Tools
|
|
|
public DelegateCommand CancelPasswordCommand { get; set; }
|
|
|
public DelegateCommand<object> SetEditToolsCommand { get; set; }
|
|
|
public DelegateCommand SetWatermarkCommand { get; set; }
|
|
|
-
|
|
|
+ public DelegateCommand CropCurrentPageWMCommand { get; set; }
|
|
|
+ public DelegateCommand CropAllPagesWMCommand { get; set; }
|
|
|
public ToolsBarContentViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
|
|
|
{
|
|
|
dialogs = dialogService;
|
|
@@ -92,6 +94,8 @@ namespace PDF_Office.ViewModels.Tools
|
|
|
SetPasswordCommand = new DelegateCommand(OpenSetPasswordDialog);
|
|
|
CancelPasswordCommand = new DelegateCommand(OpenCancelPasswordDialog);
|
|
|
SetEditToolsCommand = new DelegateCommand<object>(SetEditTools);
|
|
|
+ CropCurrentPageWMCommand = new DelegateCommand(CropCurrentPageWM);
|
|
|
+ CropAllPagesWMCommand = new DelegateCommand(CropAllPagesWM);
|
|
|
}
|
|
|
|
|
|
private void SetEditTools(object e)
|
|
@@ -112,7 +116,7 @@ namespace PDF_Office.ViewModels.Tools
|
|
|
{
|
|
|
CompressDialogModel compressDialogModel = new CompressDialogModel();
|
|
|
compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
|
|
|
- // OnOpened((Prism.Services.Dialogs.DialogResult)e);
|
|
|
+ // OnOpened((Prism.Services.Dialogs.DialogResult)e);
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -221,6 +225,53 @@ namespace PDF_Office.ViewModels.Tools
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private async void CropCurrentPageWM()
|
|
|
+ {
|
|
|
+ viewContentViewModel.IsLoading = Visibility.Visible;
|
|
|
+ await WaitCropCurrentPageWM();
|
|
|
+ viewContentViewModel.IsLoading = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+ private async void CropAllPagesWM()
|
|
|
+ {
|
|
|
+ viewContentViewModel.IsLoading = Visibility.Visible;
|
|
|
+ await WaitCropAllPagesWM();
|
|
|
+ viewContentViewModel.IsLoading = Visibility.Collapsed;
|
|
|
+
|
|
|
+ //PDFViewer.UndoManager.AddHistory();
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task WaitCropCurrentPageWM() {
|
|
|
+ await Task.Run(() => {
|
|
|
+ if (PDFViewer.CurrentIndex > 0)
|
|
|
+ {
|
|
|
+ UndoManager.cropPageList.Add(PDFViewer.CurrentIndex);
|
|
|
+ }
|
|
|
+ UndoManager.ADDCropCurrentPageWM();
|
|
|
+ PDFViewer?.SetCropMode(true, UndoManager.cropPageList);
|
|
|
+ PDFViewer.UndoManager.AddHistory(UndoManager);
|
|
|
+ PDFViewer.UndoManager.CanSave = true;
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task WaitCropAllPagesWM() {
|
|
|
+ await Task.Run(() => {
|
|
|
+ List<int> cropPagesList = new List<int>();
|
|
|
+ for (int i = 0; i < PDFViewer.Document.PageCount; i++)
|
|
|
+ {
|
|
|
+ cropPagesList.Add(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ UndoManager.cropPageList.AddRange(cropPagesList);
|
|
|
+ UndoManager.ADDCropAllPagesWM();
|
|
|
+ PDFViewer?.SetCropMode(true, UndoManager.cropPageList);
|
|
|
+ PDFViewer.UndoManager.AddHistory(UndoManager);
|
|
|
+ PDFViewer.UndoManager.CanSave = true;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
|
{
|
|
|
return true;
|
|
@@ -236,6 +287,8 @@ namespace PDF_Office.ViewModels.Tools
|
|
|
navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
|
|
|
if (PDFViewer != null)
|
|
|
{
|
|
|
+ UndoManager.setPDFViewer(PDFViewer);
|
|
|
+ //DFViewer.UndoManager.AddHistory(UndoManager);
|
|
|
isFirstLoad = false;
|
|
|
}
|
|
|
}
|