Browse Source

注释 - 优化代码,创建后多选注释

chenrongqian@kdanmobile.com 1 year ago
parent
commit
39d62c05a1
1 changed files with 52 additions and 64 deletions
  1. 52 64
      PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Command.cs

+ 52 - 64
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Command.cs

@@ -779,48 +779,7 @@ namespace PDF_Office.ViewModels.Tools
         {
             if (e != null && e.Count > 0)
             {
-                Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
-                int count = 0;
-                foreach (var item in e)
-                {
-                    if(item.EditAction == ActionType.Add)
-                    {
-                        var annot = item.EditAnnotArgs;
-                        if (
-                     annot.EventType == AnnotArgsType.AnnotSquare ||
-                     annot.EventType == AnnotArgsType.AnnotCircle ||
-                     annot.EventType == AnnotArgsType.AnnotLine ||
-                     annot.EventType == AnnotArgsType.AnnotStamp ||
-                     annot.EventType == AnnotArgsType.AnnotFreeText
-                     )
-                        {
-                            if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
-                            {
-                                selectAnnotDicts.Add(item.PageIndex, new List<int>());
-                                selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
-                            }
-                            else
-                            {
-                                selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
-                            }
-
-                            count++;
-                        }
-                           
-                    }
-                   
-                }
-
-               
-                if (StrAnnotToolChecked == "Signature")
-                {
-                    //AddAnnotSignature(annot);
-                }
-
-                PDFViewer.ClearSelectAnnots();
-                PDFViewer.SelectAnnotation(selectAnnotDicts);
-
-
+                MultipleSelectionAnnot(e);
 
                 for (int i = 0; i < e.Count; i++)
                 {
@@ -829,6 +788,7 @@ namespace PDF_Office.ViewModels.Tools
                     {
                         case ActionType.Add:
 
+                            //BOTA
                             bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
 
                             if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
@@ -843,27 +803,13 @@ namespace PDF_Office.ViewModels.Tools
                                 }
                             }
 
-                            //var annot = e[0].EditAnnotArgs;
-                            //if (
-                            //   annot.EventType == AnnotArgsType.AnnotSquare ||
-                            //   annot.EventType == AnnotArgsType.AnnotCircle ||
-                            //   annot.EventType == AnnotArgsType.AnnotLine ||
-                            //   annot.EventType == AnnotArgsType.AnnotStamp
-                            //   )
-                            //{
-                            //    PDFViewer.ClearSelectAnnots();
-                            //    if (StrAnnotToolChecked != "Signature")
-                            //    {
-                            //        PDFViewer.SelectAnnotation(annot.PageIndex, annot.AnnotIndex);
-                            //    }
-                            //    else
-                            //    {
-                            //        AddAnnotSignature(annot);
-                            //        PDFViewer.SelectAnnotation(annot.PageIndex, annot.AnnotIndex);
-                            //    } 
-                            //}
-
+                            //添加书签注释,用于未保存前跟图章手绘注释的区分
+                            if (StrAnnotToolChecked == "Signature")
+                            {
+                                AddAnnotSignature(editEvent.EditAnnotArgs);
+                            }
                             
+
                             break;
 
                         case ActionType.Del:
@@ -912,6 +858,47 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
+        //复制多个注释,粘贴后,默认注释未选中状态
+        private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
+        {
+            bool isAdd = false;
+            Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
+           
+            foreach (var item in e)
+            {
+                if (item.EditAction == ActionType.Add)
+                {
+                    var annot = item.EditAnnotArgs;
+                    if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
+                        annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText)
+                    {
+                        if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
+                        {
+                            selectAnnotDicts.Add(item.PageIndex, new List<int>());
+                            selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
+                        }
+                        else
+                        {
+                            selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
+                        }
+
+                        isAdd = true;
+
+                    }
+
+                }
+
+            }
+
+            if (isAdd)
+            {
+                PDFViewer.ClearSelectAnnots();
+                PDFViewer.SelectAnnotation(selectAnnotDicts);
+            }
+
+        }
+
+        //阅读页悬浮相应
         private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
         {
             if (e != null && e.DrawContext != null)
@@ -973,11 +960,11 @@ namespace PDF_Office.ViewModels.Tools
                     oldRect = hoverRect;
                     PDFViewer.MouseMove -= PDFViewer_MouseMove;
                     PDFViewer.MouseMove += PDFViewer_MouseMove;
-                    return;
                 }
-
             }
         }
+
+        //关闭ToolTip
         private void CloseAnnotToolTip()
         {
             if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
@@ -1029,6 +1016,7 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
+        //来自属性面板的事件,更改颜色等属性而触发
         private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
         {
             if (e != null)