Browse Source

注释-链接-WEB链接初版

OYXH\oyxh 2 years ago
parent
commit
ac4b6d7c39

+ 360 - 96
PDF Office/ViewModels/PropertyPanel/AnnotPanel/LinkAnnotPropertyViewModel.cs

@@ -25,6 +25,9 @@ using PDF_Office.CustomControl;
 using System.Windows.Markup;
 using ComPDFKitViewer;
 using System.Runtime.InteropServices;
+using System.Text.RegularExpressions;
+using System.Net;
+using System.Diagnostics;
 
 namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 {
@@ -35,25 +38,26 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         private AnnotPropertyPanel PropertyPanel;
         private AnnotArgsType annotType;
 
-        private LinkAnnotArgs _annotArgs;
+        private LinkAnnotArgs annotArgs;
 
         public LinkAnnotArgs AnnotArgs
         {
             get
             {
-                return _annotArgs;
+                return annotArgs;
             }
             set
             {
-                if (_annotArgs != null)
+                if (annotArgs != null)
                 {
-                    _annotArgs.LinkDrawFinished -= _annotArgs_LinkDrawFinished;
+                    annotArgs.LinkDrawFinished -= annotArgs_LinkDrawFinished;
                 }
-                _annotArgs = value;
 
-                if (_annotArgs != null)
+                annotArgs = value;
+
+                if (annotArgs != null)
                 {
-                    _annotArgs.LinkDrawFinished += _annotArgs_LinkDrawFinished;
+                    annotArgs.LinkDrawFinished += annotArgs_LinkDrawFinished;
                 }
             }
         }
@@ -67,6 +71,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        #region 输入框的验证、设置
+
         private string pageNumTextContent;
 
         public string PageNumTextContent
@@ -84,7 +90,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     if (AnnotArgs != null)
                     {
                         AnnotArgs.DestIndex = pageNum - 1;
-                        //BtnLocationIsEnabled = true;
+
                         SetImagePreview(AnnotArgs.DestIndex);
                     }
                 }
@@ -107,7 +113,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         /// <summary>
         /// 设置预文本内容
         /// </summary>
