using ComPDFKitViewer; using ComPDFKitViewer.PdfViewer; using Microsoft.Office.Core; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PDF_Master.Helper { public enum CropPageEnum { CropCurrentPageWM, CropAllPagesWM } public class CropPageUndoManager : IHistory { public List cropPageList = new List(); private List cropPageEnumList = new List(); private int cropPageEnumIndex = -1; private int cropPageListInterval = 0; private CPDFViewer pdfviewer = null; public CropPageUndoManager() { } public void setPDFViewer(CPDFViewer pDFViewer) { pdfviewer = pDFViewer; } public void ADDCropCurrentPageWM() { cropPageEnumIndex++; cropPageEnumList.Insert(cropPageEnumIndex, CropPageEnum.CropCurrentPageWM); if (cropPageEnumIndex != cropPageEnumList.Count - 1) { cropPageEnumList.RemoveRange(cropPageEnumIndex + 1, cropPageEnumList.Count - cropPageEnumIndex-1); cropPageList.RemoveRange(cropPageList.Count - cropPageListInterval-1, cropPageListInterval); cropPageListInterval = 0; } } public void ADDCropAllPagesWM() { cropPageEnumIndex++; cropPageEnumList.Insert(cropPageEnumIndex, CropPageEnum.CropAllPagesWM); if (cropPageEnumIndex != cropPageEnumList.Count - 1) { cropPageEnumList.RemoveRange(cropPageEnumIndex+1, cropPageEnumList.Count - cropPageEnumIndex-1); cropPageList.RemoveRange(cropPageList.Count - cropPageListInterval- pdfviewer.Document.PageCount, cropPageListInterval); cropPageListInterval = 0; } } public void setPageList(List CropPageList) { cropPageList = CropPageList; } public bool Redo() { cropPageEnumIndex++; if (cropPageEnumIndex < cropPageEnumList.Count ) { if (cropPageEnumList[cropPageEnumIndex] == CropPageEnum.CropAllPagesWM) { cropPageListInterval -= pdfviewer.Document.PageCount; } else { cropPageListInterval--; } if (cropPageList.Count - cropPageListInterval == 0) { pdfviewer.SetCropMode(false); } else { pdfviewer.SetCropMode(true, cropPageList.GetRange(0, cropPageList.Count - cropPageListInterval)); } return true; } else { return false; } } public bool Undo() { if (cropPageEnumIndex > -1) { if (cropPageEnumList[cropPageEnumIndex] == CropPageEnum.CropAllPagesWM) { cropPageListInterval += pdfviewer.Document.PageCount; } else { cropPageListInterval++; } if (cropPageList.Count - cropPageListInterval == 0) { pdfviewer.SetCropMode(false); } else { pdfviewer.SetCropMode(true, cropPageList.GetRange(0, cropPageList.Count - cropPageListInterval)); } cropPageEnumIndex--; return true; } else { return false; } } } }