Explorar el Código

【综合】注释列表补充注释导入、导出

tangchao hace 5 meses
padre
commit
c6c113bc17

+ 53 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Note.swift

@@ -311,6 +311,16 @@ extension KMLeftSideViewController {
         _ = self._addExportPDFMenu(menu)
         menu.addItem(.separator())
         _ = self._addDeleteAllAnnoItem(menu)
+        
+        menu.addItem(.separator())
+        let importItem = NSMenuItem(title: NSLocalizedString("导入注释", comment: ""), action: #selector(importNotes), keyEquivalent: "")
+        importItem.target = self
+        menu.addItem(importItem)
+        
+        let exportItem = NSMenuItem(title: NSLocalizedString("导出注释", comment: ""), action: #selector(exportNotes), keyEquivalent: "")
+        exportItem.target = self
+        menu.addItem(exportItem)
+        
         if let data = NSApp.currentEvent {
             NSMenu.popUpContextMenu(menu, with: data, for: view, with: nil)
         }
@@ -407,6 +417,49 @@ extension KMLeftSideViewController {
         self.noteOutlineView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false)
     }
     
+    @objc func importNotes(_ sender: NSMenuItem) {
+        let panel = NSOpenPanel()
+        panel.allowedFileTypes = ["xfdf"]
+        panel.allowsMultipleSelection = false
+        panel.beginSheetModal(for: self.view.window!) { resp in
+            if resp != .OK {
+                return
+            }
+            
+            if let result = self.pdfDocument()?.importAnnotation(fromXFDFPath: panel.url?.path), result {
+                self.reloadAnnotation()
+                self.listView?.setNeedsDisplayForVisiblePages()
+            }
+        }
+    }
+    
+    @objc func exportNotes(_ sender: NSMenuItem) {
+        guard let cnt = self.listView?.notes.count, cnt > 0 else {
+            NSSound.beep()
+            return
+        }
+        
+        let fileName = "\(self.pdfDocument()?.documentURL.deletingPathExtension().lastPathComponent ?? "")" + "_xfdf"
+        let panel = NSSavePanel()
+        panel.directoryURL = self.pdfDocument()?.documentURL.deletingLastPathComponent()
+        panel.allowedFileTypes = ["xfdf"]
+        panel.nameFieldStringValue = fileName
+        panel.beginSheetModal(for: self.view.window!) { resp in
+            if resp != .OK {
+                return
+            }
+            
+            let filePath = panel.url?.path
+            if let success = self.pdfDocument()?.exportAnnotation(toXFDFPath: filePath), success {
+                NSWorkspace.shared.selectFile(filePath, inFileViewerRootedAtPath: "")
+            } else {
+                Task {
+                    _ = await KMAlertTool.runModel(message: NSLocalizedString("Export Failure!", comment: ""), buttons: ["OK"])
+                }
+            }
+        }
+    }
+    
     @objc func exportAnnotationNotes(_ sender: AnyObject?) {
         let doc = self.view.window?.windowController?.document as? NSDocument
         doc?.saveTo(sender)