-        private string pageNumPlaceHoldText = "Enter target page";
+        private string pageNumPlaceHoldText = "输入目标页面";
 
         public string PageNumPlaceHoldText
         {
@@ -157,6 +163,81 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        private bool pageWebTextIsEnabled = false;
+
+        public bool PageWebTextIsEnabled
+        {
+            get { return pageWebTextIsEnabled; }
+            set
+            {
+                SetProperty(ref pageWebTextIsEnabled, value);
+            }
+        }
+
+        private string pageWebPlaceHoldText = "输入您要跳转的链接";
+
+        public string PageWebPlaceHoldText
+        {
+            get { return pageWebPlaceHoldText; }
+            set
+            {
+                SetProperty(ref pageWebPlaceHoldText, value);
+            }
+        }
+
+        private Visibility showPageWebTip = Visibility.Collapsed;
+
+        public Visibility ShowPageWebTip
+        {
+            get { return showPageWebTip; }
+            set
+            {
+                SetProperty(ref showPageWebTip, value);
+            }
+        }
+
+        private string pageWebTextContent;
+
+        public string PageWebTextContent
+        {
+            get
+            {
+                if (CheckPageWebVaild(pageWebTextContent))
+                {
+                    pageWebTextContent = pageWebTextContent.Trim().ToLower();
+                    if (!pageWebTextContent.StartsWith("http://") && !pageWebTextContent.StartsWith("https://"))
+                    {
+                        pageWebTextContent = "http://" + pageWebTextContent;
+                    }
+                    if (AnnotArgs != null)
+                    {
+                        AnnotArgs.URI = pageWebTextContent;
+                    }
+                }
+
+                return pageWebTextContent;
+            }
+            set
+            {
+                SetProperty(ref pageWebTextContent, value);
+            }
+        }
+
+        private string pageWebTipText = "Invalid link.";
+
+        public string PageWebTipText
+        {
+            get { return pageWebTipText; }
+            set
+            {
+                SetProperty(ref pageWebTipText, value);
+            }
+        }
+
+        #endregion 输入框的验证、设置
+
+        #region 按钮、图片的设置
+
         private bool btnLocationIsEnabled = false;
 
         public bool BtnLocationIsEnabled
@@ -267,41 +348,25 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
-        //private Visibility errorNumTipsVisibility = Visibility.Collapsed;
-
-        //public Visibility ErrorNumTipsVisibility
-        //{
-        //    get { return errorNumTipsVisibility; }
-        //    set
-        //    {
-        //        SetProperty(ref errorNumTipsVisibility, value);
-        //    }
-        //}
-
-        //private Visibility errorRangeTipsVisibility = Visibility.Collapsed;
-
-        //public Visibility ErrorRangeTipsVisibility
-        //{
-        //    get { return errorRangeTipsVisibility; }
-        //    set
-        //    {
-        //        SetProperty(ref errorRangeTipsVisibility, value);
-        //    }
-        //}
-        private int totalPage = 0;
+        #endregion 按钮、图片的设置
 
         private bool isLoaded = false;
-        private int historyPageIndex = 0;
+        private bool isMail = false;
+        private string historyBtnGOorBackTag = string.Empty;
+        private int totalPage = 0;
         private int backPageIndex = 0;
+        private int historyPageIndex = 0;
+
         private CPDFViewer pdfViewer;
         private CPDFDocument document;
+        private Button btnGOorBack = null;
         private LinkAnnotProperty linkAnnot;
         public DelegateCommand<object> LoadedCommand { get; set; }
         public DelegateCommand<object> PageNumTextChangedCommand { get; set; }
         public DelegateCommand<object> BtnGOorBackPageCommand { get; set; }
         public DelegateCommand<object> LocationCommand { get; set; }
 
-        //public DelegateCommand<object> ToggleButtonTabCommand { get; set; }
+        public DelegateCommand<object> ToggleButtonTabCommand { get; set; }
 
         public LinkAnnotPropertyViewModel()
         {
@@ -309,30 +374,87 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             PageNumTextChangedCommand = new DelegateCommand<object>(PageNumTextChanged);
             BtnGOorBackPageCommand = new DelegateCommand<object>(BtnGOorBackPageEvent);
             LocationCommand = new DelegateCommand<object>(LocationPage);
-            //ToggleButtonTabCommand = new DelegateCommand<object>(ToggleButtonTabSelected);
+            ToggleButtonTabCommand = new DelegateCommand<object>(ToggleButtonTabSelected);
             isLoaded = true;
         }
 
+        private void ToggleButtonTabSelected(object obj)
+        {
+            if (obj is RadioButton radioButton)
+            {
+                switch (radioButton.Tag)
+                {
+                    case "Page":
+                        AnnotArgs.LinkType = LINK_TYPE.GOTO;
+                        isMail = false;
+                        if (!string.IsNullOrEmpty(historyBtnGOorBackTag))
+                        {
+                            ChangeBtnGOorBack(historyBtnGOorBackTag, btnGOorBack);
+                        }
+                        else
+                        {
+                            ChangeBtnGOorBack("GO", btnGOorBack);
+                        }
+                        BtnGOorBackVisibility = string.IsNullOrEmpty(PageNumTextContent) ? Visibility.Collapsed : Visibility.Visible;
+                        break;
+
+                    case "Web":
+                        AnnotArgs.LinkType = LINK_TYPE.URI;
+                        isMail = false;
+                        if (btnGOorBack != null)
+                        {
+                            historyBtnGOorBackTag = btnGOorBack.Tag.ToString();
+                            ChangeBtnGOorBack("GO", btnGOorBack);
+                        }
+
+                        BtnGOorBackVisibility = string.IsNullOrEmpty(PageWebTextContent) ? Visibility.Collapsed : Visibility.Visible;
+                        break;
+
+                    case "Mail":
+                        AnnotArgs.LinkType = LINK_TYPE.URI;
+                        isMail = true;
+                        if (btnGOorBack != null)
+                        {
+                            historyBtnGOorBackTag = btnGOorBack.Tag.ToString();
+                            ChangeBtnGOorBack("GO", btnGOorBack);
+                        }
+
+                        break;
+
+                    default:
+                        break;
+                }
+            }
+        }
+
+        /// <summary>
+        /// 定位
+        /// </summary>
+        /// <param name="obj"></param>
         private void LocationPage(object obj)
         {
             if (!string.IsNullOrEmpty(PageNumTextContent))
             {
-                AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
-                AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, Convert.ToInt32(PageNumTextContent) - 1);
-                AnnotAttribEvent?.UpdateAnnot();
-
-                if (AnnotArgs != null)
+                if (CheckPageNumVaild(out int pageNum, PageNumTextContent))
                 {
-                    AnnotArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
+                    AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.GOTO);
+                    AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkDestIndx, pageNum - 1);
+                    AnnotAttribEvent?.UpdateAnnot();
+
+                    AnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
                 }
             }
         }
 
