Sfoglia il codice sorgente

ComPDFKit.Demo(win) - 修复从注释列表删除注释无法Undo的问题

TangJinZhou 1 giorno fa
parent
commit
9f0c6fdf7d

+ 32 - 2
Demo/Examples/ComPDFKit.Tool/Help/ParamConverter.cs

@@ -9,6 +9,8 @@ using ComPDFKit.PDFPage.Edit;
 using ComPDFKit.Tool.SettingParam;
 using ComPDFKit.Tool.UndoManger;
 using ComPDFKit.Viewer.Helper;
+using ComPDFKitViewer.Helper;
+using ComPDFKitViewer;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
@@ -169,12 +171,39 @@ namespace ComPDFKit.Tool.Help
             return annotHistory;
         }
 
-        public static bool RemovePageAnnot(Dictionary<int, List<int>> removeAnnots, CPDFDocument cPDFDocument)
+        public static bool RemovePageAnnot(Dictionary<int, List<int>> removeAnnots, CPDFViewer cPDFViewer)
         {
+            CPDFDocument cPDFDocument = cPDFViewer.GetDocument();
             if (cPDFDocument == null || removeAnnots.Count <= 0)
             {
                 return false;
             }
+
+            GroupHistory historyGroup = new GroupHistory();
+            foreach (int pageIndex in removeAnnots.Keys)
+            {
+                CPDFPage pageCore = cPDFDocument.PageAtIndex(pageIndex);
+                List<CPDFAnnotation> cPDFAnnotations = pageCore.GetAnnotations();
+                foreach (int annotIndex in removeAnnots[pageIndex])
+                {
+                    CPDFAnnotation cPDFAnnotation = cPDFAnnotations.ElementAtOrDefault(annotIndex);
+                    if (cPDFAnnotation != null)
+                    {
+                        AnnotParam annotParam = CPDFDataConverterToAnnotParam(cPDFDocument, pageIndex, cPDFAnnotation);
+                        AnnotHistory annotHistory = CreateHistory(cPDFAnnotation);
+                        annotHistory.CurrentParam = annotParam;
+                        annotHistory.PDFDoc = cPDFDocument;
+                        annotHistory.Action = HistoryAction.Remove;
+                        historyGroup.Histories.Add(annotHistory);
+                    }
+                }
+            }
+
+            if (historyGroup.Histories.Count > 0)
+            {
+                cPDFViewer.UndoManager.AddHistory(historyGroup);
+            }
+
             foreach (int pageIndex in removeAnnots.Keys)
             {
                 CPDFPage pageCore = cPDFDocument.PageAtIndex(pageIndex);
@@ -188,7 +217,8 @@ namespace ComPDFKit.Tool.Help
                     }
                 }
             }
-            return false;
+
+            return true;
         }
 
         public static FormField ConverterWidgetFormFlags(int Flags, bool IsHidden)

+ 2 - 2
Demo/Examples/Compdfkit.Controls/Annotation/PDFAnnotationList/PDFAnnotationListControl/CPDFAnnotationListControl.xaml.cs

@@ -96,8 +96,8 @@ namespace ComPDFKit.Controls.PDFControl
             if (pdfViewer != null)
             {
                 pdfViewer.PDFToolManager.ClearSelect();
-                ParamConverter.RemovePageAnnot(e, pdfViewer.PDFViewTool.GetCPDFViewer().GetDocument());
-                pdfViewer.PDFViewTool.GetCPDFViewer().UpdateAnnotFrame();
+                ParamConverter.RemovePageAnnot(e, pdfViewer.GetCPDFViewer());
+                pdfViewer.GetCPDFViewer().UpdateAnnotFrame();
                 LoadAnnotationList();
             }
         }