Browse Source

【UI替换】编辑工具 - 移除页眉页脚,移除bates码功能完善

lizhe 1 year ago
parent
commit
bd6abc7698

+ 2 - 2
PDF Office/PDF Master/Class/PDFTools/AddHeaderFooter/New/View/KMHeaderFooterView.swift

@@ -811,7 +811,7 @@ class KMHeaderFooterView: KMBaseXibView, NSTextViewDelegate, NSComboBoxDelegate
         return append2
     }
 
-    class func saveAsPDFRemoveAllHeaderFooter(_ PDFDocument: CPDFDocument,
+    static func saveAsPDFRemoveAllHeaderFooter(_ PDFDocument: CPDFDocument,
                                               password: String?,
                                               toPath path: String,
                                               completionHandler handler: ((Int) -> Void)?) {
@@ -852,7 +852,7 @@ class KMHeaderFooterView: KMBaseXibView, NSTextViewDelegate, NSComboBoxDelegate
         }
     }
 
-    class func saveAsPDFRemoveAllHeaderFooterBates(_ PDFDocument: CPDFDocument,
+    static func saveAsPDFRemoveAllHeaderFooterBates(_ PDFDocument: CPDFDocument,
                                                   password: String?,
                                                   toPath path: String,
                                                   completionHandler handler: ((Int) -> Void)?) {

+ 56 - 19
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -3125,7 +3125,7 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                     } else {
                         self.showBatchWindow(type: .RemoveHeaderFooter, files: [])
                     }
-                } else if (index == 4) { //// 移除
+                } else if (index == 2) { //// 移除
                     if (type == .watermark) {
                         let watermarks = self.listView.document.watermarks()
                         if (watermarks == nil || watermarks!.count <= 0) {
@@ -3147,27 +3147,64 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                         if (result != .alertFirstButtonReturn) {
                             return
                         }
-                    }
-                    
-                    let oType: KMWatermarkAdjectiveType = KMWatermarkAdjectiveTools.KMWatermarkAdjectiveType(from: type)
-                    KMWatermarkAdjectiveTools.delete(oType, self.listView, self.listView.document.documentURL.path) {
-                        result in
-                        DispatchQueue.main.async {
-                            self.listView.layoutDocumentView()
-                            self.listView.setNeedsDisplayForVisiblePages()
+                        
+                        let oType: KMWatermarkAdjectiveType = KMWatermarkAdjectiveTools.KMWatermarkAdjectiveType(from: type)
+                        KMWatermarkAdjectiveTools.delete(oType, self.listView, self.listView.document.documentURL.path) {
+                            result in
+                            DispatchQueue.main.async {
+                                self.listView.layoutDocumentView()
+                                self.listView.setNeedsDisplayForVisiblePages()
+                            }
+                            if (result) {
+                                let alert = NSAlert()
+                                alert.alertStyle = .warning
+                                alert.messageText = "成功"
+                                alert.runModal()
+                            } else {
+                                let alert = NSAlert()
+                                alert.alertStyle = .critical
+                                alert.messageText = "失败"
+                                alert.runModal()
+                            }
                         }
-                        if (result) {
-                            let alert = NSAlert()
-                            alert.alertStyle = .warning
-                            alert.messageText = "成功"
-                            alert.runModal()
-                        } else {
-                            let alert = NSAlert()
-                            alert.alertStyle = .critical
-                            alert.messageText = "失败"
-                            alert.runModal()
+                    }  else if type == .headerAndFooter {
+                        let savePanelAccessoryViewController = KMSavePanelAccessoryController()
+                        let savePanel = NSSavePanel()
+                        savePanel.nameFieldStringValue = (document?.documentURL.lastPathComponent.deletingPathExtension)!
+                        savePanel.allowedFileTypes = ["pdf"]
+                        savePanel.accessoryView = savePanelAccessoryViewController.view
+                        savePanel.beginSheetModal(for: NSWindow.currentWindow()) { [unowned self] result in
+                            if result.rawValue == NSApplication.ModalResponse.OK.rawValue {
+                                KMHeaderFooterView.saveAsPDFRemoveAllHeaderFooter(document!, password: document?.password, toPath: savePanel.url!.path) { success in
+                                    if savePanelAccessoryViewController.openAutomaticButton.state == .on {
+                                        NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePanel.url!.path), display: true) { _, _, _ in
+                                        }
+                                    } else {
+                                        NSWorkspace.shared.selectFile(savePanel.url?.path, inFileViewerRootedAtPath: "")
+                                    }
+                                }
+                            }
+                        }
+                    } else if type == .bates {
+                        let savePanelAccessoryViewController = KMSavePanelAccessoryController()
+                        let savePanel = NSSavePanel()
+                        savePanel.nameFieldStringValue = (document?.documentURL.lastPathComponent.deletingPathExtension)!
+                        savePanel.allowedFileTypes = ["pdf"]
+                        savePanel.accessoryView = savePanelAccessoryViewController.view
+                        savePanel.beginSheetModal(for: NSWindow.currentWindow()) { [unowned self] result in
+                            if result.rawValue == NSApplication.ModalResponse.OK.rawValue {
+                                KMHeaderFooterView.saveAsPDFRemoveAllHeaderFooterBates(document!, password: document?.password, toPath: savePanel.url!.path) { success in
+                                    if savePanelAccessoryViewController.openAutomaticButton.state == .on {
+                                        NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePanel.url!.path), display: true) { _, _, _ in
+                                        }
+                                    } else {
+                                        NSWorkspace.shared.selectFile(savePanel.url?.path, inFileViewerRootedAtPath: "")
+                                    }
+                                }
+                            }
                         }
                     }
+                
                     return
                 } else if (index == 2) { /// 应用
                     let model = self.rightSideViewController.model