+        /// <summary>
+        /// 前往/返回按钮
+        /// </summary>
+        /// <param name="obj"></param>
         private void BtnGOorBackPageEvent(object obj)
         {
             if (obj is object[] arry)
             {
-                Button btnGOorBack = arry[0] as Button;
+                btnGOorBack = arry[0] as Button;
                 RadioButton btnLinkPage = arry[1] as RadioButton;
                 RadioButton btnLinkWeb = arry[2] as RadioButton;
                 RadioButton btnLinkMail = arry[3] as RadioButton;
@@ -342,32 +464,56 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     if (btnLinkPage.IsChecked == true)
                     {
                         int pageIndex = Convert.ToInt32(PageNumTextContent) - 1;
+
                         if (btnGOorBack.Tag.ToString() == "GO")
                         {
-                            if (AnnotArgs != null)
-                            {
-                                historyPageIndex = AnnotArgs.PageIndex;
-                            }
-                            else
-                            {
-                                historyPageIndex = backPageIndex;
-                            }
+                            historyPageIndex = AnnotArgs != null ? AnnotArgs.PageIndex : backPageIndex;
                             pdfViewer.GoToPage(pageIndex);
 
                             ChangeBtnGOorBack("BACK", btnGOorBack);
-                            SetImagePreview(historyPageIndex);
+                            //SetImagePreview(historyPageIndex);
                         }
                         else
                         {
                             pdfViewer.GoToPage(historyPageIndex);
                             ChangeBtnGOorBack("GO", btnGOorBack);
-                            SetImagePreview(pageIndex);
+                            //SetImagePreview(pageIndex);
+                        }
+                    }
+
+                    if (btnLinkWeb.IsChecked == true)
+                    {
+                        if (CheckPageWebVaild(PageWebTextContent))
+                        {
+                            AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkType, LINK_TYPE.URI);
+                            PageWebTextContent = PageWebTextContent.Trim().ToLower();
+                            if (!PageWebTextContent.StartsWith("http://") && !PageWebTextContent.StartsWith("https://"))
+                            {
+                                PageWebTextContent = "http://" + PageWebTextContent;
+                            }
+                            AnnotAttribEvent?.UpdateAttrib(AnnotAttrib.LinkUri, PageWebTextContent);
+                            AnnotAttribEvent?.UpdateAnnot();
+                            AnnotArgs?.InvokeLinkSaveCalled(this, EventArgs.Empty);
+
+                            if (PageWebTextContent.StartsWith("http://") || PageWebTextContent.StartsWith("https://"))
+                            {
+                                Process.Start(PageWebTextContent);
+                            }
+                        }
+                        else
+                        {
+                            BtnGOorBackVisibility = Visibility.Collapsed;
                         }
                     }
                 }
             }
         }
 
