Browse Source

【注释回复】删除所有注释回复菜单项补充

tangchao 5 months ago
parent
commit
984ea37227

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

@@ -269,6 +269,10 @@ extension KMLeftSideViewController {
         return menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "", comment: ""), action: #selector(removeAllAnnotations), target: self)
     }
     
+    private func _addDeleteAllReplyAnnoItem(_ menu: NSMenu) -> NSMenuItem? {
+        return menu.addItem(title: NSLocalizedString("删除所有注释回复", tableName: "", comment: ""), action: #selector(removeAllReplyAnnotations), target: self)
+    }
+    
     func annoListMoreMenu(_ view: NSButton) {
         let menu = NSMenu()
         let object = KMPopupMenuObject()
@@ -311,6 +315,7 @@ extension KMLeftSideViewController {
         _ = self._addExportPDFMenu(menu)
         menu.addItem(.separator())
         _ = self._addDeleteAllAnnoItem(menu)
+        _ = self._addDeleteAllReplyAnnoItem(menu)
         
         menu.addItem(.separator())
         let importItem = NSMenuItem(title: NSLocalizedString("导入注释", comment: ""), action: #selector(importNotes), keyEquivalent: "")
@@ -548,6 +553,28 @@ extension KMLeftSideViewController {
         }
     }
     
+    @objc func removeAllReplyAnnotations(_ sender: NSMenuItem?) {
+        self.dataUpdating = true
+        for model in self.annoListModel?.datas ?? [] {
+            for item in model.items {
+//                if let anno = item.anno {
+//                    self.listView?.remove(anno)
+//                }
+                guard let annoM = item as? KMBotaAnnotationModel else {
+                    continue
+                }
+                for replyM in annoM.replyAnnos {
+//                    self.listView?.remove(replyM.replyAnno)
+                    replyM.replyAnno?.page.removeAnnotation(replyM.replyAnno)
+                }
+                annoM.replyAnnos.removeAll()
+            }
+        }
+        self.dataUpdating = false
+
+        self.note_refrshUIIfNeed()
+    }
+    
     @objc func editNoteTextFromTable(_ sender: NSMenuItem) {
 //        PDFAnnotation *annotation = [sender representedObject];
         guard let annotation = sender.representedObject as? CPDFAnnotation else {
@@ -678,7 +705,22 @@ extension KMLeftSideViewController {
         if self.noteSearchMode { // 搜索模式
             return self.noteSearchArray.safe_element(for: index) as? KMBotaAnnotationModel
         } else { // 常规模式(非搜索)
-            return self.annoListModel?.datas.safe_element(for: index) as? KMBotaAnnotationModel
+//            let model = self.annoListModel?.datas.safe_element(for: index)
+            let model = self.noteOutlineView.item(atRow: index)
+            if let data = model as? KMBotaAnnotationSectionModel {
+                return nil
+            }
+            if let data = model as? KMBotaAnnotationModel {
+                return data
+            }
+            if let data = model as? KMBotaAnnotationFooterModel {
+//                return data.annoModel
+            }
+            if let data = model as? KMBotaAnnotationReplyModel {
+//                return data.annoModel
+            }
+//            return self.annoListModel?.datas.safe_element(for: index) as? KMBotaAnnotationModel
+            return nil
         }
     }