Bladeren bron

bug-链接注释

OYXH\oyxh 2 jaren geleden
bovenliggende
commit
cb6dd2714a

+ 14 - 8
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -262,17 +262,23 @@ namespace PDF_Office.ViewModels.BOTA
                     var result = PdfViewer.RemovePageAnnot(annotation.PageIndex, annotation.AnnotIndex);
                     if (result)
                     {
-                        AnnotationListItems.Remove(annotation);
-                        var annotation1 = CurrentAnnotationLists.FirstOrDefault(x => x.PageIndex == annotation.PageIndex && x.AnnotIndex == annotation.AnnotIndex);
-                        CurrentAnnotationLists.Remove(annotation1);
-                        //记录是删除了哪些页面的注释,然后更新对应页面的注释即可
-                        UpdateAnnotListAfterDelete(annotation.PageIndex, annotation.AnnotIndex);
-                        PdfViewer.UndoManager.CanSave = true;
+                        RemoveItem(annotation);
+
                     }
                 }
             }
         }
 
+        public void RemoveItem(AnnotationHandlerEventArgs annotation)
+        {
+            AnnotationListItems.Remove(annotation);
+            var annotation1 = CurrentAnnotationLists.FirstOrDefault(x => x.PageIndex == annotation.PageIndex && x.AnnotIndex == annotation.AnnotIndex);
+            CurrentAnnotationLists.Remove(annotation1);
+            //记录是删除了哪些页面的注释,然后更新对应页面的注释即可
+            UpdateAnnotListAfterDelete(annotation.PageIndex, annotation.AnnotIndex);
+            PdfViewer.UndoManager.CanSave = true;
+        }
+
         /// <summary>
         /// 删除之后,更新
         /// </summary>
