Selaa lähdekoodia

优化 - 注释工具按钮函数

chenrongqian@kdanmobile.com 1 vuosi sitten
vanhempi
commit
e140f3b61e

+ 74 - 7
PDF Office/ViewModels/Tools/AnnotManager/AnnotTransfer.cs

@@ -14,6 +14,9 @@ namespace PDF_Office.ViewModels.Tools.AnnotManager
     /// </summary>
     public class AnnotTransfer
     {
+        public event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
+        public event EventHandler<Dictionary<AnnotArgsType, object>> AnnotTypeChanged;
+
         public bool IsAddLink = false;
         public bool IsLocationLink = false;
         public AnnotAttribEvent AnnotEvent { get; set; }
@@ -22,6 +25,7 @@ namespace PDF_Office.ViewModels.Tools.AnnotManager
         public AnnotHandlerEventArgs annot;
         public List<AnnotHandlerEventArgs> annotlists;
 
+        //是否为填写与签名的日期文本
         public bool IsTextFill { get; private set; }
 
         public void SetIsTextFill(bool isTextFill)
@@ -29,17 +33,75 @@ namespace PDF_Office.ViewModels.Tools.AnnotManager
             IsTextFill = isTextFill;
         }
 
-        public event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
-
-        public event EventHandler<Dictionary<AnnotArgsType, object>> AnnotTypeChanged;
-
-        public event EventHandler<object> DefaultStored;
+        public bool IsMultiSelected
+        { get { return (annotlists != null && annotlists.Count > 1); } }
 
         public AnnotTransfer()
         { 
         
         }
 
+        #region 静态
+
+        //是否为形状注释
+        public static bool IsShapAnnot(AnnotHandlerEventArgs annot)
+        {
+            if (annot.EventType == AnnotArgsType.AnnotCircle ||
+            annot.EventType == AnnotArgsType.AnnotSquare ||
+            annot.EventType == AnnotArgsType.AnnotLine
+            )
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        //是否为高亮注释
+        public static bool IsHightAnnot(AnnotHandlerEventArgs annot)
+        {
+            if (annot.EventType == AnnotArgsType.AnnotUnderline ||
+            annot.EventType == AnnotArgsType.AnnotSquiggly ||
+            annot.EventType == AnnotArgsType.AnnotHighlight ||
+            annot.EventType == AnnotArgsType.AnnotStrikeout
+            )
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        //判断注释列表是否有不同种类的注释
+        public static bool IsDifferentTypeAnnots(List<AnnotHandlerEventArgs> annotlists)
+        {
+            //如高亮、下划线、删除线,是属于同一种类的注释
+            bool isDifferentAnnotTyle = false;
+            var annot = annotlists[0];
+            var lastAnnot = annot;
+            foreach (var item in annotlists)
+            {
+                if (lastAnnot.EventType != item.EventType)
+                {
+                    if ((AnnotTransfer.IsShapAnnot(annot) == true && AnnotTransfer.IsShapAnnot(item) == true) || (AnnotTransfer.IsHightAnnot(annot) == true && AnnotTransfer.IsHightAnnot(item) == true))
+                    {
+                        lastAnnot = item;
+                        continue;
+                    }
+
+                    lastAnnot = item;
+                    isDifferentAnnotTyle = true;
+                    break;
+                }
+            }
+
+            return isDifferentAnnotTyle;
+        }
+
         //外部UI控件选中状态
         public static bool IsSolidStyle(DashStyle LineDash)
         {
@@ -75,6 +137,8 @@ namespace PDF_Office.ViewModels.Tools.AnnotManager
 
             return newDash;
         }
+        #endregion 静态
+
 
         //单个属性更改
         public void UpdateAnnotAAttrib(AnnotAttrib annotAttrib, object obj)
@@ -121,8 +185,8 @@ namespace PDF_Office.ViewModels.Tools.AnnotManager
         }
 
         //是否为多选
-        public bool IsMultiSelected
-        { get { return (annotlists != null && annotlists.Count > 1); } }
+
+        #region Invoke
 
         /// <summary>
         /// 更新多个属性,触发到工具栏注释工具,改变工具图标下的颜色值
@@ -147,5 +211,8 @@ namespace PDF_Office.ViewModels.Tools.AnnotManager
         {
             AnnotTypeChanged?.Invoke(sender, keyValues);
         }
+
+        #endregion Invoke
+
     }
 }

