|
@@ -94,7 +94,15 @@ class KMMergeView: KMBaseXibView {
|
|
|
boxLabel.textColor = KMAppearance.Layout.h0Color()
|
|
|
|
|
|
blankView.dragAction = { [weak self] filePaths in
|
|
|
- self?.addFilePaths(urls: filePaths)
|
|
|
+ var theFileUrls: [URL] = []
|
|
|
+ for fileUrl in filePaths {
|
|
|
+ if KMTools.isImageType(fileUrl.pathExtension) {
|
|
|
+ self?.addImageFile(fileUrl: fileUrl)
|
|
|
+ } else {
|
|
|
+ theFileUrls.append(fileUrl)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self?.addFilePaths(urls: theFileUrls)
|
|
|
}
|
|
|
|
|
|
blankView.mouseDownAction = { [unowned self] view in
|
|
@@ -210,7 +218,11 @@ extension KMMergeView: NSTableViewDelegate {
|
|
|
if url!.path.lowercased().hasSuffix("pdf") {
|
|
|
isCanDrag = true
|
|
|
} else {
|
|
|
- isCanDrag = false
|
|
|
+ if KMTools.isImageType(url?.pathExtension ?? "") {
|
|
|
+ isCanDrag = true
|
|
|
+ } else {
|
|
|
+ isCanDrag = false
|
|
|
+ }
|
|
|
}
|
|
|
} else if (pboard.availableType(from: [MyTableCellViewDataType]) != nil) {
|
|
|
result = .every
|
|
@@ -257,7 +269,15 @@ extension KMMergeView: NSTableViewDelegate {
|
|
|
// array.append(URL(string: path)!)
|
|
|
//// }
|
|
|
// }
|
|
|
- addFilePaths(urls: array)
|
|
|
+ var theFileUrls: [URL] = []
|
|
|
+ for fileUrl in array {
|
|
|
+ if KMTools.isImageType(fileUrl.pathExtension) {
|
|
|
+ self.addImageFile(fileUrl: fileUrl)
|
|
|
+ } else {
|
|
|
+ theFileUrls.append(fileUrl)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ addFilePaths(urls: theFileUrls)
|
|
|
result = true
|
|
|
} else if pboard.availableType(from: [MyTableCellViewDataType]) != nil {
|
|
|
guard let data = info.draggingPasteboard.data(forType: MyTableCellViewDataType),
|
|
@@ -392,6 +412,40 @@ extension KMMergeView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ func addImageFile(fileUrl: URL) {
|
|
|
+ if let image = NSImage(contentsOf: fileUrl) {
|
|
|
+ if let page = PDFPage(image: image) {
|
|
|
+ let document = PDFDocument()
|
|
|
+ document.insert(page, at: 0)
|
|
|
+
|
|
|
+ var path = self._saveImagePath() + "/" + fileUrl.deletingPathExtension().lastPathComponent + ".pdf"
|
|
|
+ path = KMTools.getUniqueFilePath(filePath: path)
|
|
|
+ let result = document.write(toFile: path)
|
|
|
+ if result {
|
|
|
+ let file = KMFileAttribute()
|
|
|
+ file.filePath = path
|
|
|
+ file.oriFilePath = fileUrl.path
|
|
|
+ file.myPDFDocument = document
|
|
|
+
|
|
|
+// let attribe = try?FileManager.default.attributesOfItem(atPath: fileURL.path)
|
|
|
+// let fileSize = attribe?[FileAttributeKey.size] as? CGFloat ?? 0
|
|
|
+// size = fileSize + size
|
|
|
+//
|
|
|
+// if !IAPProductsManager.default().isAvailableAllFunction() && (files.count >= 2 || size > 20 * 1024 * 1024) {
|
|
|
+// KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
|
|
|
+// return
|
|
|
+// }
|
|
|
+
|
|
|
+ self.files.append(file)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Task {
|
|
|
+ _ = await KMAlertTool.runModel(message: NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: ""))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
func openPasswordFile(completion: @escaping ((_ success: Bool, _ resultPassword: String) -> Void)) {
|
|
|
if lockFiles.count != 0 {
|
|
|
let file = lockFiles[lockFilesIndex]
|
|
@@ -429,4 +483,13 @@ extension KMMergeView {
|
|
|
|
|
|
return false
|
|
|
}
|
|
|
+
|
|
|
+ private func _saveImagePath() -> String {
|
|
|
+ let rootPath = KMDataManager.fetchAppSupportOfBundleIdentifierDirectory()
|
|
|
+ let path = rootPath.appendingPathComponent("Merge").path
|
|
|
+ if FileManager.default.fileExists(atPath: path) == false {
|
|
|
+ try?FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: false)
|
|
|
+ }
|
|
|
+ return path
|
|
|
+ }
|
|
|
}
|