+        /// <summary>
+        /// 设置前往/返回按钮的文本
+        /// </summary>
+        /// <param name="flag"></param>
+        /// <param name="button"></param>
         private void ChangeBtnGOorBack(string flag, Button button)
         {
             switch (flag)
@@ -406,12 +552,15 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        /// <summary>
+        /// 页码格式验证
+        /// </summary>
+        /// <param name="pageNum"></param>
+        /// <param name="text"></param>
+        /// <returns></returns>
         private bool CheckPageNumVaild(out int pageNum, string text)
         {
             pageNum = -1;
-            //ErrorNumTipsVisibility = Visibility.Collapsed;
-            //ErrorRangeTipsVisibility = Visibility.Collapsed;
-            //BtnGOorBackVisibility = Visibility.Collapsed;
             if (string.IsNullOrEmpty(text))
             {
                 return false;
@@ -420,10 +569,6 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             {
                 if (!int.TryParse(text.Trim(), out pageNum))
                 {
-                    //ErrorNumTipsVisibility = Visibility.Visible;
-                    //ErrorRangeTipsVisibility = Visibility.Collapsed;
-                    //textBox.IsError = true;
-                    //PageNumTextIsError = true;
                     ShowPageNumTip = Visibility.Visible;
                     PageNumTipText = " Page number error.";
                     return false;
@@ -431,24 +576,53 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
             if (pageNum < 1 || pageNum > totalPage)
             {
-                //ErrorNumTipsVisibility = Visibility.Collapsed;
-                //ErrorRangeTipsVisibility = Visibility.Visible;
-                //textBox.IsError = true;
-                //PageNumTextIsError = true;
                 ShowPageNumTip = Visibility.Visible;
                 PageNumTipText = "  Page number out of range.";
                 return false;
             }
             else
             {
-                //textBox.IsError = false;
-                //PageNumTextIsError = false;
                 ShowPageNumTip = Visibility.Collapsed;
             }
             BtnGOorBackVisibility = Visibility.Visible;
+
             return true;
         }
 
+        private bool CheckPageWebVaild(string text)
+        {
+            BtnGOorBackVisibility = Visibility.Collapsed;
+            if (string.IsNullOrEmpty(text))
+            {
+                return false;
+            }
+
+            string checkUrl = text.ToLower().TrimStart("http://".ToCharArray()).TrimStart("https://".ToCharArray());
+            if (!Regex.IsMatch(checkUrl, "([a-zA-Z0-9/\\-%\\?#&=]+[./\\-%\\?#&=]?)+"))
+            {
+                ShowPageWebTip = Visibility.Visible;
+                PageWebTipText = "Invalid link.";
+                return false;
+            }
+            string matchText = Regex.Match(checkUrl, "([a-zA-Z0-9/\\-%\\?#&=]+[./\\-%\\?#&=]?)+").Value;
+            if (matchText.Length != checkUrl.Length)
+            {
+                ShowPageWebTip = Visibility.Visible;
+                PageWebTipText = "Invalid link.";
+                return false;
+            }
+            else
+            {
+                ShowPageWebTip = Visibility.Collapsed;
+            }
+            BtnGOorBackVisibility = Visibility.Visible;
+            return true;
+        }
+
+        /// <summary>
+        /// 设置图像
+        /// </summary>
+        /// <param name="pageIndex"></param>
         private void SetImagePreview(int pageIndex)
         {
             ImagePreviewVisibility = Visibility.Visible;
@@ -479,10 +653,16 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             PreviewImage = WirteBitmap;
         }
 
-        private void _annotArgs_LinkDrawFinished(object sender, bool e)
+        /// <summary>
+        /// 链接画框完成时触发事件
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void annotArgs_LinkDrawFinished(object sender, bool e)
         {
             //linkAnnot.SetTextBoxEnableOrNot(e, totalPage);
             SetTextBoxEnableOrNot(e, totalPage);
+
             //AnnotArgs = (LinkAnnotArgs)PropertyPanel.annot;
         }
 
@@ -522,33 +702,31 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
                 SetTextBoxEnableOrNot(false, totalPage);
 
-                if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkType))
-                {
-                    SetLinkType((LINK_TYPE)AnnotAttribEvent.Attribs[AnnotAttrib.LinkType]);
-                }
-                if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkDestIndx) && !AnnotAttribEvent.IsAnnotCreateReset)
-                {
-                    SetLinkPageNum((int)AnnotAttribEvent.Attribs[AnnotAttrib.LinkDestIndx] + 1);
-                    if (AnnotArgs == null)
-                    {
-                        backPageIndex = pdfViewer.CurrentIndex;
-                    }
-                    else
-                    {
-                        AnnotArgs.PageIndex = pdfViewer.CurrentIndex;
-                    }
-                }
+                SetAnnotAttribute();
 
                 if (isLoaded)
                 {
                     if (pdfViewer != null && pdfViewer.ToolManager != null && pdfViewer.ToolManager.CurrentAnnotArgs?.EventType == AnnotArgsType.AnnotLink)
                     {
+                        if (btnGOorBack != null)
+                        {
+                            ChangeBtnGOorBack("GO", btnGOorBack);
+                        }
                         if (AnnotAttribEvent.IsAnnotCreateReset)
                         {
                             AnnotArgs = pdfViewer.ToolManager.CurrentAnnotArgs as LinkAnnotArgs;
+                            if (AnnotArgs == null)
+                            {
+                                backPageIndex = pdfViewer.CurrentIndex;
+                            }
+                            else
+                            {
+                                AnnotArgs.PageIndex = pdfViewer.CurrentIndex;
+                            }
                         }
                     }
                 }
+
                 if (AnnotArgs == null)
                 {
                     AnnotArgs = (LinkAnnotArgs)PropertyPanel.annot;
@@ -556,6 +734,70 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
+        private void SetAnnotAttribute()
+        {
+            if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkType))
+            {
+                SetLinkType((LINK_TYPE)AnnotAttribEvent.Attribs[AnnotAttrib.LinkType]);
+            }
+            if (AnnotAttribEvent.Attribs.ContainsKey(AnnotAttrib.LinkDestIndx) && !AnnotAttribEvent.IsAnnotCreateReset)
+            {
+                SetLinkPageNum((int)AnnotAttribEvent.Attribs[AnnotAttrib.LinkDestIndx] + 1);
+                if (AnnotArgs == null)
+                {
+                    backPageIndex = pdfViewer.CurrentIndex;
+                }
+                else
+                {
+                    AnnotArgs.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);
+                        }
+                    }
+                }
+            }
+        }
+
+        private void SetLinkUrl(string url)
+        {
+            PageWebTextContent = url;
+            PageWebTextIsEnabled = true;
+        }
+
+        private void SetLinkEmail(string email)
+        {
+        }
+
+        /// <summary>
+        /// 设置页码的数据
+        /// </summary>
+        /// <param name="pageNum"></param>
         private void SetLinkPageNum(int pageNum)
         {
             if (pageNum > 0 && pageNum <= totalPage)
@@ -564,10 +806,21 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 BtnLocationIsEnabled = true;
                 PageNumTextIsEnabled = true;
                 ImagePreviewVisibility = Visibility.Visible;
-                SetImagePreview(pageNum - 1);
+
+                //SetImagePreview(pageNum - 1);
+
+                //if (btnGOorBack != null)
+                //{
+                //    ChangeBtnGOorBack("GO", btnGOorBack);
+                //}
             }
         }
 