@@ -1118,9 +1124,9 @@ namespace PDF_Office.ViewModels.BOTA
                     {
                         if (item.EventType == AnnotArgsType.AnnotLink)
                         {
-                            if(item is LinkAnnotArgs link)
+                            if (item is LinkAnnotArgs link)
                             {
-                                if(link.LinkType== LINK_TYPE.URI)
+                                if (link.LinkType == LINK_TYPE.URI)
                                 {
                                     continue;
                                 }

+ 92 - 55
PDF Office/ViewModels/PropertyPanel/AnnotPanel/LinkAnnotPropertyViewModel.cs

@@ -694,11 +694,13 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             //没有选择注释工具、也不是右键添加注释
             //在阅读页,选择注释后,点击按钮
             //需要设置相关参数
-            if (AnnotAttribEvent.IsAnnotCreateReset == false)
+            if (AnnotAttribEvent.IsAnnotCreateReset == false && propertyPanel.IsAddLink == false)
             {
+                propertyPanel.IsLocationLink = true;
+
                 pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
-                pdfViewer.SetToolParam(linkAnnotArgs);
-                IsAnnotSelect = false;
+
+                pdfViewer.SetToolParam(LinkAnnotArgs);
             }
 
             pdfViewer.EnableDrawSelectArea(true);
@@ -733,12 +735,18 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>
-        private async void PDFViewer_CustomNotifyHandler(object sender, CustomNotityData e)
+        private void PDFViewer_CustomNotifyHandler(object sender, CustomNotityData e)
         {
             if (e.NotifyType == CustomNotifyType.LinkAreaLocate)
             {
                 if (e.NotifyData is AreaLocate areaInfo)
                 {
+                    if (pdfViewer.ToolManager.CurrentAnnotArgs == null)
+                    {
+                        CleanLocationState();
+
+                        return;
+                    }
                     if (pdfViewer.ToolManager.CurrentAnnotArgs.EventType == AnnotArgsType.AnnotLink && pdfViewer.MouseMode == MouseModes.AnnotCreate)
                     {
                         LinkAnnotArgs linkArgs = pdfViewer.ToolManager.CurrentAnnotArgs as LinkAnnotArgs;
@@ -750,37 +758,63 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                         historyPageIndex = linkArgs.PageIndex;
                         LinkAnnotArgs = linkArgs;
                         //LinkAnnotArgs.PageIndex = historyPageIndex;
+                        if (linkArgs.AnnotIndex != -1)
+                        {
+                            AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
+                            AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, areaInfo.PageIndex);
+                            AnnotAttribEvent?.UpdateAnnot();
 
-                        AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
-                        AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, areaInfo.PageIndex);
-                        AnnotAttribEvent?.UpdateAnnot();
+                            LinkAnnotArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
 
-                        LinkAnnotArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
+                            PageNumTextContent = (areaInfo.PageIndex + 1).ToString();
+                            SetImagePreview(areaInfo.PageIndex);
 
-                        PageNumTextContent = (areaInfo.PageIndex + 1).ToString();
-                        SetImagePreview(areaInfo.PageIndex);
+                            //viewContentViewModel.LinkAnnotTipVisibility = Visibility.Collapsed;
+                            viewContentViewModel.TipVisible = Visibility.Collapsed;
 
-                        //viewContentViewModel.LinkAnnotTipVisibility = Visibility.Collapsed;
-                        viewContentViewModel.TipVisible = Visibility.Collapsed;
-                        BtnLocationIsChecked = false;
+                            //await System.Threading.Tasks.Task.Delay(5);
+                            //SelectAnnotation();
 
-                        //没有选择注释工具、也不是右键添加注释
-                        //在阅读页,选择注释后,点击按钮
-                        //需要设置相关参数
-                        if (IsAnnotSelect == false)
-                        {
-                            pdfViewer.SetMouseMode(MouseModes.PanTool);
-                        }
+                            //pdfViewer.GoToPage(historyPageIndex);
 
-                        await System.Threading.Tasks.Task.Delay(2);
-                        SelectAnnotation();
+                            propertyPanel.IsLocationLink = false;
+                            //没有选择注释工具、也不是右键添加注释
+                            //在阅读页,选择注释后,点击按钮
+                            //需要设置相关参数
+                            if (propertyPanel.IsAddLink == false)
+                            {
+                                pdfViewer.SetMouseMode(MouseModes.PanTool);
+                            }
+                            //await System.Threading.Tasks.Task.Delay(5);
+                            pdfViewer.GoToPage(historyPageIndex);
+                            pdfViewer.SelectAnnotation(LinkAnnotArgs.PageIndex, LinkAnnotArgs.AnnotIndex);
 
-                        pdfViewer.GoToPage(historyPageIndex);
+                            BtnLocationIsChecked = false;
+                        }
+                        else
+                        {
+                            CleanLocationState();
+                            return;
+                        }
                     }
                 }
             }
         }
 
+        private void CleanLocationState()
+        {
+            viewContentViewModel.TipVisible = Visibility.Collapsed;
+            BtnLocationIsChecked = false;
+            propertyPanel.IsLocationLink = false;
+            //没有选择注释工具、也不是右键添加注释
+            //在阅读页,选择注释后,点击按钮
+            //需要设置相关参数
+            if (propertyPanel.IsAddLink == false)
+            {
+                pdfViewer.SetMouseMode(MouseModes.PanTool);
+            }
+        }
+
         /// <summary>
         /// 前往/返回按钮
         /// </summary>
@@ -893,9 +927,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         /// </summary>
         private void SelectAnnotation()
         {
-            if (linkAnnotArgs != null && !isSelected && linkAnnotArgs.AnnotIndex >= 0)
+            if (LinkAnnotArgs != null && !isSelected && LinkAnnotArgs.AnnotIndex >= 0)
             {
-                pdfViewer.SelectAnnotation(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
+                pdfViewer.SelectAnnotation(LinkAnnotArgs.PageIndex, LinkAnnotArgs.AnnotIndex);
                 isSelected = true;
             }
             else
@@ -1174,36 +1208,38 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     LinkAnnotArgs.PageIndex = pdfViewer.CurrentIndex;
                 }
             }
-            if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkUri))
-            {
-                string linkUrl = (string)AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri];
-                if (!string.IsNullOrEmpty(linkUrl))
-                {
-                    if (linkUrl.StartsWith("mailto:", StringComparison.OrdinalIgnoreCase))
-                    {
-                        SetLinkType(LINK_TYPE.URI, true);
-                        if (AnnotAttribEvent.IsAnnotCreateReset)
-                        {
-                            SetLinkEmail("");
-                        }
-                        else
-                        {
-                            SetLinkEmail(linkUrl.ToLower().TrimStart("mailto:".ToCharArray()));
-                        }
-                    }
-                    else
-                    {
-                        if (AnnotAttribEvent.IsAnnotCreateReset)
-                        {
-                            SetLinkUrl("");
-                        }
-                        else
-                        {
-                            SetLinkUrl(linkUrl);
-                        }
-                    }
-                }
-            }
+            //暂定 第一版 不显示邮箱、web链接模块
+          
+            //if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkUri))
+            //{
+            //    string linkUrl = (string)AnnotAttribEvent.Attribs[AnnotAttrib.LinkUri];
+            //    if (!string.IsNullOrEmpty(linkUrl))
+            //    {
+            //        if (linkUrl.StartsWith("mailto:", StringComparison.OrdinalIgnoreCase))
+            //        {
+            //            SetLinkType(LINK_TYPE.URI, true);
+            //            if (AnnotAttribEvent.IsAnnotCreateReset)
+            //            {
+            //                SetLinkEmail("");
+            //            }
+            //            else
+            //            {
+            //                SetLinkEmail(linkUrl.ToLower().TrimStart("mailto:".ToCharArray()));
+            //            }
+            //        }
+            //        else
+            //        {
+            //            if (AnnotAttribEvent.IsAnnotCreateReset)
+            //            {
+            //                SetLinkUrl("");
+            //            }
+            //            else
+            //            {
+            //                SetLinkUrl(linkUrl);
+            //            }
+            //        }
+            //    }
+            //}
         }
 
         private void SetLinkUrl(string url)
