Browse Source

【2025】【Edit】Link模式完善

niehaoyu 1 month ago
parent
commit
9eb195828a

+ 8 - 8
PDF Office/KMComponentLibrary/KMComponentLibrary/View/Input/ComponentTextarea/ComponentTextarea.xib

@@ -28,6 +28,14 @@
                         <rect key="frame" x="0.0" y="0.0" width="320" height="80"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
+                            <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="BBq-kb-UpR">
+                                <rect key="frame" x="6" y="56" width="37" height="16"/>
+                                <textFieldCell key="cell" lineBreakMode="clipping" placeholderString="Label" id="aTc-ny-qsk">
+                                    <font key="font" metaFont="system"/>
+                                    <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                                    <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                                </textFieldCell>
+                            </textField>
                             <scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Tm5-i8-1qu">
                                 <rect key="frame" x="4" y="24" width="312" height="48"/>
                                 <clipView key="contentView" drawsBackground="NO" id="47F-UF-VwW">
@@ -54,14 +62,6 @@
                                     <autoresizingMask key="autoresizingMask"/>
                                 </scroller>
                             </scrollView>
-                            <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="BBq-kb-UpR">
-                                <rect key="frame" x="6" y="56" width="37" height="16"/>
-                                <textFieldCell key="cell" lineBreakMode="clipping" placeholderString="Label" id="aTc-ny-qsk">
-                                    <font key="font" metaFont="system"/>
-                                    <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
-                                    <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                </textFieldCell>
-                            </textField>
                             <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="CsS-4i-87N">
                                 <rect key="frame" x="281" y="8" width="33" height="16"/>
                                 <textFieldCell key="cell" lineBreakMode="clipping" title="0/50" id="Y4G-Z9-Qd2">

+ 5 - 3
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFLinkAnnotation+PDFListView.swift