+        /// <summary>
+        /// 根据链接类型显示模块
+        /// </summary>
+        /// <param name="linkType"></param>
+        /// <param name="isMail"></param>
         public void SetLinkType(LINK_TYPE linkType, bool isMail = false)
         {
             BtnLinkPageIsChecked = false;
@@ -580,7 +833,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     break;
 
                 case LINK_TYPE.URI:
-                    if (isMail)
+                    if (this.isMail || isMail)
                     {
                         BtnLinkMailIsChecked = true;
                     }
@@ -601,25 +854,27 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             this.totalPage = totalPage;
 
             PageNumTextContent = string.Empty;
-            //PageWebText.Text = string.Empty;
+
+            PageWebTextContent = string.Empty;
             //PageMailText.Text = string.Empty;
 
             PageNumTextIsEnabled = enable;
-            if (PageNumTextIsEnabled == true)
-            {
-                //defaultPageNumText.Text = string.Format($"1-{totalPage}页");
-                //PageNumText.PlaceholderText = string.Format($"1-{totalPage}页");
-                PageNumPlaceHoldText = string.Format($"1-{totalPage}页");
-            }
-            else
-            {
-                //defaultPageNumText.Text = "Enter target page";
-                //PageNumText.PlaceholderText = "Enter target page";
-                PageNumPlaceHoldText = "Enter target page";
-            }
+            PageWebTextIsEnabled = enable;
+            //if (PageNumTextIsEnabled == true)
+            //{
+            //    PageNumPlaceHoldText = string.Format($"1-{totalPage}页");
+            //}
+            //else
+            //{
+            //    PageNumPlaceHoldText = "输入目标页面";
+            //}
+            PageNumPlaceHoldText = PageNumTextIsEnabled ? string.Format($"1-{totalPage}页") : "输入目标页面";
+            PageWebPlaceHoldText = PageWebTextIsEnabled ? "https://www.pdfreaderpro.com" : "输入您要跳转的链接";
+
             ShowPageNumTip = Visibility.Collapsed;
             //BorderPageNumText.Background = enable ? Brushes.White : Brushes.LightGray;
 
+            ShowPageWebTip = Visibility.Collapsed;
             //PageWebText.IsEnabled = enable;
             //BorderPageWebText.Background = enable ? Brushes.White : Brushes.LightGray;
 
@@ -627,6 +882,15 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             //BorderPageMailText.Background = enable ? Brushes.White : Brushes.LightGray;
 
             BtnLocationIsEnabled = enable;
+
+            //if (AnnotArgs.LinkType == LINK_TYPE.URI)
+            //{
+            //    BtnGOorBackVisibility = Visibility.Visible;
+            //}
+            //else
+            //{
+            //    BtnGOorBackVisibility = Visibility.Collapsed;
+            //}
             //BtnGOorBack.IsEnabled = false;
         }
 

+ 3 - 19
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Function.cs

@@ -175,19 +175,7 @@ namespace PDF_Office.ViewModels.Tools
                 linkArgs.LinkType = LINK_TYPE.GOTO;
                 linkArgs.DestIndex = -1;
             }
-
-            //if (viewCtrl.PdfViewer.Document != null)
-            //{
-            //    linkProperty.SetTotalPage(viewCtrl.PdfViewer.Document.PageCount);
-            //}
-            //linkProperty.SetLinkPageNum(linkArgs.DestIndex);
-            //linkProperty.SetLinkUrl(linkArgs.URI);
-            //linkProperty.SetLinkEmail(string.Empty);
-            //linkProperty.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(linkArgs, annotAttribsList);
-            //linkProperty.AnnotArgs = linkArgs;
-            //propertyPanel = linkProperty;
-            //annotArgs = linkArgs;
-            //viewCtrl.ShowPropertyPanel();
+            
             annotAttribsList[AnnotAttrib.LinkType] = linkArgs.LinkType;
             annotAttribsList[AnnotAttrib.LinkUri] = linkArgs.URI;
             annotAttribsList[AnnotAttrib.LinkDestIndx] = linkArgs.DestIndex;
@@ -639,16 +627,12 @@ namespace PDF_Office.ViewModels.Tools
             if (annot != null)
                 propertyPanel.annot = annot;
 
