Переглянути джерело

【2025】【Edit】Link模式调整

niehaoyu 2 місяців тому
батько
коміт
5d75885469

+ 1 - 1
PDF Office/KMComponentLibrary/KMComponentLibrary/View/Input/ComponentTextarea/ComponentTextarea.swift

@@ -189,7 +189,7 @@ public class ComponentTextarea: ComponentBaseXibView {
     }
     
     public override func mouseDown(with event: NSEvent) {
-        super.mouseDown(with: event)
+//        super.mouseDown(with: event)
     
     }
     

+ 30 - 51
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/KMLinkViewController/KMLinkViewController.swift

@@ -127,6 +127,10 @@ import KMComponentLibrary
         if annotations.count == 0 {
             emptyContendView.isHidden = false
             
+            linkWebView.clearData()
+            
+            linkEmailView.clearData()
+            
         } else if annotations.count == 1 {
             
             current_Annotation = annotations.first
@@ -207,24 +211,8 @@ import KMComponentLibrary
             linkPageView.reloadData()
         } else if pdfLinkType == .Web {
             linkWebView.isHidden = false
-            linkWebView.annotation = current_Annotation
-            
-            if let url = current_Annotation?.url() {
-                if url.hasPrefix("mailto:") == true {
-                    linkWebView.inputTextarea.properties.text = ""
-                    linkWebView.inputTextarea.reloadData()
-                }
-            }
         } else if pdfLinkType == .Email {
             linkEmailView.isHidden = false
-            linkEmailView.annotation = current_Annotation
-            
-            if let url = current_Annotation?.url() {
-                if url.hasPrefix("mailto:") == false {
-                    linkEmailView.inputTextarea.properties.text = ""
-                    linkEmailView.inputTextarea.reloadData()
-                }
-            }
         }
     }
     
@@ -240,20 +228,36 @@ import KMComponentLibrary
 //MARK: - ComponentTabsDelegate
 extension KMLinkViewController: ComponentTabsDelegate {
     public func componentTabsDidSelected(_ view: ComponentTabs, _ property: ComponentTabsProperty) {
-        if property == pageProperty {
-            pdfLinkType = .Page
-        } else if property == webProperty {
-            pdfLinkType = .Web
-        } else if property == emailProperty {
-            pdfLinkType = .Email
-        }
-        
         if let annotation = current_Annotation {
+            if property == pageProperty {
+                pdfLinkType = .Page
+                annotation.setURL(nil)
+                
+                if let page = pdfView?.document.page(at: UInt(linkPageView.choosedIndex-1)) {
+                    let bounds = page.bounds(for: .cropBox)
+                    let destination = CPDFDestination(page: page, at: NSPoint(x: 0, y: bounds.size.height))
+                    annotation.setDestination(destination)
+                }
+                
+            } else if property == webProperty {
+                pdfLinkType = .Web
+                annotation.setDestination(nil)
+                
+                let linkUrlPath = KMNTools.judgeWebURL(linkWebView.inputTextarea.properties.text)
+                annotation.setURL(linkUrlPath)
+                
+            } else if property == emailProperty {
+                pdfLinkType = .Email
+                annotation.setDestination(nil)
+                
+                let linkUrlPath = KMNTools.judgeEmailURL(linkEmailView.inputTextarea.properties.text)
+                annotation.setURL(linkUrlPath)
+            }
+            
             pdfLinkTypeChanged()
+            
         }
-        
         CPDFLinkAnnotation.updateDefault_AddLinkType(pdfLinkType.rawValue)
-        
     }
 }
 
@@ -264,23 +268,6 @@ extension KMLinkViewController: KMLinkPageViewDelegate {
             pdfView?.go(toPageIndex: pageIndex-1, animated: false)
         }
     }
-    
-    func kmLinkPageViewDidChangeDestination(_ view: KMLinkPageView, _ pageIndex: Int) {
-        guard let activiteAnno = current_Annotation else {
-            return
-        }
-        activiteAnno.setURL(nil)
-        
-        if let page = pdfView?.document.page(at: UInt(pageIndex-1)) {
-            let bounds = page.bounds(for: .cropBox)
-            let destination = CPDFDestination(page: page, at: NSPoint(x: 0, y: bounds.size.height))
-            activiteAnno.setDestination(destination)
-        }
-        
-        if let _ = pdfView?.document.page(at: UInt(pageIndex-1)) {
-            pdfView?.go(toPageIndex: pageIndex-1, animated: false)
-        }
-    }
 }
 
 //MARK: - KMLinkPageViewDelegate
