Browse Source

【2025】【PDFView】自测问题修改

dinglingui 1 month ago
parent
commit
f11162233d

+ 43 - 10
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/AppKitCategories/CPDFListEditAnnotationViewController.swift

@@ -31,8 +31,6 @@ class CPDFListEditAnnotationViewController: KMNBaseViewController, NSTextViewDel
     @IBOutlet var clernButton: ComponentButton!
     var colors: [NSColor] = []
     
-    var annotationModel:CPDFAnnotationModel?
-
     var textViewUndoManager = UndoManager()
 
     init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?, annotation: CPDFAnnotation) {
@@ -98,8 +96,22 @@ class CPDFListEditAnnotationViewController: KMNBaseViewController, NSTextViewDel
         }
         generaColorGroup.delegate = self
         
-        annotationModel = CPDFAnnotationModel(pdfAnnotations: [annotation])
-        generaColorGroup.currentColor = annotationModel?.color()
+        var curColor:NSColor?
+        //多选注释去拿注释类型的默认值
+        
+        if(annotation.isKind(of: CSelfSignAnnotation.self)) {
+            if let selfAnn = annotation as? CSelfSignAnnotation {
+                curColor = selfAnn.lineColor
+            }
+        } else if (annotation.isKind(of: CPDFRedactAnnotation.self)) {
+            if let redaAnn = annotation as? CPDFRedactAnnotation {
+                curColor = redaAnn.borderColor()
+            }
+        }else {
+            curColor = annotation.color ?? NSColor.clear
+        }
+        
+        generaColorGroup.currentColor = curColor
         generaColorGroup.refreshUI()
         
         contentLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
@@ -120,7 +132,7 @@ class CPDFListEditAnnotationViewController: KMNBaseViewController, NSTextViewDel
         // Do view setup here.
         
         let box = self.borderBox