@@ -1255,6 +1291,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             {
                 BtnLinkPageIsChecked = true;
                 BtnGOorBackVisibility = Visibility.Collapsed;
+                viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
                 return;
             }
             switch (linkType)

+ 7 - 3
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Command.cs

@@ -232,7 +232,6 @@ namespace PDF_Office.ViewModels.Tools
                     //viewContentViewModel.IsCreateLink = false;
                     //e.IsAnnotCreateReset= true;
                     GetLink(e.AnnotItemsList, e);
-
                     break;
 
                 case AnnotArgsType.AnnotSticky:
@@ -396,7 +395,12 @@ namespace PDF_Office.ViewModels.Tools
                 if (BtnLinkIsChecked == false)
                 {
                     if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
-                        viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
+                    {
+                        if (PDFViewer.MouseMode == MouseModes.PanTool && propertyPanel.IsAddLink == false && propertyPanel.IsLocationLink == false)
+                        {
+                            viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
+                        }
+                    }
                 }
             }
         }
@@ -428,7 +432,7 @@ namespace PDF_Office.ViewModels.Tools
                                     case AnnotArgsType.AnnotUnderline:
                                     case AnnotArgsType.AnnotStrikeout:
                                     case AnnotArgsType.AnnotSquiggly:
-                                        if(selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
+                                        if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
                                         {
                                             colorContent.ItemSource = AnnotColorList.GetHighlightColorList();
                                         }

+ 45 - 18
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Function.cs

@@ -25,6 +25,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
+using System.Windows.Annotations;
 using System.Windows.Controls;
 using System.Windows.Forms;
 using System.Windows.Input;
@@ -122,7 +123,8 @@ namespace PDF_Office.ViewModels.Tools
         }
 
         //在xaml里引用
-        public Dictionary<string, string> GetToolTipDict { get { return ToolTipDict; } }
+        public Dictionary<string, string> GetToolTipDict
+        { get { return ToolTipDict; } }
 
         //用来记录选中、创建注释的标识
         private void InitToolDict()
@@ -142,7 +144,6 @@ namespace PDF_Office.ViewModels.Tools
             ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
         }
 
-
         //注释工具按钮悬浮文案
         private void InitToolTipDict()
         {
@@ -167,18 +168,16 @@ namespace PDF_Office.ViewModels.Tools
             ToolTipDict.Add("ShowAnnot", "显示/隐藏注释");
         }
 