-            propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annotAttribsList);
+           
             if (annotAttribsList != null)
             {
+                propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annotAttribsList);
                 if (annot is LinkAnnotArgs && annotAttribEvent != null)
                 {
-                    //if (annotAttribEvent.IsAnnotCreateReset)
-                    //{
-                    //    propertyPanel.AnnotEvent.IsAnnotCreateReset = true;
-
-                    //}
                     propertyPanel.AnnotEvent = annotAttribEvent;
                 }
             }

+ 37 - 144
PDF Office/Views/PropertyPanel/AnnotPanel/LinkAnnotProperty.xaml

@@ -52,6 +52,8 @@
                     Width="75"
                     Height="28"
                     VerticalContentAlignment="Center"
+                    Command="{Binding ToggleButtonTabCommand}"
+                    CommandParameter="{Binding ElementName=BtnLinkPage}"
                     GroupName="LinkTab"
                     IsChecked="{Binding BtnLinkPageIsChecked}"
                     Style="{StaticResource PageViewRadioBtn}"
@@ -87,6 +89,8 @@
                     Height="28"
                     VerticalContentAlignment="Center"
                     Background="Transparent"
+                    Command="{Binding ToggleButtonTabCommand}"
+                    CommandParameter="{Binding ElementName=BtnLinkWeb}"
                     GroupName="LinkTab"
                     IsChecked="{Binding BtnLinkWebIsChecked}"
                     Style="{StaticResource PageViewRadioBtn}"
@@ -127,6 +131,8 @@
                     Height="28"
                     VerticalContentAlignment="Center"
                     Background="Transparent"
+                    Command="{Binding ToggleButtonTabCommand}"
+                    CommandParameter="{Binding ElementName=BtnLinkMail}"
                     GroupName="LinkTab"
                     IsChecked="{Binding BtnLinkMailIsChecked}"
                     Style="{StaticResource PageViewRadioBtn}"
@@ -168,41 +174,26 @@
                         LineHeight="20"
                         Text="Page" />
                     <StackPanel Orientation="Horizontal">
-                        <Grid>
-                            <!--<CustomControl:TextBoxEx
+                        <CustomControl:TextBoxWithTip
                             x:Name="PageNumText"
                             Width="228"
-                            Height="32"
                             Margin="16,0"
                             VerticalContentAlignment="Center"