@@ -289,10 +276,6 @@ extension KMLinkViewController: KMLinkWebViewDelegate {
         guard let activeAnnotation = current_Annotation else {
             return
         }
-        activeAnnotation.setDestination(nil)
-        
-        let linkUrlPath = KMNTools.judgeWebURL(webString)
-        activeAnnotation.setURL(linkUrlPath)
         
         if let url = activeAnnotation.url() {
             if let data = URL(string: url) {
@@ -317,10 +300,6 @@ extension KMLinkViewController: KMLinkEmailViewDelegate {
             alert.runModal()
             return
         }
-        activeAnnotation.setDestination(nil)
-        
-        let linkUrlPath = KMNTools.judgeEmailURL(emailString)
-        activeAnnotation.setURL(linkUrlPath)
         
         if let url = activeAnnotation.url() {
             NSWorkspace.shared.open(URL(string: url)!)

+ 7 - 5
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/KMLinkViewController/Views/KMLinkEmailView/KMLinkEmailView.swift

@@ -74,10 +74,8 @@ public class KMLinkEmailView: BaseXibView {
         guard let annotation = self.annotation else {
             return
         }
-        if var urlString = annotation.url() {
-            if urlString.hasPrefix("mailto:") {
-                urlString = urlString.substring(form: 7)
-            }
+        if var urlString = annotation.url(), urlString.hasPrefix("mailto:") {
+             urlString = urlString.substring(form: 7)
              inputTextarea.properties.text = urlString
         } else {
             inputTextarea.properties.text = ""
@@ -86,6 +84,11 @@ public class KMLinkEmailView: BaseXibView {
         
     }
     
+    func clearData() {
+        inputTextarea.properties.text = ""
+        inputTextarea.reloadData()
+    }
+    
     //MARK: - Action
     @objc func buttonClicked(_ sender: NSView) {
         delegate?.kmLinkEmailViewDidGo?(self, inputTextarea.properties.text)
@@ -118,7 +121,6 @@ extension KMLinkEmailView: ComponentTextareaDelegate {
             let linkUrlPath = KMNTools.judgeEmailURL(view.properties.text)
             annotation.setURL(linkUrlPath)
             
-            annotation.setDestination(nil)
         }
     }
     

+ 25 - 16
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/KMLinkViewController/Views/KMLinkPageView/KMLinkPageView.swift

@@ -11,9 +11,7 @@ import KMComponentLibrary
 @objc public protocol KMLinkPageViewDelegate: AnyObject {
     
     @objc optional func kmLinkPageViewDidGoToPage(_ view: KMLinkPageView, _ pageIndex: Int)
-    
-    @objc optional func kmLinkPageViewDidChangeDestination(_ view: KMLinkPageView, _ pageIndex: Int)
- 
+     
 }
  
 public class KMLinkPageView: BaseXibView {
@@ -31,7 +29,7 @@ public class KMLinkPageView: BaseXibView {
     
     var annotation: CPDFLinkAnnotation? = nil
     
-    var startPageIndex: Int = 0
+//    var startPageIndex: Int = 0
     var choosedIndex: Int = 0
     var isGo: Bool = false
 
@@ -89,8 +87,7 @@ public class KMLinkPageView: BaseXibView {
                                                       keepPressState: false)
         goButton.setTarget(self, action: #selector(buttonClicked(_:)))
     }
-    
-    
+     
     func reloadData() {
         guard let pdfView = self.pdfView else {
             return
@@ -107,13 +104,12 @@ public class KMLinkPageView: BaseXibView {
         paginationView.properties.totalCount = Int(pdfView.document.pageCount)
         paginationView.reloadData()
         
-        isGo = false
-        goButton.properties.buttonText = KMLocalizedString("Go")
-        
         choosedIndex = paginationView.properties.currentIndex
-        startPageIndex = paginationView.properties.currentIndex
+//        startPageIndex = paginationView.properties.currentIndex
          
         refreshPage()
+        
+        refreshGoButton()
     }
     
     func refreshPage() {
@@ -130,6 +126,14 @@ public class KMLinkPageView: BaseXibView {
     }
     
     func refreshGoButton() {
+        //当前页码等于PDF阅读页,显示Back
+        //当前页码不等于PDF阅读页,显示Go,
+        if choosedIndex != (pdfView?.currentPageIndex ?? 0) + 1 {
+            isGo = false
+        } else {
+            isGo = true
+        }
+        
         if isGo {
             goButton.properties.buttonText = KMLocalizedString("Back")
         } else {
@@ -140,12 +144,13 @@ public class KMLinkPageView: BaseXibView {
     }
     
     @objc func buttonClicked(_ sender: NSView) {
-        if isGo == false {
-            delegate?.kmLinkPageViewDidChangeDestination?(self, choosedIndex)
-            isGo = true
+        if isGo == true {
+            if let annotation = annotation {
+                delegate?.kmLinkPageViewDidGoToPage?(self, Int(annotation.pageIndex()) + 1)
+            }
         } else {
-            delegate?.kmLinkPageViewDidGoToPage?(self, startPageIndex)
-            isGo = false
+            delegate?.kmLinkPageViewDidGoToPage?(self, choosedIndex)
+ 
         }
         refreshGoButton()
         
@@ -167,7 +172,11 @@ extension KMLinkPageView: ComponentPaginationDelegate {
         if choosedIndex != pagination.properties.currentIndex {
             choosedIndex = pagination.properties.currentIndex
             
-            isGo = false
+            if let page = pdfView?.document.page(at: UInt(choosedIndex-1)), let annotation = annotation {
+                let bounds = page.bounds(for: .cropBox)
+                let destination = CPDFDestination(page: page, at: NSPoint(x: 0, y: bounds.size.height))
+                annotation.setDestination(destination)
+            }
             
             refreshPage()
             

+ 6 - 2
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/KMLinkViewController/Views/KMLinkWebView/KMLinkWebView.swift

@@ -74,7 +74,7 @@ public class KMLinkWebView: BaseXibView {
         guard let annotation = self.annotation else {
             return
         }
-        if let urlString = annotation.url() {
+        if let urlString = annotation.url(), urlString.hasPrefix("mailto:") == false {
             inputTextarea.properties.text = urlString
         } else {
             inputTextarea.properties.text = ""
@@ -82,6 +82,11 @@ public class KMLinkWebView: BaseXibView {
         inputTextarea.reloadData()
     }
     
+    func clearData() {
+        inputTextarea.properties.text = ""
+        inputTextarea.reloadData()
+    }
+    
     //MARK: - Action
     @objc func buttonClicked(_ sender: NSView) {
         delegate?.kmLinkWebViewDidGo?(self, inputTextarea.properties.text)
@@ -113,7 +118,6 @@ extension KMLinkWebView: ComponentTextareaDelegate {
             let linkUrlPath = KMNTools.judgeWebURL(view.properties.text)
             annotation.setURL(linkUrlPath)
             
-            annotation.setDestination(nil)
         }
         
     }