瀏覽代碼

【注释回复】编辑回复注释功能补充

tangchao 5 月之前
父節點
當前提交
44dcf9d997

+ 21 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -2097,6 +2097,15 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                     cell?.operationIv.image = NSImage(named: "KMImageNameBotaNoteStateRejected")
                 }
                 
+                if let con = data.replyModel?.replyAnno?.contents, con.isEmpty == false {
+                    cell?.inputTextF.stringValue = con
+                    DispatchQueue.main.async {
+                        self.view.window?.makeFirstResponder(cell?.inputTextF)
+                    }
+                } else {
+                    cell?.inputTextF.stringValue = ""
+                }
+                
                 cell?.updateUI(expand: data.isExpand, animated: data.animated)
                 data.animated = false
                 
@@ -2115,6 +2124,17 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                             }
                             return
                         }
+                        if let con = data.replyModel?.replyAnno?.contents, con.isEmpty == false {
+                            let model = data.replyModel
+                            model?.replyAnno?.contents = content
+                            model?.replyAnno?.setUserName(KMPreference.shared.author)
+                            model?.replyAnno?.setModificationDate(Date())
+                            self?.noteOutlineView.reloadData()
+                            
+                            // 置空编辑状态
+                            data.replyModel = nil
+                            return
+                        }
                         if let replyAnno = self?.noteReplyHanddler.createReplyAnnotation(data.anno, content: content, userName: KMPreference.shared.author) {
 //                            self?.reloadAnnotation()
                             let model = KMBotaAnnotationReplyModel()
@@ -2151,7 +2171,7 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                 cell?.contentLabel.stringValue = data.replyAnno?.contents ?? ""
                 cell?.itemClick = { [weak self] idx, params in
                     if idx == 1 { // 更多
-                        self?.noteReplyHanddler.showReplyMorePopView(sender: params.first as! NSView, anno: data.replyAnno)
+                        self?.noteReplyHanddler.showReplyMorePopView(sender: params.first as! NSView, replyModel: data)
                     }
                 }
                 return cell

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Model/KMAnnotationModel.swift

@@ -51,6 +51,8 @@ class KMBotaAnnotationModel: KMBotaAnnotationBaseModel {
 
 class KMBotaAnnotationFooterModel: KMBotaAnnotationBaseModel {
     weak var annoModel: KMBotaAnnotationModel?
+    
+    weak var replyModel: KMBotaAnnotationReplyModel?
 }
 
 class KMBotaAnnotationReplyModel: KMBotaAnnotationBaseModel {

+ 14 - 6
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Tools/KMNoteReplyHanddler.swift

@@ -238,7 +238,7 @@ class KMNoteReplyHanddler: NSObject {
         self.popover_ = popover
     }
     
-    func showReplyMorePopView(sender: NSView, anno: CPDFAnnotation?) {
+    func showReplyMorePopView(sender: NSView, replyModel: KMBotaAnnotationReplyModel?) {
         if let _ = self.popover_ {
             return
         }
@@ -255,12 +255,16 @@ class KMNoteReplyHanddler: NSObject {
             self?.popover_?.close()
             
             if data == NSLocalizedString("Edit", comment: "") {
-                self?.editReplyAnnotation()
+                self?.editReplyAnnotation(replyModel: replyModel)
             } else if data == NSLocalizedString("Delete", comment: "") {
-                self?.removeReplyAnnotation(anno)
+                if let model = replyModel {
+                    self?.removeReplyAnnotation(model.replyAnno)
+                    model.annoModel?.replyAnnos.removeObject(model)
+                }
             }
             
-            self?.viewC?.reloadAnnotation()
+//            self?.viewC?.reloadAnnotation()
+            self?.viewC?.noteOutlineView.reloadData()
         }
 
         let popover = NSPopover()
@@ -312,8 +316,12 @@ class KMNoteReplyHanddler: NSObject {
         return a
     }
     
-    func editReplyAnnotation() {
-        KMPrint("editReplyAnnotation")
+    func editReplyAnnotation(replyModel: KMBotaAnnotationReplyModel?) {
+        guard let model = replyModel else {
+            return
+        }
+        
+        model.annoModel?.footerModel?.replyModel = model
     }
     
     func removeReplyAnnotation(_ anno: CPDFAnnotation?) {