Prechádzať zdrojové kódy

【2025】【Home】快捷工具串接

niehaoyu 4 mesiacov pred
rodič
commit
d54a29580f

+ 1 - 0
PDF Office/KMComponentLibrary/KMComponentLibrary/View/Card/ComponentCardPDFTool/ComponentCardPDFToolProperty.swift

@@ -21,6 +21,7 @@ public class ComponentCardPDFToolProperty: NSObject {
     public var enableMouseEnterExit: Bool = true //外部控制鼠标进入退出是否修改状态
     
     public var propertyInfo = CardPropertyInfo()
+    public var customData: Any? = nil
     
     public init(collapse: Bool = false,
                 state: ComponentState = .normal,

+ 649 - 1
PDF Office/PDF Master/KMClass/KMHomeViewController/KMNHomeViewController.swift

@@ -22,6 +22,10 @@ class KMNHomeViewController: NSViewController {
      
     var demoVC: WCCompWindowController = WCCompWindowController(windowNibName: "WCCompWindowController")
     
+    
+    //合并
+    var mergeWindowController: KMMergeWindowController?
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         // Do view setup here.
@@ -163,7 +167,8 @@ extension KMNHomeViewController: KMHomeRightViewDelegate {
     
     //点击快捷工具列表中的某一项
     func homeRightViewDidQuickToolsItemClicked(_ view: KMHomeRightView, _ toolType: HomeQuickToolType) {
-        print("HomeQuickToolType = %d", toolType.rawValue)
+        self.quickToolsActionWith(toolType)
+        
     }
  
     //最近文件列表删除更新结束后回调
@@ -191,6 +196,15 @@ extension KMNHomeViewController: KMHomeDragViewDelegate {
         self.openFile(withFilePath: filePath)
 
     }
+    
+    func homeDragView(_ viewController: KMHomeDragView, notSupport: Bool) {
+        if notSupport {
+            let alert = NSAlert()
+            alert.alertStyle = .critical
+            alert.messageText = KMLocalizedString("This file format is not supported. Please enter PDF, picture, or Office file")
+            alert.runModal()
+        }
+    }
 }
 
 //MARK: - Open Files
@@ -688,3 +702,637 @@ extension KMNHomeViewController {
     
     
 }
+
+//MARK: - Quick Tools Action
+extension KMNHomeViewController {
+    func quickToolsActionWith(_ type: HomeQuickToolType) {
+        switch type {
+        case .Batch:
+            fastTool_Batch()
+            
+            break
+            
+        case .MergePDF:
+            fastTool_MergePDF()
+            
+            break
+            
+        case .ImageToPDF:
+            imageToPDFAction()
+            
+            break
+            
+        case .OCR:
+            fastTool_OCR()
+            
+            break
+            
+        case .ConvertPDF:
+            fastTool_ConvertPDF()
+            
+            break
+            
+        case .PDFToWord:
+            fastTool_ConvertPDF()
+            
+            break
+            
+        case .PDFToExcel:
+            fastTool_PDFToExcel()
+            
+            break
+            
+        case .Compression:
+            fastTool_Compression()
+            
+            break
+            
+        case .PDFToPPT:
+            fastTool_PDFToPPT()
+            
+            break
+            
+        case .Security:
+            fastTool_Security()
+            
+            break
+            
+        case .FileCompare:
+            fastTool_FileCompare()
+            
+            break
+            
+        case .Watermark:
+            fastTool_Watermark()
+            break
+            
+        case .Insert:
+            fastTool_Insert()
+            
+            break
+            
+        case .Extract:
+            fastTool_Extract()
+            
+            break
+            
+        case .DigitalSignature:
+            
+            break
+            
+        case .Print:
+            fastTool_Print()
+            
+            break
+        }
+    }
+    
+    func imageToPDFAction() {
+        let openPanel = NSOpenPanel()
+        openPanel.allowedFileTypes = KMImageToPDFMethod.supportedImageTypes()
+        //MARK: 允许多选还是单选,如果是付费用户允许多选
+        openPanel.allowsMultipleSelection = true
+        openPanel.message = KMLocalizedString("Select images to create a new document. To select multiple files press cmd ⌘ button on keyboard and click on the target files one by one.")
+        if IAPProductsManager.default().isAvailableAllFunction(){
+            openPanel.allowsMultipleSelection = true
+        } else {
+            openPanel.allowsMultipleSelection = false
+        }
+        
+        openPanel.beginSheetModal(for: NSWindow.currentWindow()) {[weak self] result in
+            if result == NSApplication.ModalResponse.OK {
+                guard let weakSelf = self else { return }
+                let urls = openPanel.urls as [URL]
+
+                weakSelf.openImageToPdfWindow(urls: urls)
+            }
+        }
+    }
+    
+    func fastTool_Batch() { // Batch
+        if !IAPProductsManager.default().isAvailableAllFunction(){
+            KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
+            return
+        }
+        let batchWindowController = KMBatchOperateWindowController.sharedWindowController
+        batchWindowController.window?.makeKeyAndOrderFront("")
+    }
+    
+    func fastTool_MergePDF() {  // MergePDF
+        mergeWindowController = KMMergeWindowController(windowNibName: "KMMergeWindowController")
+        mergeWindowController!.type = .merge
+        mergeWindowController!.cancelAction = { [unowned self] controller in
+            self.view.window?.endSheet((self.mergeWindowController!.window)!)
+        }
+        view.window?.beginSheet(mergeWindowController!.window!)
+        
+    }
+    
+    func fastTool_OCR() {   // OCR
+        if !IAPProductsManager.default().isAvailableAllFunction(){
+            let winC = KMPurchaseCompareWindowController.sharedInstance()
+            winC?.showWindow(nil)
+            return
+        }
+        let openPanel = NSOpenPanel()
+       
+        var arr = KMImageToPDFMethod.supportedImageTypes()
+        arr.append("pdf")
+        openPanel.allowedFileTypes = arr
+        openPanel.allowsMultipleSelection = false
+
+        openPanel.beginSheetModal(for: NSWindow.currentWindow()) { [self] (result) in
+            if result == NSApplication.ModalResponse.OK {
+                quickOcr(urls: openPanel.urls)
+            }
+        }
+    }
+    
+    func quickOcr(urls: Array<URL>) {
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
+            var document: CPDFDocument?
+            for fileURL in urls {
+                if fileURL.lastPathComponent.pathExtension == "pdf"{
+                    document = CPDFDocument(url: fileURL)
+                }else{
+                    document = CPDFDocument()
+                    let image = NSImage(contentsOfFile: fileURL.path)
+                    _ = document?.km_insertPage(image!.size, withImage: fileURL.path, at: 0)
+                }
+                break
+            }
+            if document == nil{
+                let alert = NSAlert()
+                alert.alertStyle = .critical
+                alert.messageText = KMLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.")
+                alert.beginSheetModal(for: NSApp.mainWindow!) { (response) in
+                    if response == .alertFirstButtonReturn {
+                        // Handle cancel action
+                    }
+                }
+                return
+            }
+            let com = KMOCRPDFWindowController(cpdfDocument: document!, pwd: document!.password)
+            self.km_beginSheet(windowC: com)
+        }
+    }
+    
+    func fastTool_ConvertPDF() {    // 转换PDF
+        let openPanel = NSOpenPanel()
+        var arr = KMImageToPDFMethod.supportedImageTypes()
+        arr.append("pdf")
+        openPanel.allowedFileTypes = ["pdf","PDF"]
+        //MARK: 允许多选还是单选,如果是付费用户允许多选
+        openPanel.allowsMultipleSelection = false
+
+        openPanel.beginSheetModal(for: self.view.window!) { [self] (result) in
+            if result == NSApplication.ModalResponse.OK {
+                quickConvertPdf(urls: openPanel.urls, type: .WordAdvance)
+            }
+        }
+    }
+    
+    func quickConvertPdf(urls: Array<URL>, type: KMConvertWithPDFType) {
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
+            var arr: Array<KMBatchOperateFile> = Array()
+            for fileURL in urls {
+                let img = NSImage(contentsOfFile: fileURL.path)
+                if self.isDamageImage(image: img, path: fileURL.path) {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.messageText = String(format: KMLocalizedString("The file \"%@\" could not be opened."), fileURL.path.lastPathComponent)
+                    alert.informativeText = KMLocalizedString("It may be damaged or use a file format that PDF Reader Pro doesn’t recognize.")
+                    alert.addButton(withTitle: KMLocalizedString("Cancel"))
+                    alert.beginSheetModal(for: NSApp.mainWindow!) { (response) in
+                        if response == .alertFirstButtonReturn {
+                            // Handle cancel action
+                        }
+                    }
+                    continue
+                }
+                let file = KMBatchOperateFile(filePath: fileURL.path, type: .Convert)
+                arr.append(file)
+            }
+            let baseWindowController = KMBatchOperateBaseWindowController(windowNibName: "KMBatchOperateBaseWindowController")
+            if #available(macOS 10.13, *) {
+                baseWindowController.window?.makeKeyAndOrderFront(nil)
+            } else {
+                baseWindowController.showWindow(nil)
+            }
+            if arr.count > 0 {
+                baseWindowController.checkNeedPasswordSwitchToOperateType(operateType: .Convert, files: arr)
+            }
+            baseWindowController.switchToConvertType(convertType: type)
+        }
+    }
+    
+    func fastTool_PDFToPPT() {
+        let openPanel = NSOpenPanel()
+        openPanel.allowedFileTypes = ["pdf","PDF"]
+        //MARK: 允许多选还是单选,如果是付费用户允许多选
+        openPanel.allowsMultipleSelection = false
+        
+        openPanel.beginSheetModal(for: NSWindow.currentWindow()) { [self] (result) in
+            if result == NSApplication.ModalResponse.OK {
+                quickConvertPdf(urls: openPanel.urls, type: .PowerPoint)
+            }
+        }
+    }
+    
+    func fastTool_PDFToExcel() {
+        let openPanel = NSOpenPanel()
+        openPanel.allowedFileTypes = ["pdf","PDF"]
+        //MARK: 允许多选还是单选,如果是付费用户允许多选
+        openPanel.allowsMultipleSelection = false
+        
+        openPanel.beginSheetModal(for: NSWindow.currentWindow()) { [self] (result) in
+            if result == NSApplication.ModalResponse.OK {
+                quickConvertPdf(urls: openPanel.urls, type: .Excel)
+            }
+        }
+    }
+    
+    // 压缩
+    func fastTool_Compression() {
+        let openPanel = NSOpenPanel()
+        openPanel.allowedFileTypes = ["pdf","PDF"]
+        //MARK: 允许多选还是单选,如果是付费用户允许多选
+        openPanel.allowsMultipleSelection = false
+
+        openPanel.beginSheetModal(for: NSWindow.currentWindow()) { [self] (result) in
+            if result == NSApplication.ModalResponse.OK {
+                quickCompressPdf(urls: openPanel.urls)
+            }
+        }
+    }
+    
+    func quickCompressPdf(urls: Array<URL>) {
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
+            var arr: Array<KMBatchOperateFile> = Array()
+            for fileURL in urls {
+                let file = KMBatchOperateFile(filePath: fileURL.path, type: .Compress)
+                arr.append(file)
+            }
+            let baseWindowController = KMBatchOperateBaseWindowController(windowNibName: "KMBatchOperateBaseWindowController")
+            if #available(macOS 10.13, *) {
+                baseWindowController.window?.makeKeyAndOrderFront(nil)
+            } else {
+                baseWindowController.showWindow(nil)
+            }
+            if arr.count > 0 {
+                baseWindowController.checkNeedPasswordSwitchToOperateType(operateType: .Compress, files: arr)
+            }
+        }
+    }
+    
+    // 安全
+    func fastTool_Security() {
+        let openPanel = NSOpenPanel()
+        openPanel.allowedFileTypes = ["pdf","PDF"]
+        //MARK: 允许多选还是单选,如果是付费用户允许多选
+        openPanel.allowsMultipleSelection = true
+        openPanel.message = KMLocalizedString("To select multiple files press cmd ⌘ button on keyboard and click on the target files one by one.")
+        openPanel.beginSheetModal(for: NSWindow.currentWindow()) { [self] (result) in
+            if result == NSApplication.ModalResponse.OK {
+                quickPassword(urls: openPanel.urls)
+            }
+        }
+    }
+    
+    func quickPassword(urls: Array<URL>) {
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
+            var arr: Array<KMBatchOperateFile> = Array()
+            for fileURL in urls {
+                let file = KMBatchOperateFile(filePath: fileURL.path, type: KMBatchQuickActionManager.defaultManager.actionType == .add ? .AddPassword : .RemovePassword)
+                arr.append(file)
+            }
+            let baseWindowController = KMBatchOperateBaseWindowController(windowNibName: "KMBatchOperateBaseWindowController")
+            if #available(macOS 10.13, *) {
+                baseWindowController.window?.makeKeyAndOrderFront(nil)
+            } else {
+                baseWindowController.showWindow(nil)
+            }
+            if arr.count > 0 {
+                baseWindowController.checkNeedPasswordSwitchToOperateType(operateType: KMBatchQuickActionManager.defaultManager.actionType == .add ? .AddPassword : .RemovePassword, files: arr)
+            }
+        }
+    }
+    
+    func fastTool_FileCompare() {    // 文件对比
+        if !IAPProductsManager.default().isAvailableAllFunction(){
+            let winC = KMPurchaseCompareWindowController.sharedInstance()
+            winC?.showWindow(nil)
+            return
+        }
+        let openPanel = NSOpenPanel()
+        openPanel.allowsMultipleSelection = false
+        openPanel.allowedFileTypes = ["pdf"]
+        openPanel.beginSheetModal(for: NSApp.mainWindow!) { result in
+            if result == .cancel {
+                return
+            }
+            
+            if !openPanel.url!.path.isPDFValid() {
+                let alert = NSAlert()
+                alert.alertStyle = .critical
+                alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
+                alert.runModal()
+                return
+            }
+            
+            KMBaseWindowController.checkPassword(url: URL(fileURLWithPath: openPanel.url!.path), type: .owner) { [unowned self] success, resultPassword in
+                if success {
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
+                        let controller = KMCompareWindowController(windowNibName: "KMCompareWindowController")
+                        
+                        controller.password = resultPassword
+                        controller.filePath = openPanel.url!.path
+                        
+                        controller.cancelAction = { [unowned self] contr in
+                            self.view.window?.endSheet((controller.window)!)
+                        }
+                        
+                        controller.contentComplete = { [unowned self] controller, pdfCompareContent, result, oldDocument, document in
+                            DispatchQueue.main.async {
+                                self.view.window?.endSheet((controller.window)!)
+                                
+//                                self.openContentCompareVC(with: pdfCompareContent, results: result, oldDocument: oldDocument, document: document)
+                            }
+                        }
+                        
+                        controller.coveringComplete = { [unowned self] controller, document in
+                            self.view.window?.endSheet((controller.window)!)
+                            
+//                            self.openCoveringCompareVC(with: document)
+                        }
+                        controller.fileType = .content
+                        
+                        NSWindow.currentWindow().beginSheet(controller.window!)
+                    }
+                } else {
+                    
+                }
+            }
+        }
+    }
+    
+    func fastTool_Watermark() { // 水印
+        if !IAPProductsManager.default().isAvailableAllFunction(){
+            let winC = KMPurchaseCompareWindowController.sharedInstance()
+            winC?.showWindow(nil)
+            return
+        }
+        
+        let openPanel = NSOpenPanel()
+        openPanel.allowedFileTypes = ["pdf","PDF"]
+        //MARK: 允许多选还是单选,如果是付费用户允许多选
+        openPanel.allowsMultipleSelection = false
+        openPanel.beginSheetModal(for: NSWindow.currentWindow()) { [self] (result) in
+            if result == NSApplication.ModalResponse.OK {
+                quickWaterMark(urls: openPanel.urls)
+            }
+        }
+    }
+    
+    func quickWaterMark(urls: Array<URL>) {
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
+            var arr: Array<KMBatchOperateFile> = Array()
+            for fileURL in urls {
+                let pdf = CPDFDocument(url: fileURL)
+                if !pdf!.allowsPrinting || !pdf!.allowsCopying {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.messageText = NSLocalizedString("This is a secured document. Editing is not permitted.", comment: "")
+                    alert.runModal()
+                    return
+                }
+                
+                let file = KMBatchOperateFile(filePath: fileURL.path, type: KMBatchQuickActionManager.defaultManager.actionType == .add ? .AddWatermark : .RemoveWatermark)
+                arr.append(file)
+            }
+            let baseWindowController = KMBatchOperateBaseWindowController(windowNibName: "KMBatchOperateBaseWindowController")
+            if #available(macOS 10.13, *) {
+                baseWindowController.window?.makeKeyAndOrderFront(nil)
+            } else {
+                baseWindowController.showWindow(nil)
+            }
+            if arr.count > 0 {
+                baseWindowController.checkNeedPasswordSwitchToOperateType(operateType: KMBatchQuickActionManager.defaultManager.actionType == .add ? .AddWatermark : .RemoveWatermark, files: arr)
+            }
+        }
+    }
+    
+    func fastTool_Background() {    // 背景
+        if !IAPProductsManager.default().isAvailableAllFunction(){
+            let winC = KMPurchaseCompareWindowController.sharedInstance()
+            winC?.showWindow(nil)
+            return
+        }
+
+        let openPanel = NSOpenPanel()
+        openPanel.allowedFileTypes = ["pdf","PDF"]
+        //MARK: 允许多选还是单选,如果是付费用户允许多选
+        openPanel.allowsMultipleSelection = false
+        openPanel.beginSheetModal(for: NSWindow.currentWindow()) { [self] (result) in
+            if result == NSApplication.ModalResponse.OK {
+                quickBackgroudMark(urls: openPanel.urls)
+            }
+        }
+    }
+    
+    func quickBackgroudMark(urls: Array<URL>) {
+        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
+            var arr: Array<KMBatchOperateFile> = Array()
+            for fileURL in urls {
+                let pdf = CPDFDocument(url: fileURL)
+                if !pdf!.allowsPrinting || !pdf!.allowsCopying {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.messageText = NSLocalizedString("This is a secured document. Editing is not permitted.", comment: "")
+                    alert.runModal()
+                    return
+                }
+                
+                let file = KMBatchOperateFile(filePath: fileURL.path, type: KMBatchQuickActionManager.defaultManager.actionType == .add ? .AddBackground : .RemoveBackground)
+                arr.append(file)
+            }
+            let baseWindowController = KMBatchOperateBaseWindowController(windowNibName: "KMBatchOperateBaseWindowController")
+            if #available(macOS 10.13, *) {
+                baseWindowController.window?.makeKeyAndOrderFront(nil)
+            } else {
+                baseWindowController.showWindow(nil)
+            }
+            if arr.count > 0 {
+                baseWindowController.checkNeedPasswordSwitchToOperateType(operateType: KMBatchQuickActionManager.defaultManager.actionType == .add ? .AddBackground : .RemoveBackground, files: arr)
+            }
+        }
+    }
+     
+    
+    func fastTool_Print() { // 打印
+        KMPrintWindowController.openFiles(window: self.view.window!)
+    }
+    
+    func fastTool_Insert() {    // 插入
+        if !IAPProductsManager.default().isAvailableAllFunction(){
+            KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
+            return
+        }
+
+        let openPanel = NSOpenPanel()
+        openPanel.prompt = NSLocalizedString("Insert", comment: "")
+        openPanel.allowsMultipleSelection = false
+        openPanel.allowedFileTypes = ["pdf"]
+        
+        openPanel.beginSheetModal(for: NSApp.mainWindow!) { result in
+            if result == .OK {
+              
+                let windowC = KMPDFInsertWindowController(fileURL: openPanel.url!)
+ 
+                windowC.callback = { [weak self] idx, params in
+                    if params.count >= 4 {
+                        if let doc = params.first as? CPDFDocument {
+                             self?.savePDFDocument(doc, password: params[1] as? String ?? "")
+                        }
+                    }
+                    self?.km_endSheet()
+                }
+                self.km_beginSheet(windowC: windowC)
+            }
+        }
+    }
+    
+    func savePDFDocument(_ pdf: CPDFDocument, password: String) -> Void {
+        DispatchQueue.global(qos: .`default`).async {
+            var isSuccessfully = false
+            if pdf.isEncrypted {
+                let dic = [
+                    CPDFDocumentWriteOption.userPasswordOption : password,
+                    CPDFDocumentWriteOption.ownerPasswordOption : password
+                ]
+                isSuccessfully = pdf.write(to: pdf.documentURL, withOptions: dic)
+            } else {
+                isSuccessfully = pdf.write(to: pdf.documentURL)
+            }
+            if !isSuccessfully {
+                if let data = pdf.dataRepresentation() {
+                    isSuccessfully = NSData(data: data).write(to: pdf.documentURL, atomically: true)
+                }
+            }
+            
+            DispatchQueue.main.sync {
+                if isSuccessfully {
+                    let workspace = NSWorkspace.shared
+                    let url = URL(fileURLWithPath: pdf.documentURL?.path ?? "")
+                    workspace.activateFileViewerSelecting([url])
+                } else {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.messageText = NSLocalizedString("Failed to insert page(s)!", comment:  "")
+                    alert.runModal()
+                }
+            }
+        }
+    }
+    
+    func fastTool_Extract() {   // 提取
+        let openPanel = NSOpenPanel()
+        openPanel.prompt = "提取"
+        openPanel.allowsMultipleSelection = false
+        openPanel.allowedFileTypes = ["pdf"]
+        openPanel.beginSheetModal(for: NSApp.mainWindow!) { result in
+            if result == .OK {
+                DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
+                    let insertWindowController: KMPDFInsertPageWindow = KMPDFInsertPageWindow.init(documentPath: openPanel.url!, toolType: .Extract)
+                    insertWindowController.beginSheetExtractModal(for: self.view.window!) { pdfDocument, pages, oneDocumentPerPage, isDeletePage in
+                        self.extractPageAction(pdfDocument, pages, oneDocumentPerPage, isDeletePage)
+                    }
+                }
+            }
+        }
+    }
+    
+    func extractPageAction(_ pdfDocument: CPDFDocument, _ pages: [CPDFPage], _ oneDocumentPerPage: Bool, _ isDeletePage: Bool) -> Void {
+        
+        if pages.count < 1 {
+            let alert = NSAlert()
+            alert.alertStyle = .critical
+            alert.messageText = NSLocalizedString("Please select two or more pages first to organize.", comment:  "")
+            alert.runModal()
+            return
+        }
+        
+        if !oneDocumentPerPage {
+            let fileName = pdfDocument.getFileNameAccordingSelctPages(pages)
+            let outputSavePanel = NSSavePanel()
+            outputSavePanel.allowedFileTypes = ["pdf"]
+            outputSavePanel.nameFieldStringValue = fileName
+            
+            outputSavePanel.beginSheetModal(for: self.view.window!) { result in
+                if result == .OK {
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+                        let saveFilePath = outputSavePanel.url?.path
+                        DispatchQueue.global().async {
+                            var pdf = CPDFDocument.init()
+                            let success = (pdf!.extractAsOneDocument(withPages: pages, savePath: saveFilePath)) as Bool
+                            DispatchQueue.main.async {
+                                if success {
+                                    let workspace = NSWorkspace.shared
+                                    let url = URL(fileURLWithPath: saveFilePath!)
+                                    workspace.activateFileViewerSelecting([url])
+                                    
+                                    if isDeletePage {
+                                        for page in pages {
+                                            let indexPage = pdfDocument.index(for: page)
+                                            pdfDocument.removePage(at: indexPage)
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } else {
+            let panel = NSOpenPanel()
+            panel.canChooseFiles = false
+            panel.canChooseDirectories = true
+            panel.canCreateDirectories = true
+            panel.allowsMultipleSelection = false
+            panel.beginSheetModal(for: self.view.window!) { result in
+                if result == .OK {
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+                        let outputURL = panel.url
+                        DispatchQueue.global().async {
+                            let folderName = String(pdfDocument.documentURL!.lastPathComponent.split(separator: ".")[0]) + "_extract"
+                            
+                            var filePath = URL(fileURLWithPath: outputURL!.path).appendingPathComponent(folderName).path
+                            var i = 1
+                            let testFilePath = filePath
+                            while FileManager.default.fileExists(atPath: filePath) {
+                                filePath = testFilePath + "\(i)"
+                                i += 1
+                            }
+                            
+                            try? FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false, attributes: nil)
+                            
+                            let successArray = pdfDocument.extractPerPageDocument(withPages: pages, folerPath: filePath)
+                            DispatchQueue.main.async {
+                                if successArray!.count > 0 {
+                                    NSWorkspace.shared.activateFileViewerSelecting(successArray!)
+                                    
+                                    if !isDeletePage {
+                                        for page in pages {
+                                            let indexPage = pdfDocument.index(for: page)
+                                            pdfDocument.removePage(at: indexPage)
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

+ 0 - 1
PDF Office/PDF Master/KMClass/KMHomeViewController/Views/KMHomeQuickTools/KMNHomeQuickToolManager.swift

@@ -119,7 +119,6 @@ class KMNHomeQuickToolMode: NSObject {
             mode.toolImageName = "KMNImageNameQuickToolPrint"
             mode.isNewState = true
         }
-        mode.isNewState = true
         return mode
     }
 }

+ 11 - 2
PDF Office/PDF Master/KMClass/KMHomeViewController/Views/KMHomeQuickToolsView/KMHomeQuickToolsView.swift

@@ -91,6 +91,10 @@ public class KMHomeQuickToolsView: BaseXibView {
         moreButton.reloadData()
         moreButton.setTarget(self, action: #selector(moreButtonClicked(_:)))
         
+        let items = [cardPDFTool1, cardPDFTool2, cardPDFTool3, cardPDFTool4, cardPDFTool5, cardPDFTool6, cardPDFTool7, cardPDFTool8]
+        for item in items {
+            item!.delegate = self
+        }
         
     }
     
@@ -166,6 +170,7 @@ public class KMHomeQuickToolsView: BaseXibView {
                                                                    icon: NSImage(named: toolMode.toolImageName),
                                                                    text: toolMode.toolTitle,
                                                                    subText: toolMode.toolSubtitle)
+                cardItem.properties.customData = toolMode
             }
             if toolMode.isNewState {
                 let tagItem = tagItems[index]
@@ -214,8 +219,12 @@ public class KMHomeQuickToolsView: BaseXibView {
 //MARK: -
 extension KMHomeQuickToolsView: ComponentCardPDFToolDelegate {
     public func componentCardPDFToolDidClicked(_ view: ComponentCardPDFTool) {
-        let toolType = HomeQuickToolType(rawValue: KMNHomeQuickToolManager.defaultManager.quickToolsItemMutableArray[view.viewTag-1000])!
-        self.delegate?.homeQuickToolsViewDidItemClicked?(self, toolType)
+        if view.properties.customData is KMNHomeQuickToolMode {
+            let toolMode: KMNHomeQuickToolMode = view.properties.customData as! KMNHomeQuickToolMode
+                
+            delegate?.homeQuickToolsViewDidItemClicked?(self, toolMode.quickToolType)
+        }
+        
     }
 }
 

+ 5 - 6
PDF Office/PDF Master/KMClass/KMHomeViewController/Views/KMHomeRightView/KMHomeRightView.swift

@@ -324,7 +324,7 @@ extension KMHomeRightView: NSCollectionViewDelegate, NSCollectionViewDataSource,
                 filesEmptyView.frame = CGRectMake((CGRectGetWidth(collectionView.frame)-520)/2, (344-184)/2, 520, 184)
                 filesEmptyView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
                 filesEmptyView.emptyView.setTarget(self, action: #selector(emptyViewAddFileClicked(_:)))
-                view.addSubview(self.filesEmptyView)
+                view.addSubview(filesEmptyView)
                 
             }
             return view
@@ -401,7 +401,6 @@ extension KMHomeRightView: KMHomeFilesHeaderViewDelegate {
     public func homeFilesHeaderViewDeleteButtonClicked(_ view: KMHomeFilesHeaderView) {
         
         if UserDefaults.standard.object(forKey: "HomeFilesDeleteConfirmKey") != nil {
-            
             var selects: [URL] = []
             if HistoryFilesManager.manager.selectFiles.count > 0 {
                 for selecturl in HistoryFilesManager.manager.selectFiles {
@@ -508,16 +507,16 @@ extension KMHomeRightView: KMHistoryFileListItemDelegate {
                 collectionView.selectItems(at: [indexPath], scrollPosition: .nearestHorizontalEdge)
             }
         }
-        self.groupActionView = view.moreButton
+        groupActionView = view.moreButton
 
         var point = view.moreButton.superview?.convert(view.moreButton.frame.origin, to: self) ?? CGPointZero
         point.x -= 216
-        self.showFileMoreActionMenu(point: point)
+        showFileMoreActionMenu(point: point)
     }
     
     public func historyFileListItemDidDoubleClicked(_ view: KMHistoryFileListItem) {
         if let url = view.fileURL {
-            self.delegate?.homeRightViewDidChooseFileToOpen?(self, url)
+            delegate?.homeRightViewDidChooseFileToOpen?(self, url)
         }
     }
 }
@@ -526,7 +525,7 @@ extension KMHomeRightView: KMHistoryFileListItemDelegate {
 extension KMHomeRightView: KMHistoryFileThumbItemDelegate {
     func historyFileThumbItemDidDoubleClicked(_ view: KMHistoryFileThumbItem) {
         if let url = view.fileURL {
-            self.delegate?.homeRightViewDidChooseFileToOpen?(self, url)
+            delegate?.homeRightViewDidChooseFileToOpen?(self, url)
         }
     }
 }

+ 0 - 32
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -1020,22 +1020,6 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "2647257D-FE51-4BF8-A749-F1FE1A66668E"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "KMComponentLibrary/KMComponentLibrary/View/Segmented/ComponentSegmentedItem.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "107"
-            endingLineNumber = "107"
-            landmarkName = "mouseUp(with:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent
@@ -1260,21 +1244,5 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "5786CF51-BA42-44DA-8BE9-CA6C95141F35"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/KMClass/KMHomeViewController/KMNHomeViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "166"
-            endingLineNumber = "166"
-            landmarkName = "homeRightViewDidQuickToolsItemClicked(_:_:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
    </Breakpoints>
 </Bucket>