Sfoglia il codice sorgente

【注释】修复“Form button注释创建属性关联属性面板错误”

wanjun 10 mesi fa
parent
commit
fe4d52a4d1

+ 6 - 7
PDF Office/PDF Master/Class/PDFWindowController/Form/KMFormActionButtonPopWindowController.swift

@@ -103,8 +103,7 @@ class KMFormActionButtonPopWindowController: NSWindowController {
             visibleComboBox.selectItem(at: 0)
         }
         
-//        if let mouseUpAction = settingButtonWidget.mouseUpAction, mouseUpAction as CPDFNamedAction {
-        if let mouseUpAction = settingButtonWidget?.mouseUpAction() as? CPDFAnnotation {
+        if settingButtonWidget?.mouseUpAction() is CPDFAnnotation {
             actionComboBox.selectItem(at: 1)
             urlButton.isEnabled = false
             emailButton.isEnabled = false
@@ -117,7 +116,7 @@ class KMFormActionButtonPopWindowController: NSWindowController {
             urlTextField.isEnabled = true
             emailTextField.isEnabled = true
             
-            if let urlAction = settingButtonWidget!.mouseUpAction as? CPDFURLAction {
+            if let urlAction = settingButtonWidget!.mouseUpAction() as? CPDFURLAction {
                 if urlAction.url().fileURL.absoluteString.hasPrefix("mailto:") {
                     urlButton.state = .off
                     emailButton.state = .on
@@ -199,7 +198,7 @@ class KMFormActionButtonPopWindowController: NSWindowController {
     }
 
     @IBAction func buttonClicked_CancelSetting(_ sender: Any) {
-        dismissSheet(cancelButton)
+        dismissSheet(cancelButton as Any)
     }
     
     @IBAction func buttonClicked_ConfirmSetting(_ sender: Any) {
@@ -219,11 +218,11 @@ class KMFormActionButtonPopWindowController: NSWindowController {
                 }
             }
             if let action = CPDFURLAction(url: url) {
-//                settingButtonWidget?.setMouseUpAction(action)
+                settingButtonWidget?.setMouseUpAction(action)
             }
         } else {
             if let action = CPDFNamedAction(name: .print) {
-//                settingButtonWidget?.setMouseUpAction(action)
+                settingButtonWidget?.setMouseUpAction(action)
             }
         }
         
@@ -241,7 +240,7 @@ class KMFormActionButtonPopWindowController: NSWindowController {
         settingButtonWidget?.setCaption(labelTextField.stringValue)
 
         NotificationCenter.default.post(name: NSNotification.Name("KMFormActionButtonChange"), object: nil, userInfo: nil)
-        dismissSheet(okButton)
+        dismissSheet(okButton as Any)
     }
     
     // MARK: NSNotification Action

+ 3 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Form.swift

@@ -107,9 +107,12 @@ extension CPDFListView {
             } else if let buttonWidget = editAnnotation as? CPDFButtonWidgetAnnotation {
                 let buttonWindowController = KMFormActionButtonPopWindowController(buttonWidget: buttonWidget, isEdit: false)
                 buttonWindowController.beginSheetModal(for: window!) { result in
+                    editAnnotation.updateAppearanceStream()
+                    self.setNeedsDisplayAnnotationViewFor(editAnnotation.page)
                     if result == 0 {
                         self.remove(editAnnotation)
                     }
+                    self.pdfListViewDelegate.pdfListViewChangeatioActiveAnnotations?(self, forActiveAnnotations: (self.activeAnnotations as! [CPDFAnnotation]), isRightMenu: false)
                 }
             }
         }

+ 14 - 39
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/FormProperties/KMAnnotationButtonOptionsViewController.swift

@@ -37,11 +37,7 @@ private let LinkHyperlink = "https://www.pdfreaderpro.com"
     
     override func viewDidLoad() {
         super.viewDidLoad()
-        
-//        if let note = self.annotation as? CPDFButtonWidgetAnnotation {
-//            note.controlType() = .pushButtonControl
-//        }
-        
+    
         actionLabel.stringValue = NSLocalizedString("Label", comment: "")
         actionLabel.textColor = KMAppearance.Layout.h1Color()
         
@@ -114,34 +110,29 @@ private let LinkHyperlink = "https://www.pdfreaderpro.com"
             actionLabelTextField.layer?.backgroundColor = lightBackground
         }
     }
-
+    
     func reload() {
-//        if let annotation = self.annotation as? PDFAnnotationButtonWidget {
-//            annotation.widgetControlType = .widgetPushButtonControl
-//            reloadData(annotation)
-//        }
         reloadData()
     }
     
     func reloadData() {
         if annotations.count > 0 {
-            if annotation!.caption() == "" || annotation!.caption() == nil {
-                if let namedAction = annotation!.mouseUpAction() as? CPDFNamedAction {
+            if annotation?.caption() == "" || annotation?.caption() == nil {
+                if annotation?.action() is CPDFNamedAction {
                     actionLabelTextField.stringValue = NSLocalizedString("Print", comment: "")
-                } else if let urlAction = annotation!.mouseUpAction() as? CPDFURLAction {
+                } else if annotation?.action() is CPDFURLAction {
                     actionLabelTextField.stringValue = NSLocalizedString("Submit", comment: "")
                 }
             } else {
-                actionLabelTextField.stringValue = (annotation!.caption())!
+                actionLabelTextField.stringValue = annotation?.caption() ?? ""
             }
-
-            if let urlAction = annotation!.mouseUpAction() as? CPDFURLAction {
+            
+            if let urlAction = annotation?.action() as? CPDFURLAction {
                 actionSendEmailView.isHidden = false
-                let actionUrlPath = urlAction.url().fileURL.absoluteString
-
+                let actionUrlPath = urlAction.url() ?? ""
                 actionSendEmailLabel.isHidden = false
                 actionSendEmailTextField.isHidden = false
-
+                
                 if actionUrlPath.hasPrefix("http://") || actionUrlPath.hasPrefix("https://") {
                     actionSelectActionBtn.selectItem(at: 1)
                     actionSendEmailLabel.stringValue = NSLocalizedString("Add URL", comment: "")
@@ -166,24 +157,6 @@ private let LinkHyperlink = "https://www.pdfreaderpro.com"
         }
     }
     
-    func updateAnnotationMode() {
-        let userDefaults = UserDefaults.standard
-        if formMode == .actionButton {
-            userDefaults.set(annotation?.caption, forKey: SKAnnotationChoiceWidgetChoicesKey)
-            
-            if let mouseUpAction = annotation?.mouseUpAction {
-                userDefaults.set(mouseUpAction, forKey: SKAnnotationActionButtonWidgetActionKey)
-                
-                if let actionURL = mouseUpAction as? PDFActionURL {
-                    let actionUrlPath = actionURL.url?.absoluteString ?? ""
-                    userDefaults.set(actionUrlPath, forKey: SKAnnotationActionButtonWidgetActionURLKey)
-                } else {
-                    userDefaults.set(mouseUpAction, forKey: SKAnnotationActionButtonWidgetActionNameKey)
-                }
-            }
-        }
-    }
-    
     private func updateAnnotation() {
         if annotationModel.annotation != nil {
             for tAnnotation in annotations {
@@ -286,9 +259,11 @@ private let LinkHyperlink = "https://www.pdfreaderpro.com"
 
     @objc func actionLabelTextFieldDidChange() {
         for tAnnotation in annotations {
+            tAnnotation.updateAppearanceStream()
             tAnnotation.setCaption(actionLabelTextField.stringValue)
+            self.pdfView?.setNeedsDisplayAnnotationViewFor(tAnnotation.page)
         }
-        updateAnnotation()    }
+    }
 
     @objc func actionSendEmailTextFieldDidChange() {
         var url: String?
@@ -310,8 +285,8 @@ private let LinkHyperlink = "https://www.pdfreaderpro.com"
         for tAnnotation in annotations {
             let action = CPDFURLAction(url: url)
             tAnnotation.setMouseUpAction(action)
+            self.pdfView?.setNeedsDisplayAnnotationViewFor(tAnnotation.page)
         }
-        updateAnnotation()
     }
     
     @objc func themeChanged(_ notification: Notification) {