-
         //便签批注弹窗
         private void LoaedStickyNotePopup()
         {
             if (PDFViewer == null) return;
 
-            if(customStickyPopup == null)
+            if (customStickyPopup == null)
             {
                 customStickyPopup = new StickyNotePopup();
                 PDFViewer.SetStickyNotePop(customStickyPopup);
             }
-           
         }
 
         #endregion 初始化数据
@@ -252,14 +251,13 @@ namespace PDF_Office.ViewModels.Tools
 
                 case "Link"://链接
                     viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
+                    propertyPanel.IsAddLink = true;
                     annotArgs = GetLink();
                     break;
             }
 
-            if(annotArgs != null)
-            annotArgs.Author = Settings.Default.AppProperties.Description.Author;
-
-
+            if (annotArgs != null)
+                annotArgs.Author = Settings.Default.AppProperties.Description.Author;
         }
 
         /// <summary>
@@ -670,7 +668,7 @@ namespace PDF_Office.ViewModels.Tools
                 lineArgs.LineWidth = 1;
                 lineArgs.Transparency = 1;
                 lineArgs.Content = string.Empty;
-                
+
                 if (lineArgs != null)
                 {
                     selectedArgs = new List<AnnotHandlerEventArgs>();
@@ -783,7 +781,8 @@ namespace PDF_Office.ViewModels.Tools
             if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
             {
                 AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
-
+                propertyPanel.IsAddLink = false;
+                propertyPanel.IsLocationLink = false;
                 switch (clickMenu.Tag.ToString())
                 {
                     case "HighLight"://字体高亮
@@ -861,6 +860,9 @@ namespace PDF_Office.ViewModels.Tools
                         linkArgs.LinkType = LINK_TYPE.GOTO;
                         linkArgs.DestIndex = annotCommand.PageIndex;
                         PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
+
+                        propertyPanel.IsAddLink = true;
+
                         BtnLinkIsChecked = true;
                         List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
                         lists.Add(linkArgs);
@@ -1072,7 +1074,8 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
-        System.Windows.Controls.Primitives.Popup popup = null;
+        private System.Windows.Controls.Primitives.Popup popup = null;
+
         //更改颜色
         private async void AnnotColorPalette_Menu(object obj)
         {
@@ -1086,9 +1089,9 @@ namespace PDF_Office.ViewModels.Tools
                     item.DataContext = annot;
                     item.ColorSelected -= AnnotMenu_ColorSelected;
                     item.ColorSelected += AnnotMenu_ColorSelected;
-                    
-                    if(popup == null)
-                    popup = new System.Windows.Controls.Primitives.Popup();
+
+                    if (popup == null)
+                        popup = new System.Windows.Controls.Primitives.Popup();
 
                     ContentControl window = null;
                     if (PDFViewer.Parent as ContentControl != null)
@@ -1099,11 +1102,11 @@ namespace PDF_Office.ViewModels.Tools
                     popup.Child = item;
                     popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
                     popup.Placement = System.Windows.Controls.Primitives.PlacementMode.Relative;
-                    popup.PlacementTarget = window; 
+                    popup.PlacementTarget = window;
                     popup.IsOpen = true;
 
                     Window parentWnd = Window.GetWindow(App.Current.MainWindow);
-                    if (parentWnd != null )
+                    if (parentWnd != null)
                     {
                         parentWnd.MouseDown -= parentWnd_MouseDown;
                         parentWnd.MouseDown += parentWnd_MouseDown;
@@ -1155,7 +1158,7 @@ namespace PDF_Office.ViewModels.Tools
                         AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
                         AnnotEvent?.UpdateAnnot();
                     }
-                    else if(annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
+                    else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
                     {
                         var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
                         AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
@@ -1354,6 +1357,30 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
+        private void Link_Menu(object obj)
+        {
+            if (obj is CusMenuItem menuItem)
+            {
+                if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
+                {
+                    var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
+                    if (result)
+                    {
+                        viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
+                        bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
+                        if (isTabItemAnnotation)
+                        {
+                            AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
+                            if (viewModel != null)
+                            {
+                                viewModel.UpdateModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex, true);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
         //图章
         private void StampExportPicture_Menu(object obj)
         {

+ 3 - 3
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Layout.cs

@@ -406,7 +406,7 @@ namespace PDF_Office.ViewModels.Tools
         {
             if (e == null) return;
 
-            if(sender is Ellipse)
+            if (sender is Ellipse)
             {
                 var item = new ColorDropBoxPop();
                 item.DataContext = (sender as Ellipse).DataContext;
@@ -456,7 +456,7 @@ namespace PDF_Office.ViewModels.Tools
                 }
             }
 
-            
+
         }
 
         /// <summary>
@@ -763,7 +763,7 @@ namespace PDF_Office.ViewModels.Tools
             menuItem = new MenuItem();
             menuItem.Name = "LinkDelete";
             menuItem.Header = "删除";
-            pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
+            pop.BindingEvent(pop.AddItem(menuItem), Link_MenuCommand);
             LinkAnnotPopMenu = pop;
         }
 

+ 7 - 0
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Properties.cs

@@ -23,6 +23,8 @@ namespace PDF_Office.ViewModels.Tools
     /// </summary>
     public class AnnotPropertyPanel
     {
+        public bool IsAddLink = false;
+        public bool IsLocationLink = false;
         public AnnotAttribEvent AnnotEvent { get; set; }
         public List<AnnotAttribEvent> AnnotEvents = new List<AnnotAttribEvent>();
 
@@ -240,6 +242,7 @@ namespace PDF_Office.ViewModels.Tools
                 SetProperty(ref btnHandIsChecked, value);
             }
         }
+
         private bool btnShowAnnotIsChecked = true;
 
         public bool BtnShowAnnotIsChecked
@@ -289,6 +292,7 @@ namespace PDF_Office.ViewModels.Tools
         public DelegateCommand AddBookMarkCommand { get; set; }
 
         public DelegateCommand<object> HandCommand { get; set; }
+
         #region 注释 - 右键菜单
 
         //公共
@@ -322,6 +326,9 @@ namespace PDF_Office.ViewModels.Tools
         //ESC
         public DelegateCommand EscCommand { get; set; }
 
+        //链接
+        public DelegateCommand<object> Link_MenuCommand { get; set; }
+
         #endregion 注释 - 右键菜单
 
         #endregion 事件

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

@@ -76,6 +76,7 @@ namespace PDF_Office.ViewModels.Tools
             HandCommand = new DelegateCommand<object>(Hand_Click);
             //ESC
             EscCommand = new DelegateCommand(Esc_KeyDown);
+
             #region 注释 - 右键菜单
 
             //公共command
@@ -96,6 +97,8 @@ namespace PDF_Office.ViewModels.Tools
             ShapeLineDirect_MenuCommand = new DelegateCommand<object>(ShapeLineDirect_Menu);
             //图章
             StampExportPicture_MenuCommand = new DelegateCommand<object>(StampExportPicture_Menu);
+            //链接
+            Link_MenuCommand = new DelegateCommand<object>(Link_Menu);
 
             #endregion 注释 - 右键菜单
         }
@@ -103,7 +106,6 @@ namespace PDF_Office.ViewModels.Tools
         private void Esc_KeyDown()
         {
             PDFViewer.SetMouseMode(MouseModes.None);
-
         }
 
         private void Hand_Click(object obj)
@@ -190,6 +192,8 @@ namespace PDF_Office.ViewModels.Tools
             }
             else
             {
+                propertyPanel.IsAddLink = false;
+                propertyPanel.IsLocationLink = false;
                 PDFViewer.ToolManager.EnableClickCreate = false;
             }
 
@@ -224,6 +228,8 @@ namespace PDF_Office.ViewModels.Tools
                 AnnotHandlerEventArgs annotHandler = null;
                 string str = menuItem.Tag.ToString();
                 viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
+                propertyPanel.IsAddLink = false;
+                propertyPanel.IsLocationLink = false;
                 if (str == AddAnnotType.AnnotFreehand.ToString())
                 {
                     annotHandler = GetFreehand();
@@ -254,6 +260,7 @@ namespace PDF_Office.ViewModels.Tools
                 }
                 if (str == AddAnnotType.AnnotLink.ToString())
                 {
+                    propertyPanel.IsAddLink = true;
                     annotHandler = GetLink();
                 }
                 if (str == AddAnnotType.AnnotStamp.ToString())