-                            IsEnabled="False"
-                            PlaceholderText="Enter target page">
-                            <i:Interaction.Triggers>
-                            <i:EventTrigger EventName="TextChanged">
-                            <i:InvokeCommandAction Command="{Binding PageNumTextChangedCommand}" PassEventArgsToCommand="True" />
-                            </i:EventTrigger>
-                            </i:Interaction.Triggers>
-                            </CustomControl:TextBoxEx>-->
-                            <CustomControl:TextBoxWithTip
-                                x:Name="PageNumText"
-                                Width="228"
-                                Margin="16,0"
-                                VerticalContentAlignment="Center"
-                                IsEnabled="{Binding PageNumTextIsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
-                                IsError="{Binding ElementName=PageNumText, Path=ShowTip, Converter={StaticResource VisibleToBoolConvert}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
-                                PlaceHoldText="{Binding PageNumPlaceHoldText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
-                                ShowTip="{Binding ShowPageNumTip, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
-                                Text="{Binding PageNumTextContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
-                                TipText="{Binding PageNumTipText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
-                        </Grid>
+                            IsEnabled="{Binding PageNumTextIsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            IsError="{Binding ElementName=PageNumText, Path=ShowTip, Converter={StaticResource VisibleToBoolConvert}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            PlaceHoldText="{Binding PageNumPlaceHoldText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            ShowTip="{Binding ShowPageNumTip, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            Text="{Binding PageNumTextContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            TipText="{Binding PageNumTipText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                     </StackPanel>
                     <Button
                         Name="BtnLocation"
                         Width="228"
                         Height="32"
                         Margin="16,16,16,0"
+                        Command="{Binding LocationCommand}"
                         IsEnabled="{Binding BtnLocationIsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
-                        Style="{StaticResource btn.sec-icon}" Command="{Binding LocationCommand}">
+                        Style="{StaticResource btn.sec-icon}">
                         <Button.Content>
                             <StackPanel Orientation="Horizontal">
                                 <Path
@@ -232,66 +223,19 @@
                         Foreground="#616469"
                         LineHeight="20"
                         Text="URL" />
-                    <Grid>
-                        <Border
-                            Name="BorderPageWebText"
+                    <StackPanel Orientation="Horizontal">
+                        <CustomControl:TextBoxWithTip
+                            x:Name="PageWebText"
                             Width="228"
-                            Height="32"
                             Margin="16,0"
-                            Background="#FFFFFF"
-                            BorderBrush="#1770F4"
-                            BorderThickness="1"
-                            CornerRadius="4">
-                            <TextBox
-                                Name="PageWebText"
-                                VerticalContentAlignment="Center"
-                                Background="Transparent"
-                                BorderThickness="0"
-                                IsEnabled="True" />
-                        </Border>
-                        <TextBlock
-                            x:Name="defaultPageWebText"
-                            Margin="25,0,0,0"
-                            VerticalAlignment="Center"
-                            FontSize="14"
-                            Foreground="Gray"
-                            IsHitTestVisible="False"
-                            Visibility="{Binding ElementName=PageWebText, Path=Text, Converter={StaticResource StringToUnVisibleConvert}, Mode=OneWay}">
-                            https://www.pdfreaderpro.com
-                        </TextBlock>
-                        <Button
-                            Width="18"
-                            Height="18"
-                            Margin="0,0,18,0"
-                            HorizontalAlignment="Right"
-                            VerticalAlignment="Center"
-                            Background="Transparent"
-                            Tag="PageWebText"
-                            Visibility="{Binding ElementName=PageWebText, Path=Text, Converter={StaticResource StringToVisibleConvert}}">
-                            <Button.Content>
-                                <Path Fill="#333333">
-                                    <Path.Data>
-                                        M9.48528137,2.98528137 L9.48428137,8.48428137 L14.9852814,8.48528137 L14.9852814,9.48528137 L9.48428137,9.48428137 L9.48528137,14.9852814 L8.48528137,
-                                        14.9852814 L8.48428137,9.48428137 L2.98528137,9.48528137 L2.98528137,8.48528137 L8.48428137,8.48428137 L8.48528137,2.98528137 L9.48528137,2.98528137 Z
-                                    </Path.Data>
-                                    <Path.RenderTransform>
-                                        <TransformGroup>
-                                            <TranslateTransform X="-8" />
-                                            <RotateTransform Angle="45" />
-                                            <TranslateTransform X="13" />
-                                        </TransformGroup>
-                                    </Path.RenderTransform>
-                                </Path>
-                            </Button.Content>
-                        </Button>
-                    </Grid>
-                    <TextBlock
-                        Name="ErrorUrlTips"
-                        Margin="12,0,0,0"
-                        Foreground="Red"
-                        Visibility="Collapsed">
-                        Invalid link.
-                    </TextBlock>
+                            VerticalContentAlignment="Center"
+                            IsEnabled="{Binding PageWebTextIsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            IsError="{Binding ElementName=PageWebText, Path=ShowTip, Converter={StaticResource VisibleToBoolConvert}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            PlaceHoldText="{Binding PageWebPlaceHoldText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            ShowTip="{Binding ShowPageWebTip, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            Text="{Binding PageWebTextContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            TipText="{Binding PageWebTipText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                    </StackPanel>
                 </StackPanel>
                 <StackPanel Name="LinkMailPanel" Visibility="{Binding ElementName=BtnLinkMail, Path=IsChecked, Converter={StaticResource BoolToVisible}, Mode=OneWay}">
                     <TextBlock
@@ -302,70 +246,19 @@
                         Foreground="#616469"
                         LineHeight="20"
                         Text="Email" />
-                    <Grid>
-                        <Border
-                            Name="BorderPageMailText"
+                    <StackPanel Orientation="Horizontal">
+                        <CustomControl:TextBoxWithTip
+                            x:Name="PageMailText"
                             Width="228"
-                            Height="32"
                             Margin="16,0"
-                            Background="#FFFFFF"
-                            BorderBrush="#1770F4"
-                            BorderThickness="1"
-                            CornerRadius="4">
-                            <TextBox
-                                Name="PageMailText"
-                                Width="232"
-                                Height="32"
-                                HorizontalAlignment="Left"
-                                VerticalContentAlignment="Center"
-                                Background="Transparent"
-                                BorderBrush="Transparent"
-                                IsEnabled="False" />
-                        </Border>
-                        <TextBlock
-                            x:Name="defaultPageMailText"
-                            Margin="25,0,0,0"
-                            VerticalAlignment="Center"
-                            FontSize="14"
-                            Foreground="Gray"
-                            IsHitTestVisible="False"
-                            Visibility="{Binding ElementName=PageMailText, Path=Text, Converter={StaticResource StringToUnVisibleConvert}, Mode=OneWay}">
-                            support@pdfreaderpro.com
-                        </TextBlock>
-                        <Button
-                            Width="18"
-                            Height="18"
-                            Margin="0,0,18,0"
-                            HorizontalAlignment="Right"
-                            VerticalAlignment="Center"
-                            Background="Transparent"
-                            Tag="PageMailText"
-                            Visibility="{Binding ElementName=PageMailText, Path=Text, Converter={StaticResource StringToVisibleConvert}}">
-                            <Button.Content>
-                                <Path Fill="#333333">
-                                    <Path.Data>
-                                        M9.48528137,2.98528137 L9.48428137,8.48428137 L14.9852814,8.48528137 L14.9852814,9.48528137 L9.48428137,9.48428137 L9.48528137,14.9852814 L8.48528137,
-                                        14.9852814 L8.48428137,9.48428137 L2.98528137,9.48528137 L2.98528137,8.48528137 L8.48428137,8.48428137 L8.48528137,2.98528137 L9.48528137,2.98528137 Z
-                                    </Path.Data>
-                                    <Path.RenderTransform>
-                                        <TransformGroup>
-                                            <TranslateTransform X="-8" />
-                                            <RotateTransform Angle="45" />
-                                            <TranslateTransform X="13" />
-                                        </TransformGroup>
-                                    </Path.RenderTransform>
-                                </Path>
-                            </Button.Content>
-                        </Button>
-                    </Grid>
-                    <TextBlock
-                        Name="ErrorMailTips"
-                        Margin="12,0,0,0"
-                        Foreground="Red"
-                        TextWrapping="Wrap"
-                        Visibility="Collapsed">
-                        The email is invalid.Please enter a valid email address.
-                    </TextBlock>
+                            VerticalContentAlignment="Center"
+                            IsEnabled="{Binding PageMailTextIsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            IsError="{Binding ElementName=PageMailText, Path=ShowTip, Converter={StaticResource VisibleToBoolConvert}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            PlaceHoldText="{Binding PageMailPlaceHoldText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            ShowTip="{Binding ShowPageMailTip, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            Text="{Binding PageMailTextContent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                            TipText="{Binding PageMailTipText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                    </StackPanel>
                 </StackPanel>
             </Grid>
             <Button

+ 28 - 30
PDF Office/Views/PropertyPanel/AnnotPanel/LinkAnnotProperty.xaml.cs

@@ -28,40 +28,38 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
             InitializeComponent();
         }
 
-        internal void SetTextBoxEnableOrNot(bool enable, int totalPage)
-        {
-            TotalPage = totalPage;
-
-            PageNumText.Text = string.Empty;
-            PageWebText.Text = string.Empty;
-            PageMailText.Text = string.Empty;
+        //internal void SetTextBoxEnableOrNot(bool enable, int totalPage)
+        //{
+        //    TotalPage = totalPage;
 
-            PageNumText.IsEnabled = enable;
-            if (PageNumText.IsEnabled == true)
-            {
-                //defaultPageNumText.Text = string.Format($"1-{totalPage}页");
-                //PageNumText.PlaceholderText = string.Format($"1-{totalPage}页");
-                PageNumText.PlaceHoldText = string.Format($"1-{totalPage}页");
-            }
-            else
-            {
-                //defaultPageNumText.Text = "Enter target page";
-                //PageNumText.PlaceholderText = "Enter target page";
-                PageNumText.PlaceHoldText = "Enter target page";
-            }
-            PageNumText.IsError = false;
-            //BorderPageNumText.Background = enable ? Brushes.White : Brushes.LightGray;
+        //    PageNumText.Text = string.Empty;
+        //    PageWebText.Text = string.Empty;
+        //    PageMailText.Text = string.Empty;
 
-            PageWebText.IsEnabled = enable;
-            BorderPageWebText.Background = enable ? Brushes.White : Brushes.LightGray;
+        //    PageNumText.IsEnabled = enable;
+        //    if (PageNumText.IsEnabled == true)
+        //    {
+        //        //defaultPageNumText.Text = string.Format($"1-{totalPage}页");
+        //        //PageNumText.PlaceholderText = string.Format($"1-{totalPage}页");
+        //        PageNumText.PlaceHoldText = string.Format($"1-{totalPage}页");
+        //    }
+        //    else
+        //    {
+        //        //defaultPageNumText.Text = "Enter target page";
+        //        //PageNumText.PlaceholderText = "Enter target page";
+        //        PageNumText.PlaceHoldText = "Enter target page";
+        //    }
+        //    PageNumText.IsError = false;
+        //    //BorderPageNumText.Background = enable ? Brushes.White : Brushes.LightGray;
 
-            PageMailText.IsEnabled = enable;
-            BorderPageMailText.Background = enable ? Brushes.White : Brushes.LightGray;
-
-            BtnGOorBack.IsEnabled = false;
-            //BtnLocation.IsEnabled = enable;
-        }
+        //    PageWebText.IsEnabled = enable;
+        //    BorderPageWebText.Background = enable ? Brushes.White : Brushes.LightGray;
 
+        //    PageMailText.IsEnabled = enable;
+        //    BorderPageMailText.Background = enable ? Brushes.White : Brushes.LightGray;
 
+        //    BtnGOorBack.IsEnabled = false;
+        //    //BtnLocation.IsEnabled = enable;
+        //}
     }
 }