|
@@ -9,18 +9,438 @@ import Cocoa
|
|
|
|
|
|
typealias KMCompareViewCancelAction = (_ view: KMCompareView) -> Void
|
|
|
|
|
|
+enum KMCompareFilesType {
|
|
|
+ case content
|
|
|
+ case coverting
|
|
|
+}
|
|
|
+
|
|
|
+let CPDFOldFileQKSelectedPathsKey = "CPDFOldFileQKSelectedPathsKey"
|
|
|
+let CPDFNewFileQKSelectedPathsKey = "CPDFNewFileQKSelectedPathsKey"
|
|
|
+let CPDFMaxQKSelectedPathsCount = 5
|
|
|
|
|
|
class KMCompareView: KMBaseXibView {
|
|
|
|
|
|
@IBOutlet weak var cancelButton: NSButton!
|
|
|
@IBOutlet weak var doneButton: NSButton!
|
|
|
|
|
|
+ @IBOutlet weak var compareTypeSegment: NSSegmentedControl!
|
|
|
+ @IBOutlet weak var typeSegWidthConst: NSLayoutConstraint!
|
|
|
+
|
|
|
+ @IBOutlet weak var comparePreviewBox: NSBox!
|
|
|
+
|
|
|
+ @IBOutlet weak var oldDocumentsTitle: NSTextField!
|
|
|
+
|
|
|
+ @IBOutlet weak var compareOldPreviewView: KMCompareFilesView!
|
|
|
+ @IBOutlet weak var oldFileQKSelectedBox: NSComboBox!
|
|
|
+ @IBOutlet weak var oldFileSelectBtn: NSButton!
|
|
|
+ @IBOutlet weak var oldPDFView: PDFView!
|
|
|
+ @IBOutlet weak var currentOldPageLabel: NSTextField!
|
|
|
+ @IBOutlet weak var totalPaOldgeLabel: NSTextField!
|
|
|
+
|
|
|
+ @IBOutlet weak var compareNewPreviewView: KMCompareFilesView!
|
|
|
+ @IBOutlet weak var documentsNewTitle: NSTextField!
|
|
|
+ @IBOutlet weak var fileQKNewSelectedBox: NSComboBox!
|
|
|
+ @IBOutlet weak var fileSelectNewBtn: NSButton!
|
|
|
+ @IBOutlet weak var pdfNewView: PDFView!
|
|
|
+ @IBOutlet weak var addFileContentView: KMCompareFilesView!
|
|
|
+ @IBOutlet weak var addFileImageView: NSImageView!
|
|
|
+ @IBOutlet weak var addFileAddImageFramView: KMCompareFilesView!
|
|
|
+ @IBOutlet weak var currentNewPageLabel: NSTextField!
|
|
|
+ @IBOutlet weak var totalPaNewgeLabel: NSTextField!
|
|
|
+
|
|
|
+ @IBOutlet weak var addFileTitle: NSTextField!
|
|
|
+ @IBOutlet weak var addFileMag: NSTextField!
|
|
|
+
|
|
|
+ @IBOutlet weak var pageRangeField: NSTextField!
|
|
|
+ @IBOutlet weak var oldFileRangeField: NSTextField!
|
|
|
+ @IBOutlet weak var pageRangeOldComboBox: NSComboBox!
|
|
|
+ @IBOutlet weak var fileNewRangeField: NSTextField!
|
|
|
+ @IBOutlet weak var pageRangeNewComboBox: NSComboBox!
|
|
|
+
|
|
|
+ @IBOutlet weak var compareTextTypeBtn: NSButton!
|
|
|
+ @IBOutlet weak var compareImageTypeBtn: NSButton!
|
|
|
+
|
|
|
+ @IBOutlet weak var compareSettingsBtn: NSButton!
|
|
|
+ @IBOutlet weak var settingBtnTopLayout: NSLayoutConstraint!
|
|
|
+
|
|
|
+ var pdfCompareContent: CPDFCompareContent?
|
|
|
+
|
|
|
+
|
|
|
+ var pdfOldDocument: PDFDocument?
|
|
|
+ var oldFileQKSelectedPaths: [String] = []
|
|
|
+
|
|
|
+ var pdfNewDocument: PDFDocument?
|
|
|
+ var fileQKNewSelectedPaths: [String] = []
|
|
|
+
|
|
|
+ var fileType: KMCompareFilesType = .content
|
|
|
var cancelAction: KMCompareViewCancelAction?
|
|
|
|
|
|
- override func draw(_ dirtyRect: NSRect) {
|
|
|
- super.draw(dirtyRect)
|
|
|
+ convenience init(pdfDocument: PDFDocument) {
|
|
|
+ self.init()
|
|
|
+ self.pdfOldDocument = pdfDocument
|
|
|
+ let document: CPDFDocument = CPDFDocument.init(url: pdfDocument.documentURL)
|
|
|
+
|
|
|
+ let file: KMFileAttribute = KMFileAttribute()
|
|
|
+ file.pdfDocument = document
|
|
|
+
|
|
|
+ let config: KMCompareFilesConfig = KMCompareFilesConfig.init()
|
|
|
+ config.fileOldAttribute = file
|
|
|
+ }
|
|
|
+
|
|
|
+ convenience init(filePath: String, password: String) {
|
|
|
+ self.init()
|
|
|
+ self.pdfOldDocument = PDFDocument.init(url: NSURL(fileURLWithPath: filePath) as URL)
|
|
|
+ let pdfDocument = CPDFDocument.init(url: NSURL(fileURLWithPath: filePath) as URL)
|
|
|
+ if pdfDocument!.isLocked {
|
|
|
+ pdfDocument!.unlock(withPassword: password)
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.pdfOldDocument!.isLocked {
|
|
|
+ self.pdfOldDocument!.unlock(withPassword: password)
|
|
|
+ }
|
|
|
+
|
|
|
+ let file: KMFileAttribute = KMFileAttribute()
|
|
|
+ file.pdfDocument = pdfDocument
|
|
|
+
|
|
|
+ let config = KMCompareFilesConfig.defaultConfig
|
|
|
+ config.fileOldAttribute = file
|
|
|
+ config.fileOldAttribute.password = password
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setup() {
|
|
|
+ fileQKNewSelectedBox.delegate = self
|
|
|
+ oldFileQKSelectedBox.delegate = self
|
|
|
+
|
|
|
+ compareTypeSegment.action = #selector(segmentedControlClicked)
|
|
|
+ compareTypeSegment.target = self
|
|
|
+
|
|
|
+ compareTypeSegment.wantsLayer = true
|
|
|
+ addFileContentView.wantsLayer = true
|
|
|
+
|
|
|
+ addFileImageView.ignoresMultiClick = true
|
|
|
+
|
|
|
+ fileQKNewSelectedBox.isEnabled = false
|
|
|
+ oldFileQKSelectedBox.isEnabled = false
|
|
|
+ fileQKNewSelectedBox.cell!.isEnabled = false
|
|
|
+ oldFileQKSelectedBox.cell!.isEnabled = false
|
|
|
+
|
|
|
+ currentOldPageLabel.delegate = self
|
|
|
+ currentNewPageLabel.delegate = self
|
|
|
+
|
|
|
+ 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
|
|
|
+ compareTypeSegment.layer?.masksToBounds = true
|
|
|
+ compareTypeSegment.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
+ addFileContentView.wantsLayer = true
|
|
|
+
|
|
|
+ addFileAddImageFramView.wantsLayer = true
|
|
|
+ addFileAddImageFramView.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
+
|
|
|
+ self.compareOldPreviewView.dragSuccessBlock = { [unowned self] filePath in
|
|
|
+ self.updateDocument(filePath: filePath) { fileAttitude in
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.compareNewPreviewView.dragSuccessBlock = { [unowned self] filePath in
|
|
|
+ self.updateDocument(filePath: filePath, isNew: true) { fileAttitude in
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.addFileContentView.dragSuccessBlock = { [unowned self] filePath in
|
|
|
+ self.updateDocument(filePath: filePath, isNew: true) { fileAttitude in
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.addFileAddImageFramView.dragSuccessBlock = { [unowned self] filePath in
|
|
|
+ self.updateDocument(filePath: filePath, isNew: true) { fileAttitude in
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.addFileContentView.mouseUpBack = { [unowned self] view in
|
|
|
+ self.chooseFileAction()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override func updateLanguage() {
|
|
|
+ compareTypeSegment.setLabel(NSLocalizedString("Side-by-Side View", comment: ""), forSegment: 0)
|
|
|
+ compareTypeSegment.setLabel(NSLocalizedString("Compare by File Overlay", comment: ""), forSegment: 1)
|
|
|
+
|
|
|
+ compareTypeSegment.setToolTip(NSLocalizedString("Side-by-Side View", comment: ""), forSegment: 0)
|
|
|
+ compareTypeSegment.setToolTip(NSLocalizedString("Compare by File Overlay", comment: ""), forSegment: 1)
|
|
|
+
|
|
|
+ oldDocumentsTitle.stringValue = NSLocalizedString("Old File", comment: "")
|
|
|
+ documentsNewTitle.stringValue = NSLocalizedString("New File", comment: "")
|
|
|
+
|
|
|
+ oldFileSelectBtn.title = NSLocalizedString("Choose...", comment: "")
|
|
|
+ fileSelectNewBtn.title = NSLocalizedString("Choose...", comment: "")
|
|
|
+
|
|
|
+ oldFileSelectBtn.toolTip = NSLocalizedString("Choose...", comment: "")
|
|
|
+ fileSelectNewBtn.toolTip = NSLocalizedString("Choose...", comment: "")
|
|
|
+
|
|
|
+ addFileTitle.stringValue = NSLocalizedString("Select File", comment: "")
|
|
|
+ addFileMag.stringValue = NSLocalizedString("Click to add", comment: "")
|
|
|
+
|
|
|
+ oldFileRangeField.stringValue = NSLocalizedString("Old File:", comment: "")
|
|
|
+ fileNewRangeField.stringValue = NSLocalizedString("New File:", comment: "")
|
|
|
+
|
|
|
+ pageRangeField.stringValue = NSLocalizedString("Page Range", comment: "")
|
|
|
+
|
|
|
+ pageRangeOldComboBox.removeAllItems()
|
|
|
+ pageRangeOldComboBox.addItems(withObjectValues: [NSLocalizedString("All Pages", comment: ""),
|
|
|
+ NSLocalizedString("Odd Pages Only", comment: ""),
|
|
|
+ NSLocalizedString("Even Pages Only",comment: ""),
|
|
|
+ NSLocalizedString("e.g. 1,3-5,10",comment: "")])
|
|
|
+ pageRangeOldComboBox.placeholderString = NSLocalizedString("e.g. 1,3-5,10", comment: "")
|
|
|
+
|
|
|
+ pageRangeNewComboBox.addItems(withObjectValues: [NSLocalizedString("All Pages", comment: ""),
|
|
|
+ NSLocalizedString("Odd Pages Only", comment: ""),
|
|
|
+ NSLocalizedString("Even Pages Only",comment: ""),
|
|
|
+ NSLocalizedString("e.g. 1,3-5,10",comment: "")])
|
|
|
+ self.pageRangeNewComboBox.placeholderString = NSLocalizedString("e.g. 1,3-5,10", comment: "")
|
|
|
+
|
|
|
+ self.compareTextTypeBtn.title = NSLocalizedString("Compare text", comment: "")
|
|
|
+ self.compareImageTypeBtn.title = NSLocalizedString("Compare image", comment: "")
|
|
|
+
|
|
|
+ let settingsString = " " + NSLocalizedString("Settings", comment: "")
|
|
|
+ compareSettingsBtn.title = settingsString
|
|
|
+ compareSettingsBtn.state = .off
|
|
|
+ compareSettingsBtn.setTitleColor(KMAppearance.Layout.h1Color())
|
|
|
+
|
|
|
+ cancelButton.title = NSLocalizedString("Cancel", comment: "")
|
|
|
+ doneButton.title = NSLocalizedString("Compare", comment: "")
|
|
|
+ }
|
|
|
+
|
|
|
+ override func updateUI() {
|
|
|
+ if KMAppearance.isDarkMode() {
|
|
|
+ self.compareTypeSegment.layer?.backgroundColor = NSColor(red: 50.0/255.0, green: 53.0/255.0, blue: 54.0/255.0, alpha: 1).cgColor
|
|
|
+ self.addFileContentView.layer?.backgroundColor = NSColor.black.cgColor
|
|
|
+ } else {
|
|
|
+ self.compareTypeSegment.layer?.backgroundColor = NSColor(red: 247.0/255.0, green: 247.0/255.0, blue: 247.0/255.0, alpha: 1).cgColor
|
|
|
+ self.addFileContentView.layer?.backgroundColor = NSColor.white.cgColor
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override func reloadData() {
|
|
|
+ if(pageRangeOldComboBox.indexOfSelectedItem == 3) {
|
|
|
+ self.window?.makeFirstResponder(pageRangeOldComboBox)
|
|
|
+ pageRangeOldComboBox.stringValue = ""
|
|
|
+ pageRangeOldComboBox.isSelectable = true
|
|
|
+ }
|
|
|
+
|
|
|
+ self.updatePageRangeData(view: pageRangeNewComboBox, file: KMCompareFilesConfig.defaultConfig.fileNewAttribute, isNew: true)
|
|
|
+ self.updatePageRangeData(view: pageRangeOldComboBox, file: KMCompareFilesConfig.defaultConfig.fileOldAttribute)
|
|
|
+
|
|
|
+ if (KMCompareFilesConfig.defaultConfig.isCompareText)() {
|
|
|
+ self.compareTextTypeBtn.state = .on;
|
|
|
+ } else {
|
|
|
+ self.compareTextTypeBtn.state = .off;
|
|
|
+ }
|
|
|
+ if (KMCompareFilesConfig.defaultConfig.isCompareImage)() {
|
|
|
+ self.compareImageTypeBtn.state = .on;
|
|
|
+ } else {
|
|
|
+ self.compareImageTypeBtn.state = .off;
|
|
|
+ }
|
|
|
+
|
|
|
+ self.updateSelectBoxData()
|
|
|
+
|
|
|
+ self.updatePageState()
|
|
|
+ self.updatePageState(isNew: true)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension KMCompareView {
|
|
|
+ func addFileQKSelectPath(filePath: String, isNewFile: Bool = false) {
|
|
|
+ let pdfdocument = CPDFDocument(url: NSURL(fileURLWithPath: filePath) as URL)
|
|
|
+ guard let pdfdocument = pdfdocument else { return }
|
|
|
+
|
|
|
+ var key = ""
|
|
|
+ if isNewFile {
|
|
|
+ key = CPDFNewFileQKSelectedPathsKey
|
|
|
+ } else {
|
|
|
+ key = CPDFOldFileQKSelectedPathsKey
|
|
|
+ }
|
|
|
+
|
|
|
+ var filePaths: [String] = UserDefaults.standard.object(forKey: key) as? [String] ?? []
|
|
|
+ if filePaths.count > CPDFMaxQKSelectedPathsCount {
|
|
|
+ filePaths.removeLast()
|
|
|
+
|
|
|
+ }
|
|
|
+ filePaths.insert(filePath, at: 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateSelectBoxData() {
|
|
|
+ self.oldFileQKSelectedPaths = self.updateSelectBoxItemData()
|
|
|
+ self.oldFileQKSelectedBox.removeAllItems()
|
|
|
+ self.oldFileQKSelectedBox.addItems(withObjectValues: self.oldFileQKSelectedPaths)
|
|
|
+
|
|
|
+ self.fileQKNewSelectedPaths = self.updateSelectBoxItemData(isNew: true)
|
|
|
+ self.fileQKNewSelectedBox.removeAllItems()
|
|
|
+ self.fileQKNewSelectedBox.addItems(withObjectValues: self.fileQKNewSelectedPaths)
|
|
|
+
|
|
|
+ if self.fileQKNewSelectedPaths.count > 0 {
|
|
|
+ self.fileQKNewSelectedBox.isEnabled = true
|
|
|
+ } else {
|
|
|
+ self.fileQKNewSelectedBox.isEnabled = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateSelectBoxItemData(isNew: Bool = false) -> [String] {
|
|
|
+ let defaults = UserDefaults.standard
|
|
|
+ var fileSelectedCachePaths: [String] = []
|
|
|
+ if isNew {
|
|
|
+ fileSelectedCachePaths = defaults.value(forKey: CPDFOldFileQKSelectedPathsKey) as? [String] ?? []
|
|
|
+ } else {
|
|
|
+ fileSelectedCachePaths = defaults.value(forKey: CPDFNewFileQKSelectedPathsKey) as? [String] ?? []
|
|
|
+ }
|
|
|
+
|
|
|
+ var fileSelectedPaths: [String] = []
|
|
|
|
|
|
- // Drawing code here.
|
|
|
+ let fileManager = FileManager.default
|
|
|
+ for path in fileSelectedCachePaths {
|
|
|
+ if fileManager.fileExists(atPath: path) {
|
|
|
+// #if VERSION_DMG
|
|
|
+ fileSelectedPaths.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
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fileSelectedPaths
|
|
|
+ }
|
|
|
+
|
|
|
+ func updatePageState(isNew: Bool = false) {
|
|
|
+ var pageDocument = PDFDocument()
|
|
|
+ var pdfView = PDFView()
|
|
|
+ var currentPageLabel = NSTextField()
|
|
|
+ var totalPageLabel = NSTextField()
|
|
|
+
|
|
|
+ guard let pdfNewDocument = pdfNewDocument else { return }
|
|
|
+ guard let pdfOldDocument = pdfOldDocument else { return }
|
|
|
+
|
|
|
+ if isNew {
|
|
|
+ pageDocument = pdfNewDocument
|
|
|
+ pdfView = pdfNewView
|
|
|
+ currentPageLabel = currentNewPageLabel
|
|
|
+ totalPageLabel = totalPaNewgeLabel
|
|
|
+ } else {
|
|
|
+ pageDocument = pdfOldDocument
|
|
|
+ pdfView = oldPDFView
|
|
|
+ currentPageLabel = currentOldPageLabel
|
|
|
+ totalPageLabel = totalPaOldgeLabel
|
|
|
+ }
|
|
|
+ // 隐藏PDFView滑动条
|
|
|
+ pdfView.documentView?.enclosingScrollView?.hasVerticalScroller = false
|
|
|
+ pdfView.documentView?.enclosingScrollView?.hasHorizontalScroller = false
|
|
|
+ let pageCount = pageDocument.pageCount
|
|
|
+ var currentPageIndex = 0
|
|
|
+ if(pdfView.currentPage != nil) {
|
|
|
+ currentPageIndex = pageDocument.index(for: pdfView.currentPage!)
|
|
|
+ }
|
|
|
+
|
|
|
+ if(pageCount > 0) {
|
|
|
+ currentPageLabel.stringValue = "\(currentPageIndex + 1)"
|
|
|
+ } else {
|
|
|
+ currentPageLabel.stringValue = "\(currentPageIndex)"
|
|
|
+ }
|
|
|
+ totalPageLabel.stringValue = "/ \(pageCount)"
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateDocument(filePath: String, isNew: Bool = false, completion: @escaping (_ fileAttitude: KMFileAttribute?) -> Void) {
|
|
|
+ var pdfDocument = CPDFDocument()
|
|
|
+ if isNew {
|
|
|
+ pdfDocument = KMCompareFilesConfig.defaultConfig.fileOldAttribute.pdfDocument ?? CPDFDocument()
|
|
|
+ } else {
|
|
|
+ pdfDocument = KMCompareFilesConfig.defaultConfig.fileNewAttribute.pdfDocument ?? CPDFDocument()
|
|
|
+ }
|
|
|
+
|
|
|
+ guard let pdfDocument = pdfDocument else {
|
|
|
+ completion(nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (pdfDocument.documentURL.path == filePath) {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = NSAlert.Style.critical
|
|
|
+ alert.messageText = NSLocalizedString("There is no difference between the two documents.", comment: "")
|
|
|
+ alert.runModal()
|
|
|
+ completion(nil)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ KMBaseWindowController.checkPassword(url: NSURL(fileURLWithPath: filePath) as URL) { success, resultPassword in
|
|
|
+ if success {
|
|
|
+ let file = KMFileAttribute()
|
|
|
+ file.pdfDocument = pdfDocument
|
|
|
+ file.password = resultPassword
|
|
|
+ completion(file)
|
|
|
+ } else {
|
|
|
+ completion(nil)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func updatePageRangeData(view: NSComboBox, file: KMFileAttribute, isNew: Bool = false) {
|
|
|
+ switch (file.pagesType) {
|
|
|
+ case .all:
|
|
|
+ view.selectItem(at: 0)
|
|
|
+ view.isEditable = false
|
|
|
+ view.delegate = nil
|
|
|
+ break;
|
|
|
+ case .odd:
|
|
|
+ view.selectItem(at: 1)
|
|
|
+ view.isEditable = false
|
|
|
+ view.delegate = nil
|
|
|
+ break;
|
|
|
+ case .even:
|
|
|
+ view.selectItem(at: 2)
|
|
|
+ view.isEditable = false
|
|
|
+ view.delegate = nil
|
|
|
+ break;
|
|
|
+ case .custom:
|
|
|
+ view.delegate = self
|
|
|
+ view.stringValue = file.pagesString
|
|
|
+ view.isEditable = true
|
|
|
+ break;
|
|
|
+ default: break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateFileCompareType(fileType: KMCompareFilesType) {
|
|
|
+ if fileType == .content {
|
|
|
+ compareTypeSegment.selectedSegment = 0
|
|
|
+ compareTextTypeBtn.isHidden = false
|
|
|
+ compareImageTypeBtn.isHidden = false
|
|
|
+ settingBtnTopLayout.constant = 81
|
|
|
+ } else {
|
|
|
+ compareTypeSegment.selectedSegment = 1
|
|
|
+ compareTextTypeBtn.isHidden = true
|
|
|
+ compareImageTypeBtn.isHidden = true
|
|
|
+ settingBtnTopLayout.constant = 20
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -34,4 +454,47 @@ extension KMCompareView {
|
|
|
@IBAction func convertButtonAction(_ sender: Any) {
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @objc func segmentedControlClicked(sender: NSSegmentedControl) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 {
|
|
|
+ self.updateDocument(filePath: filePath, isNew: isNew) { file in
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+extension KMCompareView: NSComboBoxDelegate {
|
|
|
+
|
|
|
}
|