@@ -20,18 +20,20 @@ import Foundation
     convenience init(PDFListViewNoteWith document: CPDFDocument, page: CPDFPage) {
         self.init(document: document)
         
-        if CPDFLinkAnnotation.default_Add_LinkType() == .Page {
+        let defaultType: PDFLinkType = CPDFLinkAnnotation.default_Add_LinkType()
+        
+        if defaultType == .Page {
             let bounds = page.bounds(for: .cropBox)
             let destination = CPDFDestination(page: page, at: NSPoint(x: 0, y: bounds.size.height))
             self.setDestination(destination)
             
             self.setURL(nil)
             
-        } else if CPDFLinkAnnotation.default_Add_LinkType() == .Web {
+        } else if defaultType == .Web {
             self.setDestination(nil)
             self.setURL("")
             
-        } else if CPDFLinkAnnotation.default_Add_LinkType() == .Email {
+        } else if defaultType == .Email {
             self.setDestination(nil)
             self.setURL("")
             

+ 21 - 3
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/KMLinkViewController/KMLinkViewController.swift

@@ -29,6 +29,11 @@ import KMComponentLibrary
  - 输入文字:修改跳转内容。
  */
 
+@objc protocol KMLinkViewControllerDelegate: AnyObject {
+    
+    @objc optional func kmLinkViewControllerDidUpdateMode(_ controller: KMLinkViewController)
+}
+
 //MARK: - KMLinkViewController
 @objcMembers class KMLinkViewController: NSViewController {
     
@@ -56,6 +61,8 @@ import KMComponentLibrary
     let webProperty = ComponentTabsProperty(tabsType: .underline_Fill, state: .normal, showIcon: false, title: NSLocalizedString("Web", comment: ""))
     let emailProperty = ComponentTabsProperty(tabsType: .underline_Fill, state: .normal, showIcon: false, title: NSLocalizedString("Email", comment: ""))
     
+    weak open var delegate: KMLinkViewControllerDelegate?
+    
     public override func viewDidLoad() {
         super.viewDidLoad()
         // Do view setup here.
@@ -122,18 +129,26 @@ import KMComponentLibrary
             }
         }
         annotations = linkAnnotations
-        current_Annotation = nil
         
         if annotations.count == 0 {
             emptyContendView.isHidden = false
             
+            current_Annotation = nil
+            linkPageView.clearData()
             linkWebView.clearData()
-            
             linkEmailView.clearData()
             
         } else if annotations.count == 1 {
             
-            current_Annotation = annotations.first
+            if let annotation = annotations.first {
+                if current_Annotation != annotation {
+                    current_Annotation = annotation
+                    
+                    linkPageView.clearData()
+                    linkWebView.clearData()
+                    linkEmailView.clearData()
+                }
+            }
             
             multiController.view.isHidden = true
             typeContendView.isHidden = false
@@ -258,6 +273,9 @@ extension KMLinkViewController: ComponentTabsDelegate {
             
         }
         CPDFLinkAnnotation.updateDefault_AddLinkType(pdfLinkType.rawValue)
+        
+        delegate?.kmLinkViewControllerDidUpdateMode?(self)
+        
     }
 }
 

+ 12 - 8
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/KMLinkViewController/Views/KMLinkPageView/KMLinkPageView.swift

@@ -87,6 +87,10 @@ public class KMLinkPageView: BaseXibView {
                                                       keepPressState: false)
         goButton.setTarget(self, action: #selector(buttonClicked(_:)))
     }
+    
+    func clearData() {
+        self.isGo = false
+    }
      
     func reloadData() {
         guard let pdfView = self.pdfView else {
@@ -128,11 +132,11 @@ public class KMLinkPageView: BaseXibView {
     func refreshGoButton() {
         //当前页码等于PDF阅读页,显示Back
         //当前页码不等于PDF阅读页,显示Go,
-        if choosedIndex != (pdfView?.currentPageIndex ?? 0) + 1 {
-            isGo = false
-        } else {
-            isGo = true
-        }
+//        if choosedIndex != (pdfView?.currentPageIndex ?? 0) + 1 {
+//            isGo = false
+//        } else {
+//            isGo = true
+//        }
         
         if isGo {
             goButton.properties.buttonText = KMLocalizedString("Back")
@@ -144,13 +148,13 @@ public class KMLinkPageView: BaseXibView {
     }
     
     @objc func buttonClicked(_ sender: NSView) {
+        isGo = !isGo
         if isGo == true {
+            delegate?.kmLinkPageViewDidGoToPage?(self, choosedIndex)
+        } else {
             if let annotation = annotation {
                 delegate?.kmLinkPageViewDidGoToPage?(self, Int(annotation.pageIndex()) + 1)
             }
-        } else {
-            delegate?.kmLinkPageViewDidGoToPage?(self, choosedIndex)
- 
         }
         refreshGoButton()
         

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

@@ -80,6 +80,12 @@ public class KMLinkWebView: BaseXibView {
             inputTextarea.properties.text = ""
         }
         inputTextarea.reloadData()
+        
+        if inputTextarea.properties.text.count > 0 {
+            goButton.isHidden = false
+        } else {
+            goButton.isHidden = true
+        }
     }
     
     func clearData() {

+ 2 - 0
PDF Office/PDF Master/KMClass/KMPDFViewController/KMMainViewController.swift

@@ -4162,6 +4162,8 @@ extension KMMainViewController: KMRightSideControllerDelegate {
                 cropVC.reloadData()
             }
         }
+        
+        reloadPopUIWindow()
     }
     
     func kmRightSideControllerOCRShowTypeChange(_ controller: KMRightSideController, _ type: KMOCRShowType) {

+ 10 - 1
PDF Office/PDF Master/KMClass/KMPDFViewController/RightSideController/KMRightSideController.swift

@@ -262,6 +262,7 @@ class KMRightSideController: NSViewController {
                 if edit_linkController == nil {
                     edit_linkController = KMLinkViewController.init()
                 }
+                edit_linkController?.delegate = self
                 edit_linkController?.pdfView = self.pdfView
                 contentViewController = edit_linkController
             } else if subToolMode == .Edit_Crop {
@@ -779,13 +780,14 @@ class KMRightSideController: NSViewController {
     
 }
 
-
+//MARK: - KMStampListControllerDelegate
 extension KMRightSideController: KMStampListControllerDelegate {
     func kmStampListControllerDidStampTypeUpdated(_ controller: KMStampListController) {
         reloadTopRightButtonInfo()
     }
 }
 
+//MARK: - KMStampControllerDelegate
 extension KMRightSideController: KMStampControllerDelegate {
     func kmStampControllerRotateLeft(_ annotations: [CPDFStampAnnotation], withPDFView pdfView: CPDFListView?) {
         delegate?.kmRightSideControllerRotateLeft(annotations, withPDFView: pdfView)
@@ -797,3 +799,10 @@ extension KMRightSideController: KMStampControllerDelegate {
 }
 
 
+//MARK: - KMLinkViewControllerDelegate
+extension KMRightSideController: KMLinkViewControllerDelegate {
+    func kmLinkViewControllerDidUpdateMode(_ controller: KMLinkViewController) {
+        delegate?.kmRightSideControllerDidContendVCUpdated?(self)
+        
+    }
+}

+ 10 - 9
PDF Office/PDF Master/KMClass/PDFListView/WindowController/KMNPopAnnotationWindowController.swift

@@ -1029,15 +1029,6 @@ extension KMNPopAnnotationWindowController: ComponentInputDelegate {
             }
             
             updatePDFViewCallback?()
-        } else if (inputView == urlInput) {
-        }
-    }
-    
-    func componentInputDidEndEditing(inputView: ComponentInput) {
-        if (inputView == fildNameInput) {
-          
-        } else if (inputView == gropNameInput) {
-           
         } else if (inputView == urlInput) {
             if linkType == .email {
                 let emailString = urlInput.properties.text
@@ -1057,6 +1048,16 @@ extension KMNPopAnnotationWindowController: ComponentInputDelegate {
                 linkAnnotation.setURL(linkUrlPath)
                 updatePDFViewCallback?()
             }
+        }
+    }
+    
+    func componentInputDidEndEditing(inputView: ComponentInput) {
+        if (inputView == fildNameInput) {
+          
+        } else if (inputView == gropNameInput) {
+           
+        } else if (inputView == urlInput) {
+            
            
         }
     }

+ 1 - 1
PDF Office/PDF Master/KMClass/Tools/Tool/KMNTools.swift

@@ -165,7 +165,7 @@ class KMNTools: NSObject {
         if modifiedURLString.hasSuffix(".com") == false {
             modifiedURLString = modifiedURLString + ".com"
         }
-        if modifiedURLString == "https://" {
+        if modifiedURLString == "https://.com" {
             modifiedURLString = ""
         }
         return modifiedURLString