-        if let annotationColor = annotationModel?.color() {
+        if let annotationColor = generaColorGroup.currentColor {
             box?.borderColor = annotationColor
         } else {
             box?.borderColor = NSColor.white
@@ -182,11 +194,32 @@ class CPDFListEditAnnotationViewController: KMNBaseViewController, NSTextViewDel
 
 //MARK: - ComponentCColorDelegate
 extension CPDFListEditAnnotationViewController: ComponentCColorDelegate {
-    func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
-        annotationModel?.setColor(color)
-        annotationModel?.setOpacity(1.0)
-        
-        if let annotationColor = annotationModel?.color() {
+    func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {        
+        if(annotation.isKind(of: CSelfSignAnnotation.self)) {
+            if let selfAnn = annotation as? CSelfSignAnnotation {
+                selfAnn.lineColor = color ?? NSColor.clear
+                selfAnn.lineOpacity = 1.0
+            }
+        } else if (annotation.isKind(of: CPDFRedactAnnotation.self)) {
+            if let redaAnn = annotation as? CPDFRedactAnnotation {
+                redaAnn.setBorderColor(color ?? NSColor.black)
+                redaAnn.opacity = 1.0
+            }
+        } else if ((annotation.isKind(of: CPDFFreeTextAnnotation.self))) {
+            if color  == NSColor.clear {
+                annotation.color = nil
+            } else {
+                annotation.color = color
+            }
+            annotation.opacity = 1.0
+
+        } else {
+            annotation.color = color;
+            annotation.opacity = 1.0
+        }
+
+                
+        if let annotationColor = color {
             borderBox.borderColor = annotationColor
         } else {
             borderBox.borderColor = .white

+ 16 - 16
PDF Office/PDF Master/KMClass/Left/Annotaion/Controller/KMLeftSideViewController.swift

@@ -413,18 +413,20 @@ class KMLeftSideViewController: KMSideViewController {
                 break
             }
         }
+        let hasAnno = self.allAnnotations.count >= 1
+        let disable = !hasAnno
         
-        let expand_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(text: expand_MenuString,
+        let expand_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(isDisabled:disable, text: expand_MenuString,
                                                                                        identifier: BOTAMenuIdentifier_Annotation_Expand)
 
         let sort_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(text: KMLocalizedString("Sort"),
                                                                                        identifier: BOTAMenuIdentifier_Annotation_Sort)
         
         var subMenuItemArr: [ComponentMenuitemProperty] = []
-        let pageProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(text: KMLocalizedString("By Page"),identifier: BOTAMenuIdentifier_Annotation_SortPage)
-        let timeAscProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(text: KMLocalizedString("By Time - Ascending"),identifier: BOTAMenuIdentifier_Annotation_SortAscTime)
+        let pageProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(isDisabled:disable,text: KMLocalizedString("By Page"),identifier: BOTAMenuIdentifier_Annotation_SortPage)
+        let timeAscProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(isDisabled:disable,text: KMLocalizedString("By Time - Ascending"),identifier: BOTAMenuIdentifier_Annotation_SortAscTime)
         let timeDecProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(
-                                                                                    text: KMLocalizedString("By Time - Descending"),identifier: BOTAMenuIdentifier_Annotation_SortDesTime)
+            isDisabled:disable,text: KMLocalizedString("By Time - Descending"),identifier: BOTAMenuIdentifier_Annotation_SortDesTime)
         
         subMenuItemArr.append(pageProperty)
         subMenuItemArr.append(timeAscProperty)
@@ -434,12 +436,12 @@ class KMLeftSideViewController: KMSideViewController {
         let improt_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(text: KMLocalizedString("Import Annotations"),
                                                                                        identifier: BOTAMenuIdentifier_Annotation_Improt)
         
-        let exprot_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(text: KMLocalizedString("Import Annotations"),
-                                                                                       identifier: BOTAMenuIdentifier_Annotation_Improt)
+        let exprot_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(isDisabled:disable,text: KMLocalizedString("Export Annotations"),
+                                                                                       identifier: BOTAMenuIdentifier_Annotation_Export)
         
-        let rem_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(text: KMLocalizedString("Remove All Annotations"),
+        let rem_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(isDisabled:disable,text: KMLocalizedString("Remove All Annotations"),
                                                                                        identifier: BOTAMenuIdentifier_Annotation_RemoveAll)        
-        let delete_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(text: KMLocalizedString("Delete All Reply"),
+        let delete_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(isDisabled:disable,text: KMLocalizedString("Delete All Reply"),
                                                                                        identifier: BOTAMenuIdentifier_Annotation_DeleteRep)
         
         var menuItemArr: [ComponentMenuitemProperty] = []
@@ -730,11 +732,9 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
             if(!hasAnno) {
                 headerView.sortButton.properties.isDisabled = true
                 headerView.searchButton.properties.isDisabled = true
-                headerView.moreButton.properties.isDisabled = true
             } else {
                 headerView.sortButton.properties.isDisabled = false
                 headerView.searchButton.properties.isDisabled = false
-                headerView.moreButton.properties.isDisabled = false
             }
             headerView.sortButton.reloadData()
             headerView.searchButton.reloadData()
@@ -1591,7 +1591,7 @@ extension KMLeftSideViewController: ComponentGroupDelegate {
                     }
                 }
             } else if (menuItemProperty?.identifier == PDFViewMenuIdentifier_Normal_Copy) {
-                if let models = menuItemProperty?.representedObject as? [KMBotaAnnotationReplyModel] {
+                if let models = menuItemProperty?.representedObject as? [KMBotaAnnotationModel] {
                     if models.first != nil {
                         let model = models.first
                         let an = model?.anno
@@ -1603,11 +1603,11 @@ extension KMLeftSideViewController: ComponentGroupDelegate {
                         } else if an?.isKind(of: CPDFFreeTextAnnotation.self) == true ||
                                   an?.isKind(of: CPDFTextAnnotation.self) == true {
                             copyText = an?.contents ?? ""
-                            let pboard = NSPasteboard.general
-                            if copyText.isEmpty == false {
-                                pboard.clearContents()
-                                pboard.writeObjects([copyText as NSPasteboardWriting])
-                            }
+                        }
+                        let pboard = NSPasteboard.general
+                        if copyText.isEmpty == false {
+                            pboard.clearContents()
+                            pboard.writeObjects([copyText as NSPasteboardWriting])
                         }
                     }
                 }