|
@@ -157,6 +157,7 @@ extension KMHomeViewController {
|
|
|
fastTool_PageEdit()
|
|
|
break
|
|
|
case .ComparativeTable:
|
|
|
+ fastTool_FileCompare()
|
|
|
break
|
|
|
case .equity:
|
|
|
break
|
|
@@ -1206,8 +1207,59 @@ extension KMHomeViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func fastTool_FileCompare() { // 文件对比
|
|
|
- KMPrint("选中 快捷工具 文件对比")
|
|
|
+ func fastTool_FileCompare() { // 文件对比
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
|
|
|
+ let controller = KMCompareWindowController(windowNibName: "KMCompareWindowController")
|
|
|
+ self.currentWindowController = controller
|
|
|
+
|
|
|
+ controller.filePath = openPanel.url!.path
|
|
|
+
|
|
|
+ controller.cancelAction = { [unowned self] contr in
|
|
|
+ self.view.window?.endSheet((controller.window)!)
|
|
|
+// self.currentWindowController = nil
|
|
|
+ }
|
|
|
+
|
|
|
+ controller.contentComplete = { [unowned self] controller, pdfCompareContent, result, oldDocument, document in
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.view.window?.endSheet((controller.window)!)
|
|
|
+// self.currentWindowController = nil
|
|
|
+
|
|
|
+ self.openContentCompareVC(with: pdfCompareContent, results: result, oldDocument: oldDocument, document: document)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ controller.coveringComplete = { [unowned self] controller, document in
|
|
|
+ self.view.window?.endSheet((controller.window)!)
|
|
|
+// self.currentWindowController = nil
|
|
|
+
|
|
|
+ self.openCoveringCompareVC(with: document)
|
|
|
+ }
|
|
|
+
|
|
|
+// if index == 1 {
|
|
|
+ controller.fileType = .content
|
|
|
+// } else {
|
|
|
+// controller.fileType = .coverting
|
|
|
+// }
|
|
|
+
|
|
|
+ NSWindow.currentWindow().beginSheet(controller.window!)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func fastTool_PDFToPPT() {
|
|
@@ -1607,6 +1659,7 @@ extension KMHomeViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@IBAction func escButtonAction(_ sender: Any) {
|
|
|
// self.historyFileViewController.selectFiles.removeAll()
|
|
|
// if self.historyFileViewController.showMode == .Thumbnail {
|
|
@@ -1784,3 +1837,143 @@ extension KMHomeViewController {
|
|
|
KMAnalytics.Parameter.labelKey : KMAnalytics.Label.create_Btn], platform: .AppCenter, appTarget: .all)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+extension KMHomeViewController {
|
|
|
+ //文件对比
|
|
|
+ func openContentCompareVC(with pdfCompareContent: CPDFCompareContent?, results: [CPDFCompareResults], oldDocument: CPDFDocument, document: CPDFDocument) {
|
|
|
+ let compareContentController = KMCompareContentWindowController(document: document, oldDocument: oldDocument, results: results)
|
|
|
+ self.currentController = compareContentController
|
|
|
+// let compareContentView = KMCompareContentView()
|
|
|
+// compareContentView.oldDocument = oldDocument
|
|
|
+// compareContentView.document = document
|
|
|
+// compareContentView.compareResults = results
|
|
|
+ compareContentController.saveHandle = { [unowned self] view in
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.25) { [unowned self] in
|
|
|
+ let saveController = KMCompareSaveWindow(windowNibName: "KMCompareSaveWindow")
|
|
|
+ self.currentWindowController = saveController
|
|
|
+ saveController.cancelHandle = { [unowned self] controller in
|
|
|
+ NSWindow.currentWindow().endSheet(controller.window!)
|
|
|
+ self.currentWindowController = nil
|
|
|
+ }
|
|
|
+
|
|
|
+ saveController.saveHandle = { [unowned self] controller, saveType in
|
|
|
+ let folderPath = controller.fileSaveFolderPath
|
|
|
+ if folderPath != nil {
|
|
|
+ if !FileManager.default.fileExists(atPath: folderPath) {
|
|
|
+ try? FileManager.default.createDirectory(atPath: folderPath, withIntermediateDirectories: true, attributes: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ var savePath: String
|
|
|
+
|
|
|
+
|
|
|
+ switch saveType {
|
|
|
+ case 0:
|
|
|
+ let filePath = oldDocument.documentURL.path
|
|
|
+ let fileName = filePath.deletingPathExtension.lastPathComponent
|
|
|
+
|
|
|
+ savePath = "\(folderPath)/\(fileName.deletingPathExtension)_compare\(filePath.extension)"
|
|
|
+ savePath = self.getValidFilePath(savePath)
|
|
|
+ oldDocument.write(to: URL(fileURLWithPath: savePath))
|
|
|
+ NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: savePath)])
|
|
|
+ case 1:
|
|
|
+ let filePath = document.documentURL.path
|
|
|
+ let fileName = filePath.deletingPathExtension.lastPathComponent
|
|
|
+
|
|
|
+ savePath = "\(folderPath)/\(fileName)_compare\(filePath.extension)"
|
|
|
+ savePath = self.getValidFilePath(savePath)
|
|
|
+ document.write(to: URL(fileURLWithPath: savePath))
|
|
|
+ NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: savePath)])
|
|
|
+ case 2:
|
|
|
+ let filePath = oldDocument.documentURL.path
|
|
|
+ let fileName = filePath.deletingPathExtension.lastPathComponent
|
|
|
+
|
|
|
+ savePath = "\(folderPath)/MergedCompareFile\(filePath.extension)"
|
|
|
+ savePath = self.getValidFilePath(savePath)
|
|
|
+ pdfCompareContent!.saveAsComparisonDocument(withFilePath: savePath)
|
|
|
+ NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: savePath)])
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ NSWindow.currentWindow().endSheet(controller.window!)
|
|
|
+ self.currentWindowController = nil
|
|
|
+ }
|
|
|
+
|
|
|
+ NSWindow.currentWindow().beginSheet(saveController.window!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ compareContentController.closeHandle = { [unowned self] controller in
|
|
|
+ self.view.window!.endSheet(controller.window!)
|
|
|
+ self.currentController = nil
|
|
|
+// view.removeFromSuperview()
|
|
|
+ }
|
|
|
+ NSWindow.currentWindow().beginSheet(compareContentController.window!)
|
|
|
+
|
|
|
+
|
|
|
+// self.PDFContendView.addSubview(compareContentView)
|
|
|
+// compareContentView.frame = self.PDFContendView.bounds
|
|
|
+// compareContentView.autoresizingMask = [.width,.height]
|
|
|
+ }
|
|
|
+
|
|
|
+ func getValidFilePath(_ oldPath: String) -> String {
|
|
|
+ let fileManager = FileManager.default
|
|
|
+
|
|
|
+ do {
|
|
|
+ let fileAttributes = try fileManager.attributesOfItem(atPath: oldPath)
|
|
|
+ guard let fileType = fileAttributes[FileAttributeKey.type] as? String else {
|
|
|
+ return oldPath
|
|
|
+ }
|
|
|
+
|
|
|
+ var i = 1
|
|
|
+ var newPath = oldPath
|
|
|
+
|
|
|
+ while fileManager.fileExists(atPath: newPath) {
|
|
|
+ if fileType == FileAttributeType.typeDirectory.rawValue {
|
|
|
+ newPath = oldPath + "(\(i))"
|
|
|
+ } else {
|
|
|
+ let fileExtension = (oldPath as NSString).pathExtension
|
|
|
+ newPath = ((oldPath as NSString).deletingPathExtension as NSString).appendingFormat("(\(i)).\(fileExtension)" as NSString) as String
|
|
|
+ }
|
|
|
+ i += 1
|
|
|
+ }
|
|
|
+
|
|
|
+ return newPath
|
|
|
+ } catch {
|
|
|
+ print("Error getting file attributes: \(error)")
|
|
|
+ return oldPath
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func openCoveringCompareVC(with pdfDocument: CPDFDocument) {
|
|
|
+ let controller = KMCompareCoveringWindowController(document: pdfDocument)
|
|
|
+ self.currentWindowController = controller
|
|
|
+// let coveringView = KMCompareCoveringView()
|
|
|
+// coveringView.pdfDocument = pdfDocument
|
|
|
+ controller.closeHandle = { [unowned self] controller in
|
|
|
+// view.removeFromSuperview()
|
|
|
+ self.view.window!.endSheet(controller.window!)
|
|
|
+ self.currentController = nil
|
|
|
+ }
|
|
|
+
|
|
|
+ controller.saveHandle = { [unowned self] controller in
|
|
|
+ let savePanel = NSSavePanel()
|
|
|
+ savePanel.nameFieldStringValue = "untitled"
|
|
|
+ savePanel.allowedFileTypes = ["pdf"]
|
|
|
+ savePanel.beginSheetModal(for: NSWindow.currentWindow()) { result in
|
|
|
+ if result == .OK {
|
|
|
+ pdfDocument.write(to: savePanel.url!)
|
|
|
+ NSWorkspace.shared.activateFileViewerSelecting([savePanel.url!])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// self.view.window!.endSheet(controller.window!)
|
|
|
+ NSWindow.currentWindow().beginSheet(controller.window!)
|
|
|
+// self.PDFContendView.addSubview(coveringView)
|
|
|
+// coveringView.frame = self.PDFContendView.bounds
|
|
|
+// coveringView.autoresizingMask = [.width,.height]
|
|
|
+ }
|
|
|
+
|
|
|
+}
|