Ver Fonte

填写与签名-右击菜单

liyijie há 2 anos atrás
pai
commit
a6c1ccf397

+ 155 - 5
PDF Office/ViewModels/FillAndSign/FillAndSignContentViewModel.cs

@@ -28,6 +28,12 @@ using Control = System.Windows.Controls.Control;
 using Microsoft.Office.Interop.Word;
 using Point = System.Windows.Point;
 using System.Windows.Ink;
+using PDF_Office.EventAggregators;
+using System.Management.Instrumentation;
+using Prism.Events;
+using System.Windows.Input;
+using ContextMenu = System.Windows.Controls.ContextMenu;
+using MenuItem = System.Windows.Controls.MenuItem;
 
 namespace PDF_Office.ViewModels.FillAndSign
 {
@@ -38,9 +44,17 @@ namespace PDF_Office.ViewModels.FillAndSign
         private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
         private ViewContentViewModel viewContentViewModel;
         private bool isRightMenuAddAnnot = false;
+        private IEventAggregator events;
         public List<List<Point>> ShapePoints = new List<List<Point>>();
         private string Shape = "HookShape";
-
+        private PopMenu HightAnnotPopMenu;
+        private PopMenu FreeHandAnnotPopMenu;
+        private PopMenu FreeTextAnnotPopMenu;
+        private PopMenu StrickNoteAnnotPopMenu;
+        private PopMenu ShapeAnnotPopMenu;
+        private PopMenu LinkAnnotPopMenu;
+        private PopMenu StampAnnotPopMenu;
+        private PopMenu MultiAnnotPopMenu;
         private IRegionManager regions { get; set; }
         private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
         public static bool IsEdit = false;
@@ -58,13 +72,14 @@ namespace PDF_Office.ViewModels.FillAndSign
         public Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
         #endregion
 
-        public FillAndSignContentViewModel(IRegionManager regionManager)
+        public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events)
         {
             regions = regionManager;
-
+            this.events = events;
             CheckCommand = new DelegateCommand<RoutedEventArgs>(CheckedEvent);
             ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
             InitDictionary();
+            InitSelectFreeHandAnnotMenu();
         }
 
         private void CheckedEvent(RoutedEventArgs e)
@@ -439,18 +454,20 @@ namespace PDF_Office.ViewModels.FillAndSign
         private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null, bool isUpData = false)
         {
 
-            if (annots != null)
+            if (annots != null&& annots.Count!=0)
             {
                 propertyPanel.annotlists = annots;
                 propertyPanel.annot = annots[0];
+
             }
             else
             {
                 propertyPanel.annotlists = null;
                 propertyPanel.annot = null;
+                return;
             }
 
-            if (annotAttribsList != null)
+            if (annotAttribsList != null && annotAttribsList.Count != 0)
             {
                 if (annots.Count > 1)
                 {
@@ -511,6 +528,43 @@ namespace PDF_Office.ViewModels.FillAndSign
 
         }
 
+        /// <summary>
+        /// 手绘
+        /// </summary>
+        private void InitSelectFreeHandAnnotMenu()
+        {
+            var popMenu = new ContextMenu();
+            PopMenu pop = new PopMenu(popMenu);
+            var menuItem = new MenuItem();
+            menuItem.Name = "FreeHandCopy";
+            menuItem.Header = "复制";
+            pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
+
+            menuItem = new MenuItem();
+            menuItem.Name = "FreeHandCut";
+            menuItem.Header = "剪切";
+            pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
+
+            menuItem = new MenuItem();
+            menuItem.Name = "FreeHandPaste";
+            menuItem.Header = "粘贴";
+            pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
+
+            menuItem = new MenuItem();
+            menuItem.Name = "FreeHandDelete";
+            menuItem.Header = "删除";
+            pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
+            pop.AddItem(GetSeparator());
+            FreeHandAnnotPopMenu = pop;
+        }
+        private Separator GetSeparator()
+        {
+            Separator separator = new Separator();
+            separator.Height = 1;
+            separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
+            separator.BorderThickness = new Thickness(1);
+            return separator;
+        }
         private void BindingPDFViewerHandler()
         {
             //来自PDFViewer的响应事件
@@ -520,6 +574,9 @@ namespace PDF_Office.ViewModels.FillAndSign
 
                 PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
                 PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
+
+                PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
+                PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
                 PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
                 PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
             }
@@ -530,8 +587,101 @@ namespace PDF_Office.ViewModels.FillAndSign
             {
                 PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
                 PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
+                PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
             }
         }
+        //在注释工具的状态下,右键菜单
+        private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
+        {
+            if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
+                return;
+
+            switch (e.CommandType)
+            {
+                case CommandType.Context:
+                    if (e.AnnotEventArgsList.Count > 0)
+                    {
+                        if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
+                        {
+                            //绑定标记密文处右键菜单
+                            events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
+                        }
+                        else
+                        {
+                            if (e.AnnotEventArgsList.Count == 1)
+                            {
+                                var selectedAnnot = e.AnnotEventArgsList[0];
+                                switch (selectedAnnot.EventType)
+                                {
+                                  
+
+                                    case AnnotArgsType.AnnotFreehand:
+                                        e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
+                                        break;
+
+                                }
+                            }
+                            else
+                            {
+                                bool isHigh = true;//是否为高亮
+                                foreach (var item in e.AnnotEventArgsList)
+                                {
+                                    if (isHightAnnot(item) == false)
+                                    {
+                                        isHigh = false;
+                                        break;
+                                    }
+                                }
+
+                                MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
+                                MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
+                                e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
+                            }
+                        }
+                        if (e.PopupMenu != null)
+                        {
+                            e.Handle = true;
+                        }
+                    }
+                    else
+                    {
+                        if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
+                        {
+          
+                            if (e.PopupMenu != null)
+                            {
+                                e.Handle = true;
+                            }
+                        }
+                        else
+                        {
+                          
+                            if (e.PopupMenu != null)
+                            {
+                                e.Handle = true;
+                            }
+                        }
+                    }
+
+                    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;
+            }
+        }
+
         private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
         {
             if (e != null && e.Count > 0)