|
@@ -15,6 +15,8 @@ class KMCompareWindowController: KMBaseWindowController {
|
|
|
@IBOutlet weak var compareView: KMCompareView!
|
|
|
|
|
|
var pdfCompareContent: CPDFCompareContent?
|
|
|
+ var maskView: KMBookletMaskView?
|
|
|
+ var progressController: SKProgressController?
|
|
|
|
|
|
var filePath: String = "" {
|
|
|
didSet {
|
|
@@ -60,12 +62,14 @@ class KMCompareWindowController: KMBaseWindowController {
|
|
|
|
|
|
func compareAction(config: KMCompareFilesConfig) {
|
|
|
compareView.doneButton.isEnabled = false
|
|
|
+ self.showWaitting()
|
|
|
|
|
|
guard let pdfOldDocument = config.fileOldAttribute.pdfDocument, let pdfNewDocument = config.fileNewAttribute.pdfDocument else {
|
|
|
let alert = NSAlert()
|
|
|
alert.alertStyle = .critical
|
|
|
alert.messageText = NSLocalizedString("Please select two files to compare", comment: "")
|
|
|
alert.runModal()
|
|
|
+ self.hideWaitting()
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -78,6 +82,7 @@ class KMCompareWindowController: KMBaseWindowController {
|
|
|
alert.alertStyle = .critical
|
|
|
alert.messageText = NSLocalizedString("The file has been deleted, please reselect a file.", comment: "")
|
|
|
alert.runModal()
|
|
|
+ self.hideWaitting()
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -92,6 +97,8 @@ class KMCompareWindowController: KMBaseWindowController {
|
|
|
config.fileNewAttribute.pagesType = .all
|
|
|
|
|
|
compareView.reloadData()
|
|
|
+
|
|
|
+ self.hideWaitting()
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -105,6 +112,8 @@ class KMCompareWindowController: KMBaseWindowController {
|
|
|
config.fileOldAttribute.pagesType = .all
|
|
|
|
|
|
compareView.reloadData()
|
|
|
+
|
|
|
+ self.hideWaitting()
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -136,17 +145,25 @@ class KMCompareWindowController: KMBaseWindowController {
|
|
|
pdfCompareOverlay?.setBlendMod(config.blendMod())
|
|
|
|
|
|
if (pdfCompareOverlay?.compare() == true) {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.progressController?.doubleValue = 30.0
|
|
|
+ }
|
|
|
+
|
|
|
guard let document = pdfCompareOverlay?.comparisonDocument() else {
|
|
|
DispatchQueue.main.async {
|
|
|
let alert = NSAlert()
|
|
|
alert.alertStyle = .critical
|
|
|
alert.messageText = NSLocalizedString("Failure", comment: "")
|
|
|
alert.runModal()
|
|
|
+
|
|
|
+ self.hideWaitting()
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+
|
|
|
DispatchQueue.main.async {
|
|
|
+ self.hideWaitting()
|
|
|
self.coveringComplete?(self, document)
|
|
|
}
|
|
|
debugPrint("合并成功")
|
|
@@ -184,6 +201,9 @@ class KMCompareWindowController: KMBaseWindowController {
|
|
|
// if self._compareCancel {
|
|
|
// return
|
|
|
// }
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.progressController?.doubleValue = 30.0
|
|
|
+ }
|
|
|
|
|
|
for i in 0..<maxIndex {
|
|
|
let oldPageIndex: Int
|
|
@@ -212,6 +232,7 @@ class KMCompareWindowController: KMBaseWindowController {
|
|
|
}
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
+ self.hideWaitting()
|
|
|
self.contentComplete?(self, pdfCompareContent!, results, oldDoc!, doc!)
|
|
|
if results.count > 0 {
|
|
|
// Handle success case
|
|
@@ -227,3 +248,38 @@ class KMCompareWindowController: KMBaseWindowController {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+extension KMCompareWindowController {
|
|
|
+ func showWaitting() {
|
|
|
+ if self.maskView == nil {
|
|
|
+ self.maskView = KMBookletMaskView(frame: CGRect(x: 0, y: 0, width: self.window?.frame.size.width ?? 0, height: self.window?.frame.size.height ?? 0))
|
|
|
+ }
|
|
|
+ self.window?.contentView?.addSubview(self.maskView!)
|
|
|
+
|
|
|
+ let progress = SKProgressController()
|
|
|
+ progress.window?.backgroundColor = NSColor.km_init(hex: "#36383B")
|
|
|
+ progress.window?.contentView?.wantsLayer = true
|
|
|
+ progress.window?.contentView?.layer?.backgroundColor = NSColor.km_init(hex: "#36383B").cgColor
|
|
|
+ progress.progressField.textColor = NSColor.white
|
|
|
+ progress.message = NSLocalizedString("Translating...", comment: "")
|
|
|
+
|
|
|
+ progress.closeBlock = { [unowned self] in
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ self.progressController = progress
|
|
|
+ self.window?.beginSheet(progress.window!)
|
|
|
+ }
|
|
|
+ func hideWaitting() {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.progressController?.doubleValue = 99.0
|
|
|
+ }
|
|
|
+
|
|
|
+ self.maskView?.removeFromSuperview()
|
|
|
+
|
|
|
+ if (self.progressController != nil) {
|
|
|
+ self.window?.endSheet((self.progressController?.window)!)
|
|
|
+ self.progressController = nil
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|