|
@@ -17,7 +17,8 @@ class KMConvertOCRSettingItemView: KMConvertBaseView {
|
|
|
}
|
|
|
|
|
|
private var _languageVC: KMDesignSelect?
|
|
|
-
|
|
|
+ var progressController: SKProgressController?
|
|
|
+
|
|
|
private var _languageIndex: Int = 0
|
|
|
var languageIndex: Int {
|
|
|
get {
|
|
@@ -76,39 +77,48 @@ class KMConvertOCRSettingItemView: KMConvertBaseView {
|
|
|
}
|
|
|
|
|
|
@objc func checkBoxAction(sender: NSButton) {
|
|
|
-// let isExist = KMResourceDownload().documentAIBundleIsExist()
|
|
|
-// if isExist || self._checkVC?.state == .Checked {
|
|
|
-// if let state = self._checkVC?.state {
|
|
|
-// self._checkVC?.state = state == .Checked ? .Norm : .Checked
|
|
|
-// }
|
|
|
-//
|
|
|
-// self._checkAction()
|
|
|
-// } else {
|
|
|
-// let alert = NSAlert()
|
|
|
-// alert.messageText = NSLocalizedString("Do you want to download resources?", comment: "")
|
|
|
-// alert.informativeText = NSLocalizedString("Additional resource pack download is required to use OCR. Do you want to continue?", comment: "")
|
|
|
-// alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
-// alert.addButton(withTitle: NSLocalizedString("No", comment: ""))
|
|
|
-// alert.beginSheetModal(for: self.window!) { [unowned self] result in
|
|
|
-// if (result == .alertFirstButtonReturn) { /// 取消
|
|
|
-// KMResourceDownload().downloadFramework()
|
|
|
-//
|
|
|
-// if let state = self._checkVC?.state {
|
|
|
-// self._checkVC?.state = state == .Checked ? .Norm : .Checked
|
|
|
-// }
|
|
|
-//
|
|
|
-// self._checkAction()
|
|
|
-// } else if result == .alertSecondButtonReturn {
|
|
|
-// return
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
- if let state = self._checkVC?.state {
|
|
|
- self._checkVC?.state = state == .Checked ? .Norm : .Checked
|
|
|
+ let isExist = KMResourceDownload().documentAIBundleIsExist()
|
|
|
+ if isExist || self._checkVC?.state == .Checked {
|
|
|
+ if let state = self._checkVC?.state {
|
|
|
+ self._checkVC?.state = state == .Checked ? .Norm : .Checked
|
|
|
+ }
|
|
|
+
|
|
|
+ self._checkAction()
|
|
|
+ } else {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.messageText = NSLocalizedString("Do you want to download resources?", comment: "")
|
|
|
+ alert.informativeText = NSLocalizedString("Additional resource pack download is required to use OCR. Do you want to continue?", comment: "")
|
|
|
+ alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
|
|
|
+ alert.addButton(withTitle: NSLocalizedString("No", comment: ""))
|
|
|
+ alert.beginSheetModal(for: self.window!) { [unowned self] result in
|
|
|
+ if (result == .alertFirstButtonReturn) { /// 取消
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.showProgressWindow()
|
|
|
+ self.progressController?.maxValue = Double(100)
|
|
|
+ }
|
|
|
+ KMResourceDownload().downloadFrameworkProgress { progress in
|
|
|
+ self.progressController?.doubleValue = Double(progress*100)
|
|
|
+ } result: { result in
|
|
|
+ if result {
|
|
|
+ if let state = self._checkVC?.state {
|
|
|
+ self._checkVC?.state = state == .Checked ? .Norm : .Checked
|
|
|
+ }
|
|
|
+
|
|
|
+ self._checkAction()
|
|
|
+
|
|
|
+ if let state = self._checkVC?.state {
|
|
|
+ self._checkVC?.state = state == .Checked ? .Norm : .Checked
|
|
|
+ }
|
|
|
+
|
|
|
+ self._checkAction()
|
|
|
+ }
|
|
|
+ self.hiddenProgressWindow()
|
|
|
+ }
|
|
|
+ } else if result == .alertSecondButtonReturn {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- self._checkAction()
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public func checkAction() {
|
|
@@ -122,6 +132,32 @@ class KMConvertOCRSettingItemView: KMConvertBaseView {
|
|
|
|
|
|
self._languageVC?.enabled = state == .Checked
|
|
|
}
|
|
|
+
|
|
|
+ func showProgressWindow() {
|
|
|
+ let progress = SKProgressController()
|
|
|
+ progress.message = NSLocalizedString("Download...", comment: "")
|
|
|
+ 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.closeBlock = { [unowned self] in
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ self.progressController = progress
|
|
|
+ self.window?.beginSheet(progress.window!)
|
|
|
+ }
|
|
|
+
|
|
|
+ func hiddenProgressWindow() {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.progressController?.doubleValue = 100.0
|
|
|
+ if (self.progressController != nil) {
|
|
|
+ self.window?.endSheet((self.progressController?.window)!)
|
|
|
+ self.progressController = nil
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension KMConvertOCRSettingItemView: KMSelectPopButtonDelegate {
|