|
@@ -100,8 +100,9 @@ class KMCompareView: BaseXibView {
|
|
|
|
|
|
convenience init(pdfDocument: PDFDocument) {
|
|
|
self.init()
|
|
|
+
|
|
|
self.pdfOldDocument = pdfDocument
|
|
|
- let document: PDFDocument = PDFDocument.init(url: pdfDocument.documentURL!)!
|
|
|
+
|
|
|
let cDocument: CPDFDocument = CPDFDocument.init(url: pdfDocument.documentURL!)
|
|
|
|
|
|
let file: KMFileAttribute = KMFileAttribute()
|
|
@@ -113,6 +114,7 @@ class KMCompareView: BaseXibView {
|
|
|
|
|
|
convenience init(filePath: String, password: String) {
|
|
|
self.init()
|
|
|
+
|
|
|
self.pdfOldDocument = PDFDocument.init(url: NSURL(fileURLWithPath: filePath) as URL)
|
|
|
let pdfDocument = PDFDocument.init(url: NSURL(fileURLWithPath: filePath) as URL)
|
|
|
let cDocument = CPDFDocument.init(url: NSURL(fileURLWithPath: filePath) as URL)
|
|
@@ -158,10 +160,8 @@ class KMCompareView: BaseXibView {
|
|
|
|
|
|
oldPDFView.wantsLayer = true
|
|
|
pdfNewView.wantsLayer = true
|
|
|
-// vsMaskView.wantsLayer = true;
|
|
|
oldPDFView.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
pdfNewView.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
-// vsMaskView.layer.backgroundColor = NSColor.clear.CGColor
|
|
|
|
|
|
compareTypeSegment.wantsLayer = true
|
|
|
compareTypeSegment.layer?.cornerRadius = 5.0
|
|
@@ -200,6 +200,8 @@ class KMCompareView: BaseXibView {
|
|
|
}
|
|
|
|
|
|
KMCompareFilesConfig.defaultConfig.fileNewAttribute.pdfDocument = nil
|
|
|
+
|
|
|
+ updateLanguage()
|
|
|
}
|
|
|
|
|
|
func updateLanguage() {
|
|
@@ -300,12 +302,10 @@ extension KMCompareView {
|
|
|
let document: PDFDocument = PDFDocument.init(url: NSURL(fileURLWithPath: filePath) as URL) ?? PDFDocument()
|
|
|
let cDocument: CPDFDocument = CPDFDocument.init(url: NSURL(fileURLWithPath: filePath) as URL)!
|
|
|
let file: KMFileAttribute = KMFileAttribute()
|
|
|
-// file.pdfDocument = cDocument
|
|
|
-// file.myPDFDocument = document
|
|
|
+
|
|
|
file.password = password
|
|
|
file.filePath = filePath
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
document.unlock(withPassword: password)
|
|
|
cDocument.unlock(withPassword: password)
|
|
|
|
|
@@ -410,25 +410,9 @@ extension KMCompareView {
|
|
|
let fileManager = FileManager.default
|
|
|
for path in fileSelectedCachePaths {
|
|
|
if fileManager.fileExists(atPath: path) {
|
|
|
-// #if VERSION_DMG
|
|
|
fileSelectedPaths.append(path.lastPathComponent)
|
|
|
filePaths.append(path)
|
|
|
-// #else
|
|
|
-// let url = URL(fileURLWithPath: path)
|
|
|
-//
|
|
|
-// if let bookmarkData = try? url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil) {
|
|
|
-// AppSandboxFileAccess.fileAccess().bookmarkPersistanceDelegate.setBookmarkData(bookmarkData, forURL: url)
|
|
|
-// AppSandboxFileAccess.fileAccess().bookmarkPersistanceDelegate.setBookmarkData(bookmarkData, forURL: URL(fileURLWithPath: url.path ?? url.absoluteString))
|
|
|
-//
|
|
|
-// fileOldSelectedPaths.append(path)
|
|
|
-// } else {
|
|
|
-// AppSandboxFileAccess.fileAccess().accessFileURL(url, persistPermission: yearMask) {
|
|
|
-// if let bookmarkData = try? url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil) {
|
|
|
-// fileOldSelectedPaths.append(path)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// #endif
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -492,10 +476,6 @@ extension KMCompareView {
|
|
|
pdfDocument = KMCompareFilesConfig.defaultConfig.fileOldAttribute.pdfDocument
|
|
|
}
|
|
|
|
|
|
-// guard let pdfDocument = pdfDocument else {
|
|
|
-// completion(nil)
|
|
|
-// return
|
|
|
-// }
|
|
|
if (pdfDocument?.documentURL.path == filePath) {
|
|
|
let alert = NSAlert()
|
|
|
alert.alertStyle = NSAlert.Style.critical
|
|
@@ -523,17 +503,23 @@ extension KMCompareView {
|
|
|
func updatePageRangeData(view: NSComboBox, file: KMFileAttribute, isNew: Bool = false) {
|
|
|
switch (file.pagesType) {
|
|
|
case .all:
|
|
|
- view.selectItem(at: 0)
|
|
|
+ if view.numberOfItems > 0 {
|
|
|
+ view.selectItem(at: 0)
|
|
|
+ }
|
|
|
view.isEditable = false
|
|
|
view.delegate = nil
|
|
|
break;
|
|
|
case .odd:
|
|
|
- view.selectItem(at: 1)
|
|
|
+ if view.numberOfItems > 0 {
|
|
|
+ view.selectItem(at: 1)
|
|
|
+ }
|
|
|
view.isEditable = false
|
|
|
view.delegate = nil
|
|
|
break;
|
|
|
case .even:
|
|
|
- view.selectItem(at: 2)
|
|
|
+ if view.numberOfItems > 0 {
|
|
|
+ view.selectItem(at: 2)
|
|
|
+ }
|
|
|
view.isEditable = false
|
|
|
view.delegate = nil
|
|
|
break;
|
|
@@ -726,28 +712,11 @@ extension KMCompareView {
|
|
|
}
|
|
|
|
|
|
func chooseFileAction(isNew: Bool = false) {
|
|
|
-// fileQKNewSelectedBox.resignFirstResponder()
|
|
|
-// self.window?.makeFirstResponder(nil)
|
|
|
-
|
|
|
let openPanel = NSOpenPanel()
|
|
|
openPanel.allowedFileTypes = ["pdf"]
|
|
|
openPanel.allowsMultipleSelection = false
|
|
|
openPanel.beginSheetModal(for: self.window!) { (result) in
|
|
|
if result == NSApplication.ModalResponse.OK {
|
|
|
- #if VERSION_DMG
|
|
|
- // Add code for VERSION_DMG
|
|
|
- #else
|
|
|
-// if let url = openPanel.url {
|
|
|
-// do {
|
|
|
-// let bookmarkData = try url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil)
|
|
|
-// AppSandboxFileAccess.fileAccess().bookmarkPersistanceDelegate.setBookmarkData(bookmarkData, forURL: url)
|
|
|
-// AppSandboxFileAccess.fileAccess().bookmarkPersistanceDelegate.setBookmarkData(bookmarkData, forURL: URL(fileURLWithPath: url.path ?? url.absoluteString))
|
|
|
-// } catch {
|
|
|
-// // Handle error
|
|
|
-// print("Error creating bookmark data: \(error)")
|
|
|
-// }
|
|
|
-// }
|
|
|
- #endif
|
|
|
|
|
|
if let filePath = openPanel.url?.path {
|
|
|
let url = NSURL(fileURLWithPath: filePath)
|
|
@@ -757,31 +726,7 @@ extension KMCompareView {
|
|
|
AppSandboxFileAccess().bookmarkPersistanceDelegate.setBookmarkData(bookmarkData! as Data, for: url as URL)
|
|
|
AppSandboxFileAccess().bookmarkPersistanceDelegate.setBookmarkData(bookmarkData! as Data, for: NSURL(fileURLWithPath: url.path!) as URL)
|
|
|
}
|
|
|
-
|
|
|
-// let isAccessFilePath = AppSandboxFileAccess().accessFileURL(url as URL, persistPermission: true) {
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// if (isAccessFilePath) {
|
|
|
-// print("获取权限成功")
|
|
|
-// let url = NSURL(fileURLWithPath: filePath)
|
|
|
-// let bookmarkData = try?url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)
|
|
|
-// if bookmarkData != nil {
|
|
|
-// AppSandboxFileAccess().bookmarkPersistanceDelegate.setBookmarkData(bookmarkData, for: url as URL)
|
|
|
-// AppSandboxFileAccess().bookmarkPersistanceDelegate.setBookmarkData(bookmarkData, for: NSURL(fileURLWithPath: url.path!) as URL)
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// print("获取权限失败")
|
|
|
-// }
|
|
|
-
|
|
|
-// NSURL *url = [NSURL fileURLWithPath:folderPath];
|
|
|
-// [[AppSandboxFileAccess fileAccess] persistPermissionURL:url];
|
|
|
-// NSData *bookmarkData = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:NULL];
|
|
|
-// if (bookmarkData) {
|
|
|
-// [[AppSandboxFileAccess fileAccess].bookmarkPersistanceDelegate setBookmarkData:bookmarkData forURL:url];
|
|
|
-// [[AppSandboxFileAccess fileAccess].bookmarkPersistanceDelegate setBookmarkData:bookmarkData forURL:[NSURL fileURLWithPath:(url.path?:url.absoluteString)]];
|
|
|
-// }
|
|
|
-
|
|
|
+
|
|
|
self.updateDocument(filePath: filePath, isNew: isNew) { [weak self] file in
|
|
|
if let _ = file {
|
|
|
self?.addFilePath(filePath: filePath, isNew: isNew, password: file?.password ?? "")
|