+ 36 - 94
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Command.cs

@@ -39,8 +39,6 @@ namespace PDF_Office.ViewModels.Tools
             //比如在属性面板里更改注释颜色,会同时更新工具栏对应的工具颜色
             propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
             propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
-            propertyPanel.DefaultStored -= AnnotProperty_DefaultStored;
-            propertyPanel.DefaultStored += AnnotProperty_DefaultStored;
             propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
             propertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
             //快捷键
@@ -51,7 +49,6 @@ namespace PDF_Office.ViewModels.Tools
         private void UnBindingEvent()
         {
             propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
-            propertyPanel.DefaultStored -= AnnotProperty_DefaultStored;
             propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
             //快捷盘解绑
             KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
@@ -71,9 +68,6 @@ namespace PDF_Office.ViewModels.Tools
                 PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
                 PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
 
-                PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander;
-                PDFViewer.WidgetClickHander += PDFViewer_WidgetClickHander;
-
                 PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
                 PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler;
 
@@ -87,45 +81,6 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
-        private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
-        {
-            if (action == null)
-            {
-                return;
-            }
-            switch (action.ActionType)
-            {
-                case C_ACTION_TYPE.ACTION_TYPE_GOTO:
-                    if (PDFViewer != null)
-                    {
-                        CPDFGoToAction gotoAction = action as CPDFGoToAction;
-                        CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
-                        if (dest != null)
-                        {
-                            PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
-                        }
-                    }
-                    break;
-
-                case C_ACTION_TYPE.ACTION_TYPE_URI:
-                    {
-                        CPDFUriAction uriAction = action as CPDFUriAction;
-                        string uri = uriAction.GetUri();
-                        try
-                        {
-                            if (!string.IsNullOrEmpty(uri))
-                            {
-                                Process.Start(uri);
-                            }
-                        }
-                        catch (Exception ex)
-                        {
-                        }
-                    }
-                    break;
-            }
-        }
-
         private void UnBindingPDFViewerHandler()
         {
             if (PDFViewer != null)
@@ -133,7 +88,6 @@ namespace PDF_Office.ViewModels.Tools
                 PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
                 PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
                 PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
-                PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander;
                 PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
                 PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
                 PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
@@ -146,6 +100,7 @@ namespace PDF_Office.ViewModels.Tools
 
         #region 与触发事件调用相关的函数
 
+
         //鼠标左键双击注释
         private void PDFViewer_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
@@ -176,39 +131,45 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
-        //是否为形状注释
-        private bool isShapAnnot(AnnotHandlerEventArgs annot)
+        //超链接跳转
+        private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
         {
-            if (annot.EventType == AnnotArgsType.AnnotCircle ||
-            annot.EventType == AnnotArgsType.AnnotSquare ||
-            annot.EventType == AnnotArgsType.AnnotLine
-            )
+            if (action == null)
             {
-                return true;
+                return;
             }
-            else
+            switch (action.ActionType)
             {
-                return false;
-            }
-        }
+                case C_ACTION_TYPE.ACTION_TYPE_GOTO:
+                    if (PDFViewer != null)
+                    {
+                        CPDFGoToAction gotoAction = action as CPDFGoToAction;
+                        CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
+                        if (dest != null)
+                        {
+                            PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
+                        }
+                    }
+                    break;
 
-        //是否为高亮注释
-        private bool isHightAnnot(AnnotHandlerEventArgs annot)
-        {
-            if (annot.EventType == AnnotArgsType.AnnotUnderline ||
-            annot.EventType == AnnotArgsType.AnnotSquiggly ||
-            annot.EventType == AnnotArgsType.AnnotHighlight ||
-            annot.EventType == AnnotArgsType.AnnotStrikeout
-            )
-            {
-                return true;
-            }
-            else
-            {
-                return false;
+                case C_ACTION_TYPE.ACTION_TYPE_URI:
+                    {
+                        CPDFUriAction uriAction = action as CPDFUriAction;
+                        string uri = uriAction.GetUri();
+                        try
+                        {
+                            if (!string.IsNullOrEmpty(uri))
+                            {
+                                Process.Start(uri);
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                        }
+                    }
+                    break;
             }
         }
-
         private void GetSelectedAnnots(AnnotAttribEvent e)
         {
             var annot = e.AnnotItemsList[0];
@@ -448,23 +409,7 @@ namespace PDF_Office.ViewModels.Tools
                     }
                     else
                     {
-                        bool isDifferentAnnotTyle = false;
-                        var lastAnnot = annot;
-                        foreach (var item in e.AnnotItemsList)
-                        {
-                            if (lastAnnot.EventType != item.EventType)
-                            {
-                                if ((isShapAnnot(annot) == true && isShapAnnot(item) == true) || (isHightAnnot(annot) == true && isHightAnnot(item) == true))
-                                {
-                                    lastAnnot = item;
-                                    continue;
-                                }
-
-                                lastAnnot = item;
-                                isDifferentAnnotTyle = true;
-                                break;
-                            }
-                        }
+                        bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
 
                         if (isDifferentAnnotTyle)
                             viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
@@ -592,7 +537,7 @@ namespace PDF_Office.ViewModels.Tools
                                 bool isHigh = true;//是否为高亮
                                 foreach (var item in e.AnnotEventArgsList)
                                 {
-                                    if (isHightAnnot(item) == false)
+                                    if (AnnotTransfer.IsHightAnnot(item) == false)
                                     {
                                         isHigh = false;
                                         break;
@@ -601,7 +546,7 @@ namespace PDF_Office.ViewModels.Tools
 
                                 MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
                                 MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
-                                e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
+                                e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
                             }
                         }
                         if (e.PopupMenu != null)
@@ -924,9 +869,6 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
-        private void PDFViewer_WidgetClickHander(object sender, WidgetArgs e)
-        {
-        }
 
         private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
         {

+ 1 - 1
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Properties.cs

@@ -171,7 +171,7 @@ namespace PDF_Office.ViewModels.Tools
         public DelegateCommand<object> SetAddAnnotationCommand { get; set; }
         public DelegateCommand AddBookMarkCommand { get; set; }
 
-        public DelegateCommand<object> HandCommand { get; set; }
+        public DelegateCommand HandCommand { get; set; }
 
         #region 注释 - 右键菜单
 

+ 65 - 48
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -44,7 +44,6 @@ namespace PDF_Office.ViewModels.Tools
     public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
     {
         #region 初始化
-
         public AnnotToolContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogService)
         {
             region = regionManager;
@@ -83,7 +82,7 @@ namespace PDF_Office.ViewModels.Tools
             SetAddAnnotationCommand = new DelegateCommand<object>(AddAnnotation_Click);
             AddBookMarkCommand = new DelegateCommand(AddBookMark_Click);
             PropertyRegionName = Guid.NewGuid().ToString();
-            HandCommand = new DelegateCommand<object>(Hand_Click);
+            HandCommand = new DelegateCommand(Hand_Click);
 
             #region 注释 - 右键菜单
 
@@ -111,7 +110,12 @@ namespace PDF_Office.ViewModels.Tools
             #endregion 注释 - 右键菜单
         }
 
-        private void Hand_Click(object obj)
+        #endregion 初始化
+
+        #region 注释工具栏 -》Command实现
+
+        //手型工具
+        private void Hand_Click()
         {
             HandToolIsCheckedEvent(BtnHandIsChecked);
             if (BtnHandIsChecked)
@@ -123,6 +127,7 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
+        //手型工具按钮选中或取消
         private void HandToolIsCheckedEvent(bool isChecked)
         {
             if (isChecked == false)
@@ -147,92 +152,65 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
-        #endregion 初始化
-
-        #region Command实现
-
         //点击注释工具
         private void BtnMyTools_Click(CustomIconToggleBtn annotBtn)
         {
+            if (annotBtn == null || annotBtn.Tag == null) return;
+
             //不创建注释,属于注释模板
-            bool isTemplateAnnot = false;
-            bool isSnapshotEdit = false;
+            Dictionary<string,bool> dictVar = new Dictionary<string,bool>();
+            dictVar.Add("isTemplateAnnot", false);
+            dictVar.Add("isSnapshotEdit", false);
             AnnotHandlerEventArgs annotArgs = null;
+            var tag = annotBtn.Tag.ToString();
 
+           
             if (annotBtn.Name == "BtnShowAnnot")
-            {
+            { 
+                //显示/隐藏注释
                 PDFViewer.SetDrawAnnot((bool)annotBtn.IsChecked);
                 return;
             }
 
             if (annotBtn.IsChecked == true)
             {
-                if (BtnHandIsChecked)
-                {
-                    BtnHandIsChecked = false;
-                }
-
-                PDFViewer.ClearSelectAnnots();
-                var tag = annotBtn.Tag.ToString();
+                MyToolCheckedDoing(dictVar, tag);
                 FindAnnotTypeKey(tag, ref annotArgs);
 
-                if (tag == "SnapshotEdit")
-                {
-                    isSnapshotEdit = true;
-                }
-                else if (tag == "Signature" || tag == "Stamp")
-                {
-                    isTemplateAnnot = true;
-                }
-
-                if (tag != "Link")
-                    BtnLinkIsChecked = false;
-                else
-                    StrAnnotToolChecked = "Link";
-
                 if (annotArgs != null)
                 {
+                    //设置点击页面会创建对应选中注释工具的注释
                     annotArgs.Author = Settings.Default.AppProperties.Description.Author;
                     PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
                     PDFViewer.SetToolParam(annotArgs);
-
-                    if (tag == "Rect" || tag == "Circle" || tag == "Arrow" || tag == "Line")
-                    {
-                        PDFViewer.ToolManager.EnableClickCreate = true;
-                        PDFViewer.ToolManager.ClickCreateWidth = 140;
-                        PDFViewer.ToolManager.ClickCreateHeight = 140;
-                    }
-                    else
-                    {
-                        PDFViewer.ToolManager.EnableClickCreate = false;
-                    }
-
                     #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
 
                     //isRightMenuAddAnnot = false;
 
                     #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
                 }
+
             }
             else
             {
+                //取消选中注释工具按钮后,恢复到未编辑注释的状态
                 propertyPanel.IsAddLink = false;
                 propertyPanel.IsLocationLink = false;
                 PDFViewer.ToolManager.EnableClickCreate = false;
             }
 
-            //当不是注释模板,且无创建注释时,属性面板显示为空内容
-            if (isTemplateAnnot == false && annotArgs == null)
+            
+            if (dictVar["isTemplateAnnot"] == false && annotArgs == null)
             {
+                //当不是注释模板,且无创建注释时,属性面板显示为空内容
                 PDFViewer.SetMouseMode(MouseModes.PanTool);
                 viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
             }
             else
             {
-                if (isSnapshotEdit == true)
+                if (dictVar["isSnapshotEdit"] == true)
                 {
                     ShowPropertyPanel(false);
-                    isSnapshotEdit = false;
                 }
                 else
                 {
@@ -241,7 +219,46 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
-        #endregion Command实现
+        //选中注释工具按钮时,处理的一些系列事情
+        private void MyToolCheckedDoing(Dictionary<string, bool> dict,string tag)
+        {
+            BtnHandIsChecked = !BtnHandIsChecked;
+            PDFViewer.ClearSelectAnnots();
+
+            //选中内容选择工具按钮
+            if (tag == "SnapshotEdit")
+            {
+                dict["isSnapshotEdit"] = true;
+            }
+            else if (tag == "Signature" || tag == "Stamp")
+            {
+                //选中签名、图章工具按钮
+                dict["isTemplateAnnot"] = true;
+            }
+
+            //超链接工具
+            if (tag != "Link")
+                BtnLinkIsChecked = false;
+            else
+                StrAnnotToolChecked = "Link";
+
+            
+            if (tag == "Rect" || tag == "Circle" || tag == "Arrow" || tag == "Line")
+            {
+                //新建形状注释,设置默认大小
+                PDFViewer.ToolManager.EnableClickCreate = true;
+                PDFViewer.ToolManager.ClickCreateWidth = 140;
+                PDFViewer.ToolManager.ClickCreateHeight = 140;
+            }
+            else
+            {
+                PDFViewer.ToolManager.EnableClickCreate = false;
+            }
+
+        }
+
+
+        #endregion 注释工具栏 -》Command实现
 
         #region BOTA
 

+ 0 - 1
PDF Office/Views/Tools/AnnotToolContent.xaml

@@ -41,7 +41,6 @@
                 <customControl:CustomIconToggleBtn
                     x:Name="BtnHand" Tag="Hand"
                     Command="{Binding HandCommand}"
-                    CommandParameter="{Binding ElementName=ToolPanel}"
                     Foreground="Black"
                     IsChecked="{Binding BtnHandIsChecked}"
                     Style="{StaticResource ToggleBtnViewModeStyle}">