Browse Source

注释 - 创建注释后,属性面板回到默认值

chenrongqian@kdanmobile.com 2 years ago
parent
commit
49ba868be4

+ 8 - 9
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Function.cs

@@ -663,10 +663,9 @@ namespace PDF_Office.ViewModels.Tools
             return null;
         }
 
-        private AnnotHandlerEventArgs GetImage(CustomIconToggleBtn annotBtn)
+        private AnnotHandlerEventArgs GetImage()
         {
             Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
-            annotBtn.IsChecked = false;
             StampAnnotArgs stampArgs = new StampAnnotArgs();
             stampArgs.Opacity = 1;
             stampArgs.Type = StampType.IMAGE_STAMP;
@@ -723,13 +722,13 @@ namespace PDF_Office.ViewModels.Tools
         /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
         private void AddToPropertyPanel(string viewContent, string toolTag = null, AnnotHandlerEventArgs annot = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null)
         {
-            if (string.IsNullOrEmpty(toolTag) == false)
-            {
-                if (!ToolExpandDict.ContainsKey(toolTag))
-                {
-                    ToolExpandDict[toolTag] = true;
-                }
-            }
+            //if (string.IsNullOrEmpty(toolTag) == false)
+            //{
+            //    if (!ToolExpandDict.ContainsKey(toolTag))
+            //    {
+            //        ToolExpandDict[toolTag] = true;
+            //    }
+            //}
 
             if (annot != null)
                 propertyPanel.annot = annot;

+ 110 - 67
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -51,9 +51,27 @@ namespace PDF_Office.ViewModels.Tools
             PropertyRegionName = Guid.NewGuid().ToString();
             BindingEvent();
             InitDefaultValue();
+            InitToolDict();
         }
 
-        private Dictionary<string, bool> ToolExpandDict = new Dictionary<string, bool>();
+        private void InitToolDict()
+        {
+            ToolExpandDict.Add("SnapshotEdit", AnnotArgsType.SnapshotWithEditTool);
+            ToolExpandDict.Add("HighLight", AnnotArgsType.AnnotHighlight);
+            ToolExpandDict.Add("UnderLine", AnnotArgsType.AnnotUnderline);
+            ToolExpandDict.Add("Squiggly", AnnotArgsType.AnnotSquiggly);
+            ToolExpandDict.Add("Strikeout", AnnotArgsType.AnnotStrikeout);
+            ToolExpandDict.Add("Freehand", AnnotArgsType.AnnotFreehand);
+            ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
+            ToolExpandDict.Add("StickyNote", AnnotArgsType.AnnotSticky);
+            ToolExpandDict.Add("Rect", AnnotArgsType.AnnotSquare);
+            ToolExpandDict.Add("Circle", AnnotArgsType.AnnotCircle);
+            ToolExpandDict.Add("Arrow", AnnotArgsType.AnnotLine);
+            ToolExpandDict.Add("Line", AnnotArgsType.AnnotLine);
+            ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
+        }
+
+        private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
 
         public void BtnMyTools_Click(CustomIconToggleBtn annotBtn)
         {
@@ -64,73 +82,16 @@ namespace PDF_Office.ViewModels.Tools
 
             if (annotBtn.IsChecked == true)
             {
-                switch (annotBtn.Tag.ToString())
-                {
-                    case "SnapshotEdit"://内容选择
-                        annotArgs = GetSnapshotEdit();
-                        isSnapshotEdit = true;
-                        break;
-
-                    case "HighLight"://字体高亮
-                        annotArgs = GetHighLight();
-                        break;
-
-                    case "UnderLine"://下划线
-                        annotArgs = GetUnderLine();
-                        break;
-
-                    case "Squiggly"://波浪线
-                        annotArgs = GetSquiggly();
-                        break;
-
-                    case "Strikeout"://删除线
-                        annotArgs = GetStrikeout();
-                        break;
-
-                    case "Freehand"://手绘
-                        annotArgs = GetFreehand();
-                        break;
-
-                    case "Freetext"://文本
-                        annotArgs = GetFreetext();
-                        break;
-
-                    case "StickyNote"://便签
-                        annotArgs = GetStickyNote();
-                        break;
+                var tag = annotBtn.Tag.ToString();
+                FindAnnotTypeKey(tag, ref annotArgs);
 
-                    case "Rect"://矩形
-                        annotArgs = GetRect();
-                        break;
-
-                    case "Circle"://圆
-                        annotArgs = GetCircle();
-                        break;
-
-                    case "Arrow"://箭头
-                    case "Line"://线
-                        annotArgs = GetArrowLine(annotBtn.Tag.ToString());
-                        break;
-
-                    case "Stamp"://图章
-                        annotArgs = GetStamp();
-                        isTemplateAnnot = true;
-                        break;
-
-                    case "Image":
-                        annotArgs = GetImage(annotBtn);
-                        break;
-
-                    case "Signature"://签名
-                        annotArgs = GetSignature();
-                        isTemplateAnnot = true;
-                        PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
-                        break;
-
-                    case "Link"://链接
-                        viewContentViewModel.IsCreateLink = false;
-                        annotArgs = GetLink();
-                        break;
+                if (tag == "SnapshotEdit")
+                {
+                    isSnapshotEdit = true;
+                }
+                else if(tag == "Signature" || tag == "Stamp")
+                {
+                    isTemplateAnnot = true;
                 }
 
                 if (annotArgs != null)
@@ -158,6 +119,75 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
+        private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs)
+        {
+            switch (tag)
+            {
+                case "SnapshotEdit"://内容选择
+                    annotArgs = GetSnapshotEdit();
+                    break;
+
+                case "HighLight"://字体高亮
+                    annotArgs = GetHighLight();
+                    break;
+
+                case "UnderLine"://下划线
+                    annotArgs = GetUnderLine();
+                    break;
+
+                case "Squiggly"://波浪线
+                    annotArgs = GetSquiggly();
+                    break;
+
+                case "Strikeout"://删除线
+                    annotArgs = GetStrikeout();
+                    break;
+
+                case "Freehand"://手绘
+                    annotArgs = GetFreehand();
+                    break;
+
+                case "Freetext"://文本
+                    annotArgs = GetFreetext();
+                    break;
+
+                case "StickyNote"://便签
+                    annotArgs = GetStickyNote();
+                    break;
+
+                case "Rect"://矩形
+                    annotArgs = GetRect();
+                    break;
+
+                case "Circle"://圆
+                    annotArgs = GetCircle();
+                    break;
+
+                case "Arrow"://箭头
+                case "Line"://线
+                    annotArgs = GetArrowLine(tag);
+                    break;
+
+                case "Stamp"://图章
+                    annotArgs = GetStamp();
+                    break;
+
+                case "Image":
+                    annotArgs = GetImage();
+                    break;
+
+                case "Signature"://签名
+                    annotArgs = GetSignature();
+                    PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
+                    break;
+
+                case "Link"://链接
+                    viewContentViewModel.IsCreateLink = false;
+                    annotArgs = GetLink();
+                    break;
+            }
+        }
+
         private void AnnotProperty_DefaultStored(object sender, object e)
         {
         }
@@ -713,6 +743,19 @@ namespace PDF_Office.ViewModels.Tools
                                 //    isTemplateAnnot = true;
                                 //    break;
                         }
+       
+                        if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
+                        {
+                            foreach(var item in ToolExpandDict)
+                            {
+                                if(item.Value == e.AnnotItemsList[0].EventType)
+                                {
+                                    FindAnnotTypeKey(item.Key, ref annot);
+                                    break;
+                                }
+                            }
+                        }
+                        
                         ShowPropertyPanel();
                     }
                 }