|
@@ -2249,6 +2249,142 @@ struct KMNMWCFlags {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //文件对比
|
|
|
+ func openContentCompareVC(with pdfCompareContent: CPDFCompareContent?, results: [CPDFCompareResults], oldDocument: CPDFDocument, document: CPDFDocument) {
|
|
|
+ self.isCompareModel = true
|
|
|
+
|
|
|
+ let compareContentView = KMCompareContentView()
|
|
|
+ compareContentView.oldDocument = oldDocument
|
|
|
+ compareContentView.document = document
|
|
|
+ compareContentView.compareResults = results
|
|
|
+ compareContentView.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
|
|
|
+ self.view.window!.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)
|
|
|
+ }
|
|
|
+#if VERSION_DMG
|
|
|
+#else
|
|
|
+ let url = URL(fileURLWithPath: folderPath)
|
|
|
+ let fileAccess = AppSandboxFileAccess()
|
|
|
+ fileAccess?.persistPermissionURL(url)
|
|
|
+ if let bookmarkData = try?url.bookmarkData(options: [.withSecurityScope]) {
|
|
|
+ fileAccess?.bookmarkPersistanceDelegate.setBookmarkData(bookmarkData, for: url)
|
|
|
+ let urlString = url.path
|
|
|
+ let _url = URL(fileURLWithPath: urlString)
|
|
|
+ fileAccess?.bookmarkPersistanceDelegate.setBookmarkData(bookmarkData, for: _url)
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ var savePath: String
|
|
|
+
|
|
|
+ switch saveType {
|
|
|
+ case 0:
|
|
|
+ let filePath = oldDocument.documentURL.path
|
|
|
+ let fileName = filePath.deletingPathExtension.lastPathComponent
|
|
|
+
|
|
|
+ savePath = "\(folderPath)/\(fileName)_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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.view.window!.endSheet(controller.window!)
|
|
|
+ self.currentWindowController = nil
|
|
|
+ }
|
|
|
+
|
|
|
+ NSWindow.currentWindow().beginSheet(saveController.window!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ compareContentView.closeHandle = { [unowned self] view in
|
|
|
+ self.isCompareModel = false
|
|
|
+ view.removeFromSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ compareContentView.autoresizingMask = [.width,.height]
|
|
|
+ }
|
|
|
+
|
|
|
+ func openCoveringCompareVC(with pdfDocument: CPDFDocument) {
|
|
|
+ self.isCompareModel = true
|
|
|
+
|
|
|
+ let coveringView = KMCompareCoveringView()
|
|
|
+ coveringView.pdfDocument = pdfDocument
|
|
|
+ coveringView.closeHandle = { [unowned self] view in
|
|
|
+ self.isCompareModel = false
|
|
|
+ view.removeFromSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ coveringView.saveHandle = { [unowned self] view 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!])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ coveringView.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
|
|
|
+ }
|
|
|
+ }
|
|
|
//MARK: - TTS
|
|
|
@IBAction func startSpeaking(_ sender: Any?) {
|
|
|
self.showTTSWindow()
|
|
@@ -6005,11 +6141,175 @@ extension KMMainViewController: ComponentGroupDelegate {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+// MARK: - KMSnapshotWindowControllerDelegate
|
|
|
|
|
|
-//MARK: -
|
|
|
-//MARK: -
|
|
|
-//MARK: -
|
|
|
-//MARK: - 旧代码,需要用到的内容需要拖出来,写好注释
|
|
|
+extension KMMainViewController: KMSnapshotWindowControllerDelegate {
|
|
|
+ func snapshotControllerWillClose(_ controller: KMSnapshotWindowController) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func snapshotController(_ controller: KMSnapshotWindowController, miniaturizedRect isMiniaturize: Bool) -> NSRect {
|
|
|
+ return CGRectZero
|
|
|
+ }
|
|
|
+
|
|
|
+ func snapshotControllerDidFinishSetup(_ controller: KMSnapshotWindowController) {
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - CPDFDocumentDelegate
|
|
|
+
|
|
|
+extension KMMainViewController: CPDFDocumentDelegate {
|
|
|
+ func documentDidBeginDocumentFind(_ document: CPDFDocument!) {
|
|
|
+ }
|
|
|
+
|
|
|
+ func documentDidEndDocumentFind(_ document: CPDFDocument!) {
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// MARK: CDistanceMeasureInfoWindowControllerDelegate
|
|
|
+
|
|
|
+extension KMMainViewController : CDistanceMeasureInfoWindowControllerDelegate {
|
|
|
+ func distanceMeasureInfoWindowControllerSetting(_ distanceMeasureInfoWindowController: CDistanceMeasureInfoWindowController) {
|
|
|
+ let distanceSettingWC = CDistanceSettingWindowController(distanceMeasureInfo: self.distanceMeasureInfoWindowController!.measureInfo)
|
|
|
+ self.distanceMeasureInfoWindowController?.hideFloatingWindow()
|
|
|
+ distanceSettingWC.delegate = self
|
|
|
+ distanceSettingWC.startModal("")
|
|
|
+ }
|
|
|
+
|
|
|
+ func cancelMeasureInfoWindowControllerSetting(_ distanceMeasureInfoWindowController: CDistanceMeasureInfoWindowController) {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: CPerimeterMeasureInfoWindowControllerDelegate
|
|
|
+
|
|
|
+extension KMMainViewController : CPerimeterMeasureInfoWindowControllerDelegate {
|
|
|
+ func perimeterMeasureInfoWindowControllerSetting(_ perimeterMeasureInfoWindowController: CPerimeterMeasureInfoWindowController) {
|
|
|
+ let distanceSettingWC = CDistanceSettingWindowController(perimeterMeasureInfo: self.perimeterMeasureInfoWindowController!.measureInfo)
|
|
|
+ self.distanceMeasureInfoWindowController?.hideFloatingWindow()
|
|
|
+ distanceSettingWC.delegate = self
|
|
|
+ distanceSettingWC.startModal("")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: CAreaMeasureInfoWindowControllerDelegate
|
|
|
+
|
|
|
+extension KMMainViewController : CAreaMeasureInfoWindowControllerDelegate {
|
|
|
+ func areaMeasureInfoWindowControllerSetting(_ areaMeasureInfoWindowController: CAreaMeasureInfoWindowController) {
|
|
|
+ let areaSettingWC = CAreaSettingWindowController(measureInfo: self.areaMeasureInfoWindowController!.measureInfo)
|
|
|
+ self.areaMeasureInfoWindowController?.hideFloatingWindow()
|
|
|
+ areaSettingWC.delegate = self
|
|
|
+ areaSettingWC.startModal("")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: CDistanceSettingWindowControllerDelegate
|
|
|
+
|
|
|
+extension KMMainViewController : CDistanceSettingWindowControllerDelegate {
|
|
|
+ func distanceSettingWindowController(_ distanceSettingWindowController: CDistanceSettingWindowController, distanceMeasureInfo: CPDFDistanceMeasureInfo?) {
|
|
|
+ if distanceMeasureInfo != nil {
|
|
|
+ if self.listView.activeAnnotations.count > 0 {
|
|
|
+ if self.listView.activeAnnotation.isKind(of: CPDFLineAnnotation.self) {
|
|
|
+ (self.listView.activeAnnotation as! CPDFLineAnnotation).measureInfo = distanceMeasureInfo
|
|
|
+ self.listView.setNeedsDisplayAnnotationViewFor(self.listView.activeAnnotation.page)
|
|
|
+ }
|
|
|
+ self.distanceMeasureInfoWindowController?.reloadData(with: (self.listView.activeAnnotation as! CPDFLineAnnotation).measureInfo!)
|
|
|
+ } else {
|
|
|
+ distanceMeasureInfo?.leadLength = 0
|
|
|
+ self.listView.distanceMeasureInfo = distanceMeasureInfo
|
|
|
+ self.distanceMeasureInfoWindowController?.reloadData(with: self.listView.distanceMeasureInfo)
|
|
|
+ self.distanceMeasureInfoWindowController?.lengthLabel.stringValue = ""
|
|
|
+ self.distanceMeasureInfoWindowController?.angleLabel.stringValue = ""
|
|
|
+ self.distanceMeasureInfoWindowController?.xLabel.stringValue = ""
|
|
|
+ self.distanceMeasureInfoWindowController?.yLabel.stringValue = ""
|
|
|
+ }
|
|
|
+
|
|
|
+ if let data = self.listView.activeAnnotation {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.distanceMeasureInfoWindowController?.showWindow(self)
|
|
|
+ }
|
|
|
+
|
|
|
+ func distanceSettingWindowController(_ distanceSettingWindowController: CDistanceSettingWindowController, perimeterMeasureInfo: CPDFPerimeterMeasureInfo?) {
|
|
|
+ if perimeterMeasureInfo != nil {
|
|
|
+ if self.listView.activeAnnotations.count > 0 {
|
|
|
+ if self.listView.activeAnnotation.isKind(of: CPDFPolylineAnnotation.self) {
|
|
|
+ (self.listView.activeAnnotation as! CPDFPolylineAnnotation).measureInfo = perimeterMeasureInfo
|
|
|
+ self.listView.setNeedsDisplayAnnotationViewFor(self.listView.activeAnnotation.page)
|
|
|
+ }
|
|
|
+ self.perimeterMeasureInfoWindowController?.reloadData(with: (self.listView.activeAnnotation as! CPDFPolylineAnnotation).measureInfo!)
|
|
|
+ } else {
|
|
|
+ self.listView.perimeterMeasureInfo = perimeterMeasureInfo
|
|
|
+ self.perimeterMeasureInfoWindowController?.reloadData(with: self.listView.perimeterMeasureInfo)
|
|
|
+ self.perimeterMeasureInfoWindowController?.lengthLabel.stringValue = ""
|
|
|
+ self.perimeterMeasureInfoWindowController?.angleLabel.stringValue = ""
|
|
|
+ }
|
|
|
+
|
|
|
+ if let data = self.listView.activeAnnotation {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.perimeterMeasureInfoWindowController?.showWindow(self)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: CAreaSettingWindowControllerDelegate
|
|
|
+
|
|
|
+extension KMMainViewController : CAreaSettingWindowControllerDelegate {
|
|
|
+ func areaSettingWindowController(_ areaSettingWindowController: CAreaSettingWindowController, measureInfo: CPDFAreaMeasureInfo?) {
|
|
|
+ if self.listView.annotationType == .measureSquare && self.listView.toolMode == .CNoteToolMode {
|
|
|
+ if measureInfo != nil {
|
|
|
+ if self.listView.activeAnnotations.count > 0 {
|
|
|
+ if self.listView.activeAnnotation.isKind(of: CPDFPolygonAnnotation.self) {
|
|
|
+ (self.listView.activeAnnotation as! CPDFPolygonAnnotation).measureInfo = measureInfo
|
|
|
+ self.listView.setNeedsDisplayAnnotationViewFor(self.listView.activeAnnotation.page)
|
|
|
+ }
|
|
|
+ self.areaMeasureInfoWindowController?.reloadData((self.listView.activeAnnotation as! CPDFPolygonAnnotation).measureInfo!)
|
|
|
+ } else {
|
|
|
+ self.listView.squareAreaMeasureInfo = measureInfo
|
|
|
+ self.areaMeasureInfoWindowController?.reloadData(self.listView.squareAreaMeasureInfo)
|
|
|
+ self.areaMeasureInfoWindowController?.areaLabel.stringValue = ""
|
|
|
+ self.areaMeasureInfoWindowController?.angleLabel.stringValue = ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.areaMeasureInfoWindowController?.showWindow(self)
|
|
|
+ } else if self.listView.annotationType == .measurePolyGon && self.listView.toolMode == .CNoteToolMode {
|
|
|
+ if measureInfo != nil {
|
|
|
+ if self.listView.activeAnnotations.count > 0 {
|
|
|
+ if self.listView.activeAnnotation.isKind(of: CPDFPolygonAnnotation.self) {
|
|
|
+ (self.listView.activeAnnotation as! CPDFPolygonAnnotation).measureInfo = measureInfo
|
|
|
+ self.listView.setNeedsDisplayAnnotationViewFor(self.listView.activeAnnotation.page)
|
|
|
+ }
|
|
|
+ self.areaMeasureInfoWindowController?.reloadData((self.listView.activeAnnotation as! CPDFPolygonAnnotation).measureInfo!)
|
|
|
+ } else {
|
|
|
+ self.listView.polygonAreaMeasureInfo = measureInfo
|
|
|
+ self.areaMeasureInfoWindowController?.reloadData(self.listView.polygonAreaMeasureInfo)
|
|
|
+ self.areaMeasureInfoWindowController?.areaLabel.stringValue = ""
|
|
|
+ self.areaMeasureInfoWindowController?.angleLabel.stringValue = ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.areaMeasureInfoWindowController?.showWindow(self)
|
|
|
+ } else {
|
|
|
+ if measureInfo != nil {
|
|
|
+ if self.listView.activeAnnotations.count > 0 {
|
|
|
+ if self.listView.activeAnnotation.isKind(of: CPDFPolygonAnnotation.self) {
|
|
|
+ (self.listView.activeAnnotation as! CPDFPolygonAnnotation).measureInfo = measureInfo
|
|
|
+ self.listView.setNeedsDisplayAnnotationViewFor(self.listView.activeAnnotation.page)
|
|
|
+ }
|
|
|
+ self.areaMeasureInfoWindowController?.reloadData((self.listView.activeAnnotation as! CPDFPolygonAnnotation).measureInfo!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.areaMeasureInfoWindowController?.showWindow(self)
|
|
|
+ }
|
|
|
+
|
|
|
+ if measureInfo != nil {
|
|
|
+ if let data = self.listView.activeAnnotation {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
extension KMMainViewController {
|
|
|
|