|
@@ -14,23 +14,7 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
@IBOutlet weak var headerBottomLine: ComponentDivider!
|
|
|
|
|
|
@IBOutlet var outputTypeLabel: NSTextField!
|
|
|
- @IBOutlet var createNewPDFBtn: NSButton!
|
|
|
- @IBOutlet var btnMerge: NSButton!
|
|
|
- @IBOutlet var appendPDFBtn: NSButton!
|
|
|
- @IBOutlet var appendTextField: NSTextField!
|
|
|
- @IBOutlet var appendOtherPDFBtn: NSButton!
|
|
|
- @IBOutlet var appendBackView: NSView!
|
|
|
-
|
|
|
@IBOutlet var ocrLabel: NSTextField!
|
|
|
- @IBOutlet var ocrSelectBtn: NSButton!
|
|
|
- @IBOutlet var languaeBox: NSBox!
|
|
|
- @IBOutlet var languageButton: NSButton!
|
|
|
- @IBOutlet var saveAsButton: NSButton!
|
|
|
- @IBOutlet var planButton: NSButton!
|
|
|
- @IBOutlet var selectLanguageLabel: NSTextField!
|
|
|
- @IBOutlet var planBox: NSBox!
|
|
|
-
|
|
|
- @IBOutlet var actionButton: NSButton!
|
|
|
|
|
|
@IBOutlet weak var newPDFBox: NSBox!
|
|
|
@IBOutlet weak var mergeAllBox: NSBox!
|
|
@@ -80,6 +64,16 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
return view
|
|
|
}()
|
|
|
|
|
|
+ private lazy var appendBackInput_: ComponentInput = {
|
|
|
+ let view = ComponentInput()
|
|
|
+ return view
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var appendBackButtonInput_: ComponentInputAddon = {
|
|
|
+ let view = ComponentInputAddon()
|
|
|
+ return view
|
|
|
+ }()
|
|
|
+
|
|
|
private lazy var ocrCheckBox_: ComponentCheckBox = {
|
|
|
let view = ComponentCheckBox()
|
|
|
view.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: NSLocalizedString("Recognize text if needed", comment: ""), checkboxType: .normal)
|
|
@@ -90,19 +84,21 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
let view = ComponentSelect()
|
|
|
|
|
|
view.properties = ComponentSelectProperties(size: .s, state: .normal, isDisabled: false, isError: false, leftIcon: false, placeholder: nil, errorText: nil, creatable: false, text: KMLocalizedString("", comment: ""))
|
|
|
-// view.delegate = self
|
|
|
+ view.delegate = self
|
|
|
return view
|
|
|
}()
|
|
|
|
|
|
private var ocrPlanRadio_: ComponentRadio = {
|
|
|
let view = ComponentRadio()
|
|
|
view.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: true, text: KMLocalizedString("OCR Plan 1-Online", comment: ""), checkboxType: .normal)
|
|
|
+ view.toolTip = KMLocalizedString("The OCR service works via an internet connection. We would suggest you to perform OCR using a VPN connection while the service is limited.")
|
|
|
return view
|
|
|
}()
|
|
|
|
|
|
private var ocrPlanRadio2_: ComponentRadio = {
|
|
|
let view = ComponentRadio()
|
|
|
view.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: true, text: KMLocalizedString("OCR Plan 2-Online", comment: ""), checkboxType: .normal)
|
|
|
+ view.toolTip = KMLocalizedString("The OCR service works via an internet connection. We would suggest you to perform OCR using a VPN connection while the service is limited.")
|
|
|
return view
|
|
|
}()
|
|
|
|
|
@@ -145,22 +141,8 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
}
|
|
|
|
|
|
private func _updateActionButtonEnable(_ enabled: Bool) {
|
|
|
- if enabled {
|
|
|
- self.actionButton.tag = 1
|
|
|
-
|
|
|
- applyButton.properties.isDisabled = false
|
|
|
- applyButton.reloadData()
|
|
|
- } else {
|
|
|
- self.actionButton.tag = 0
|
|
|
-
|
|
|
- applyButton.properties.isDisabled = true
|
|
|
- applyButton.reloadData()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- deinit {
|
|
|
- NotificationCenter.default.removeObserver(self)
|
|
|
- DistributedNotificationCenter.default().removeObserver(self)
|
|
|
+ applyButton.properties.isDisabled = !enabled
|
|
|
+ applyButton.reloadData()
|
|
|
}
|
|
|
|
|
|
override func viewDidLoad() {
|
|
@@ -171,6 +153,44 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
createNewPDFRadio_.properties.checkboxType = .selected
|
|
|
createNewPDFRadio_.reloadData()
|
|
|
|
|
|
+ let color = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorBorder-dis")
|
|
|
+ appendBackBox.borderColor = color
|
|
|
+ let inputWithAddonProperty = ComponentInputProperty(size: .s,
|
|
|
+ state: .normal,
|
|
|
+ isError: false,
|
|
|
+ showPrefix: false,
|
|
|
+ showSuffix: false,
|
|
|
+ showClear: false,
|
|
|
+ isDisabled: true,
|
|
|
+ placeholder: KMLocalizedString("Select File..."),
|
|
|
+ text: "",
|
|
|
+ creatable: false)
|
|
|
+ appendBackInput_.properties = inputWithAddonProperty
|
|
|
+ appendBackInput_.properties.propertyInfo.cornerRadius_topRight = 0
|
|
|
+ appendBackInput_.properties.propertyInfo.cornerRadius_bottomRight = 0
|
|
|
+ appendBackInput_.properties.isDisabled = true
|
|
|
+ appendBackInput_.reloadData()
|
|
|
+
|
|
|
+ appendBackButtonInput_.properties = ComponentInputAddonProperty(size: .s,
|
|
|
+ state: .normal,
|
|
|
+ addOnBefore: false,
|
|
|
+ onlyRead: false,
|
|
|
+ addonType: .imageWithColor,
|
|
|
+ iconImage: NSImage(named: "KMFolderIcon"))
|
|
|
+ appendBackButtonInput_.properties.isDisabled = true
|
|
|
+ appendBackButtonInput_.reloadData()
|
|
|
+ appendBackButtonInput_.setTarget(self, action: #selector(buttonItemClicked_AppendOtherPDF))
|
|
|
+ appendBackBox.contentView?.addSubview(appendBackInput_)
|
|
|
+ appendBackBox.contentView?.addSubview(appendBackButtonInput_)
|
|
|
+ let boxH: CGFloat = 30
|
|
|
+ appendBackInput_.frame = NSMakeRect(0, 0, 204, boxH)
|
|
|
+ appendBackButtonInput_.frame = NSMakeRect(NSMaxX(appendBackInput_.frame), 0, boxH+2, boxH)
|
|
|
+ let hView = NSView()
|
|
|
+ appendBackBox.contentView?.addSubview(hView)
|
|
|
+ hView.frame = NSMakeRect(NSMaxX(appendBackInput_.frame), 0, 1, 32)
|
|
|
+ hView.wantsLayer = true
|
|
|
+ hView.layer?.backgroundColor = color.cgColor
|
|
|
+
|
|
|
ocrLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
|
|
|
ocrSelectBox.borderWidth = 0
|
|
|
ocrSelectBox.contentView = ocrCheckBox_
|
|
@@ -179,6 +199,7 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
languageView_.reloadData()
|
|
|
ocrPlanRadio_.setTarget(self, action: #selector(ocrPlanAction))
|
|
|
ocrPlanRadio_.properties.isDisabled = true
|
|
|
+ ocrPlanRadio_.properties.checkboxType = .selected
|
|
|
ocrPlanRadio_.reloadData()
|
|
|
ocrPlanRadio2_.setTarget(self, action: #selector(ocrPlanAction))
|
|
|
ocrPlanRadio2_.properties.isDisabled = true
|
|
@@ -188,6 +209,7 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
|
|
|
bottomBox.borderWidth = 0
|
|
|
applyButton.properties = ComponentButtonProperty(type: .primary, size: .m, onlyIcon: false, buttonText: KMLocalizedString("Apply"))
|
|
|
+ applyButton.setTarget(self, action: #selector(buttonClicked_ImageToPDF))
|
|
|
|
|
|
self.localizedLanguage()
|
|
|
self.configuUI()
|
|
@@ -197,17 +219,14 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
} else {
|
|
|
self._updateActionButtonEnable(false)
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ override func addNotifations() {
|
|
|
+ super.addNotifations()
|
|
|
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(OCRSelectedLanguagesChangeNotification(notification:)), name: NSNotification.Name("KMOCRSelectedLanguagesChangeNotification"), object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(OCRSelectedPlanChangeNotification(notification:)), name: NSNotification.Name("KMOCRSelectedPlanChangeNotification"), object: nil)
|
|
|
-
|
|
|
-// NotificationCenter.default.addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
|
|
|
- DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(batchFilesCountNotification(notification:)), name: NSNotification.Name("KMBatchFilesCountNotification"), object: nil)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
override func updateUILanguage() {
|
|
|
super.updateUILanguage()
|
|
|
|
|
@@ -226,18 +245,13 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
self.headerBottomLine.properties = ComponentDividerProperty()
|
|
|
self.ocrLabel.textColor = titleColor
|
|
|
self.bottomTopLine.properties = ComponentDividerProperty()
|
|
|
+
|
|
|
+ self.updateViewColor()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func localizedLanguage() {
|
|
|
self.outputTypeLabel.stringValue = KMLocalizedString("Output")
|
|
|
- self.btnMerge.title = KMLocalizedString("Merge All")
|
|
|
- self.createNewPDFBtn.title = KMLocalizedString("New PDF Document")
|
|
|
- self.appendPDFBtn.title = KMLocalizedString("Append To Existing File")
|
|
|
- self.appendTextField.placeholderString = KMLocalizedString("Select a File")
|
|
|
- self.selectLanguageLabel.stringValue = KMLocalizedString("Select OCR Language:")
|
|
|
- self.selectLanguageLabel.isHidden = true
|
|
|
- self.ocrSelectBtn.title = KMLocalizedString("OCR Plan")
|
|
|
|
|
|
let languages = KMGOCRManager.languages() as NSArray
|
|
|
let strings = languages.value(forKeyPath: KMGOCRLanguageStringKey) as? [String]
|
|
@@ -251,7 +265,6 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
menuItemArr.append(itemProperty)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
languageView_.updateMenuItemsArr(menuItemArr)
|
|
|
|
|
|
languageView_.selectItemAtIndex(0)
|
|
@@ -260,47 +273,22 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
languageView_.reloadData()
|
|
|
|
|
|
self.updateLanguageButton((KMGOCRManager.default().selectedLanguages?.value(forKeyPath: KMGOCRLanguageStringKey) as? [String]))
|
|
|
-
|
|
|
- self.actionButton.title = KMLocalizedString("Save as PDF")
|
|
|
- self.saveAsButton.title = KMLocalizedString("Save as TXT")
|
|
|
self.OCRSelectedPlanChangeAction()
|
|
|
}
|
|
|
func configuUI() {
|
|
|
self.view.wantsLayer = true
|
|
|
|
|
|
- appendOtherPDFBtn.wantsLayer = true
|
|
|
- appendBackView.wantsLayer = true
|
|
|
- appendBackView.layer?.borderWidth = 0.5
|
|
|
-
|
|
|
- self.appendOtherPDFBtn.layer?.backgroundColor = KMAppearance.Interactive.s0Color().withAlphaComponent(0.4).cgColor
|
|
|
-
|
|
|
- createNewPDFBtn.setTitleColor(KMAppearance.Layout.h0Color())
|
|
|
newPDFBox.borderWidth = 0
|
|
|
newPDFBox.contentView = createNewPDFRadio_
|
|
|
createNewPDFRadio_.setTarget(self, action: #selector(buttonClicked_CreateNewPDF))
|
|
|
|
|
|
- createNewPDFBtn.isHidden = true
|
|
|
- self.btnMerge.setTitleColor(KMAppearance.Layout.h0Color())
|
|
|
- self.appendPDFBtn.setTitleColor(KMAppearance.Layout.h0Color())
|
|
|
-
|
|
|
- appendBackBox.contentView = appendBackInput
|
|
|
-
|
|
|
- btnMerge.isHidden = true
|
|
|
mergeAllBox.borderWidth = 0
|
|
|
mergeAllBox.contentView = mergeAllCheckBox_
|
|
|
|
|
|
- appendPDFBtn.isHidden = true
|
|
|
appendBox.borderWidth = 0
|
|
|
appendBox.contentView = appendRadio_
|
|
|
appendRadio_.setTarget(self, action: #selector(buttonClicked_AppendOtherPDF))
|
|
|
|
|
|
- self.ocrSelectBtn.setTitleColor(KMAppearance.Layout.h0Color())
|
|
|
- self.saveAsButton.setTitleColor(KMAppearance.Layout.h0Color())
|
|
|
- self.selectLanguageLabel.textColor = KMAppearance.Layout.h0Color()
|
|
|
- saveAsButton.isHidden = true
|
|
|
-
|
|
|
- ocrSelectBtn.isHidden = true
|
|
|
-
|
|
|
languageBox.borderWidth = 0
|
|
|
languageBox.contentView = languageView_
|
|
|
|
|
@@ -316,35 +304,17 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
|
|
|
extractTextBox.borderWidth = 0
|
|
|
extractTextBox.contentView = extractTextCheckBox_
|
|
|
-
|
|
|
- appendTextField.backgroundColor = KMAppearance.Layout.l1Color()
|
|
|
- appendTextField.wantsLayer = true
|
|
|
- appendTextField.layer?.cornerRadius = 1.0
|
|
|
- languageButton.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
- languaeBox.borderColor = KMAppearance.Interactive.s0Color()
|
|
|
- planBox.borderColor = KMAppearance.Interactive.s0Color()
|
|
|
- languaeBox.fillColor = KMAppearance.Layout.l1Color()
|
|
|
- planBox.fillColor = KMAppearance.Layout.l1Color()
|
|
|
- languaeBox.isHidden = true
|
|
|
-
|
|
|
-
|
|
|
- self.updateViewColor()
|
|
|
}
|
|
|
+
|
|
|
func updateViewColor() {
|
|
|
if KMAppearance.isDarkMode() {
|
|
|
self.view.layer?.backgroundColor = NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
|
|
|
- appendBackView.layer?.borderColor = NSColor(red: 86/255.0, green: 88/255.0, blue: 90/255.0, alpha: 1).cgColor
|
|
|
- appendBackView.layer?.backgroundColor = NSColor(red: 57/255.0, green: 60/255.0, blue: 62/255.0, alpha: 1).cgColor
|
|
|
} else {
|
|
|
self.view.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
|
|
|
- appendBackView.layer?.borderColor = NSColor(red: 218/255.0, green: 219/255.0, blue: 222/255.0, alpha: 1).cgColor
|
|
|
- appendBackView.layer?.backgroundColor = NSColor.white.cgColor;
|
|
|
}
|
|
|
}
|
|
|
func updateLanguageButton(_ languages: [String]?) {
|
|
|
if languages?.count ?? 0 < 1 {
|
|
|
- self.languageButton.title = " " + KMLocalizedString("Auto Detection")
|
|
|
-
|
|
|
self.languageView_.properties.text = " " + KMLocalizedString("Auto Detection")
|
|
|
self.languageView_.reloadData()
|
|
|
return
|
|
@@ -363,10 +333,10 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
languageName = ""
|
|
|
}
|
|
|
|
|
|
- self.languageButton.title = " " + languageName
|
|
|
self.languageView_.properties.text = " " + languageName
|
|
|
self.languageView_.reloadData()
|
|
|
}
|
|
|
+
|
|
|
func converArrType(arr: Array<KMBatchOperateFile>, keyString: String) -> [String] {
|
|
|
let newArr = NSMutableArray()
|
|
|
for item in arr {
|
|
@@ -374,25 +344,14 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
}
|
|
|
return newArr as! [String]
|
|
|
}
|
|
|
+
|
|
|
func isConnectionAvailable() -> Bool {
|
|
|
- // var isExistenceNetwork = true
|
|
|
- // let reach = Reachability(hostname: "www.apple.com")
|
|
|
- // let status: NetworkStatus = NetworkStatus(rawValue: (reach?.currentReachabilityStatus())!.rawValue)
|
|
|
- // switch status.rawValue {
|
|
|
- // case 0:
|
|
|
- // isExistenceNetwork = false
|
|
|
- // case 1:
|
|
|
- // isExistenceNetwork = true
|
|
|
- // case 2:
|
|
|
- // isExistenceNetwork = true
|
|
|
- // default:
|
|
|
- // break
|
|
|
- // }
|
|
|
if Reachability.forInternetConnection().currentReachabilityStatus().rawValue == 0 {
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
+
|
|
|
func beginImageToPDF() {
|
|
|
if self.files?.count ?? 0 < 1 {
|
|
|
return
|
|
@@ -443,7 +402,7 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
isCreatNewPDF = true
|
|
|
|
|
|
} else {
|
|
|
- let appenString = self.appendTextField.stringValue
|
|
|
+ let appenString = appendBackInput_.properties.text
|
|
|
if appenString.isEmpty {
|
|
|
let alert = NSAlert()
|
|
|
alert.alertStyle = .critical
|
|
@@ -452,12 +411,11 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- path = self.appendTextField.stringValue
|
|
|
+ path = appenString
|
|
|
isMerge = true
|
|
|
isCreatNewPDF = false
|
|
|
}
|
|
|
|
|
|
- self.languageButton.isEnabled = false
|
|
|
ocrPlanRadio_.properties.isDisabled = true
|
|
|
ocrPlanRadio_.reloadData()
|
|
|
ocrPlanRadio2_.properties.isDisabled = true
|
|
@@ -468,7 +426,6 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
self.method.saveAsTestPath = self.choosePath
|
|
|
self.method.exportPDFFile(fileArray: photoArray, savePath: path, isOCR: isOCR, isCreatPDF: isCreatNewPDF, isMerge: isMerge, isSaveAsText: isSaveAs) { [weak self] savePath, errorArr, errorOCRArray in
|
|
|
|
|
|
- self?.languageButton.isEnabled = true
|
|
|
self?.ocrPlanRadio_.properties.isDisabled = false
|
|
|
self?.ocrPlanRadio_.reloadData()
|
|
|
self?.ocrPlanRadio2_.properties.isDisabled = false
|
|
@@ -522,54 +479,20 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
if radio.isEqual(to: sender) {
|
|
|
radio.properties.checkboxType = .selected
|
|
|
radio.reloadData()
|
|
|
+
|
|
|
+ KMGOCRManager.default().ocrType = .google
|
|
|
+ KMDataManager.ud_set(0, forKey: "KMOCRCurrentPlanKey")
|
|
|
} else {
|
|
|
radio.properties.checkboxType = .normal
|
|
|
radio.reloadData()
|
|
|
+
|
|
|
+ KMGOCRManager.default().ocrType = .apple
|
|
|
+ KMDataManager.ud_set(1, forKey: "KMOCRCurrentPlanKey")
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- //MARK: Notification
|
|
|
- @objc func OCRSelectedLanguagesChangeNotification(notification: Notification) {
|
|
|
- let selectedLanguages = notification.object/* as? [KMBatchOperateFile]*/
|
|
|
- self.updateLanguageButton(selectedLanguages as? [String])
|
|
|
- }
|
|
|
- @objc func OCRSelectedPlanChangeNotification(notification: Notification) {
|
|
|
+
|
|
|
self.OCRSelectedPlanChangeAction()
|
|
|
}
|
|
|
- @objc func themeChanged(notification: Notification) {
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
- self.updateViewColor()
|
|
|
- }
|
|
|
- }
|
|
|
- func OCRSelectedPlanChangeAction() {
|
|
|
- let plan = UserDefaults.standard.integer(forKey: "KMOCRCurrentPlanKey")
|
|
|
- if plan == 0 {
|
|
|
-// self.planButton.title = " " + KMLocalizedString("Plan 1 (Online)")
|
|
|
- ocrPlanRadio_.properties.checkboxType = .selected
|
|
|
- ocrPlanRadio_.reloadData()
|
|
|
- ocrPlanRadio2_.properties.checkboxType = .normal
|
|
|
- ocrPlanRadio2_.reloadData()
|
|
|
- } else {
|
|
|
-// self.planButton.title = " " + KMLocalizedString("Plan 2 (Offline)")
|
|
|
- ocrPlanRadio_.properties.checkboxType = .normal
|
|
|
- ocrPlanRadio_.reloadData()
|
|
|
- ocrPlanRadio2_.properties.checkboxType = .selected
|
|
|
- ocrPlanRadio2_.reloadData()
|
|
|
- }
|
|
|
- KMGOCRManager.default().selectedLanguages = NSMutableArray()
|
|
|
- self.updateLanguageButton(KMGOCRManager.default().selectedLanguages?.value(forKeyPath: KMGOCRLanguageStringKey) as? [String])
|
|
|
- }
|
|
|
- @objc func batchFilesCountNotification(notification: Notification) {
|
|
|
- let files: Array? = notification.object as? [KMBatchOperateFile]
|
|
|
- self.files? = files ?? []
|
|
|
- let cnt = self.files?.count ?? 0
|
|
|
- if cnt > 0 {
|
|
|
- self._updateActionButtonEnable(true)
|
|
|
- } else {
|
|
|
- self._updateActionButtonEnable(false)
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
@IBAction func buttonClicked_CreateNewPDF(_ sender: ComponentRadio) {
|
|
|
if (sender.properties.checkboxType == .selected) {
|
|
@@ -578,7 +501,11 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
|
|
|
appendRadio_.properties.checkboxType = .normal
|
|
|
appendRadio_.reloadData()
|
|
|
- self.appendOtherPDFBtn.isEnabled = false
|
|
|
+
|
|
|
+ appendBackInput_.properties.isDisabled = true
|
|
|
+ appendBackInput_.reloadData()
|
|
|
+ appendBackButtonInput_.properties.isDisabled = true
|
|
|
+ appendBackButtonInput_.reloadData()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -591,7 +518,10 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
mergeAllCheckBox_.properties.isDisabled = true
|
|
|
mergeAllCheckBox_.reloadData()
|
|
|
|
|
|
- self.appendOtherPDFBtn.isEnabled = true
|
|
|
+ appendBackInput_.properties.isDisabled = false
|
|
|
+ appendBackInput_.reloadData()
|
|
|
+ appendBackButtonInput_.properties.isDisabled = false
|
|
|
+ appendBackButtonInput_.reloadData()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -624,31 +554,7 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @IBAction func buttonClicked_ChooseLanguage(_ sender: NSButton) {
|
|
|
- let plan = UserDefaults.standard.integer(forKey: "KMOCRCurrentPlanKey")
|
|
|
- if plan == 0 {
|
|
|
- KMGOCRManager.default().ocrType = .google
|
|
|
- } else {
|
|
|
- KMGOCRManager.default().ocrType = .apple
|
|
|
- }
|
|
|
- let popover = NSPopover()
|
|
|
- popover.delegate = self
|
|
|
- popover.contentViewController = KMLanguageViewController(nibName: "KMLanguageViewController", bundle: Bundle.main)
|
|
|
- popover.animates = true
|
|
|
- popover.behavior = .transient
|
|
|
- popover.show(relativeTo: sender.bounds, of: sender as NSView, preferredEdge: .minX)
|
|
|
- }
|
|
|
-
|
|
|
- @IBAction func buttonClicked_ChoosePlan(_ sender: NSButton) {
|
|
|
- let popover = NSPopover()
|
|
|
- popover.delegate = self
|
|
|
- popover.contentViewController = KMPlanViewController(nibName: "KMPlanViewController", bundle: Bundle.main)
|
|
|
- popover.animates = true
|
|
|
- popover.behavior = .transient
|
|
|
- popover.show(relativeTo: sender.bounds, of: sender as NSView, preferredEdge: .minX)
|
|
|
- }
|
|
|
-
|
|
|
- @IBAction func buttonClicked_ImageToPDF(_ sender: NSButton) {
|
|
|
+ @IBAction func buttonClicked_ImageToPDF(_ sender: ComponentButton) {
|
|
|
//MARK: 判断是否付费用户,展示iap界面
|
|
|
if self.files?.count ?? 0 < 1 {
|
|
|
return
|
|
@@ -657,7 +563,7 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
|
|
|
return
|
|
|
}
|
|
|
- if sender.tag == 1 {
|
|
|
+ if sender.properties.state == .pressed {
|
|
|
self.choosePath = ""
|
|
|
var hasTask = false
|
|
|
for i in 0..<(self.files?.count ?? 0) {
|
|
@@ -698,7 +604,7 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
}
|
|
|
|
|
|
if createNewPDFRadio_.properties.checkboxType != .selected {
|
|
|
- let appenString = self.appendTextField.stringValue
|
|
|
+ let appenString = appendBackInput_.properties.text
|
|
|
if appenString.isEmpty {
|
|
|
let alert = NSAlert()
|
|
|
alert.alertStyle = .critical
|
|
@@ -727,6 +633,11 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
}
|
|
|
|
|
|
@IBAction func buttonItemClicked_AppendOtherPDF(_ sender: NSButton) {
|
|
|
+ let isDisabled = appendBackButtonInput_.properties.isDisabled
|
|
|
+ if isDisabled {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
let openPanel = NSOpenPanel()
|
|
|
openPanel.allowedFileTypes = ["pdf"]
|
|
|
openPanel.canChooseDirectories = false
|
|
@@ -753,57 +664,55 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController {
|
|
|
KMBaseWindowController.checkPassword(url: url, type: .owner) { [weak self] success, resultPassword in
|
|
|
if success {
|
|
|
self?.password = resultPassword
|
|
|
- self?.appendTextField.stringValue = url.path
|
|
|
+
|
|
|
+ self?.appendBackInput_.properties.text = url.path
|
|
|
+ self?.appendBackInput_.reloadData()
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- self.appendTextField.stringValue = url.path
|
|
|
+ self.appendBackInput_.properties.text = url.path
|
|
|
+ self.appendBackInput_.reloadData()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @IBAction func buttonClicked_Help(_ sender: NSButton) {
|
|
|
- let helpController = NSViewController()
|
|
|
- let textView = NSTextView(frame: NSRect(x: 0, y: 0, width: 300.0, height: 100.0))
|
|
|
- textView.backgroundColor = NSColor.clear
|
|
|
- textView.isEditable = false
|
|
|
- textView.layer?.cornerRadius = 6
|
|
|
- let tStrAuto = NSLocalizedString("Choose automatic language detection for better OCR results.", comment: "")
|
|
|
- let tStrVPN = NSLocalizedString("The OCR service works via an internet connection. We would suggest you to perform OCR using a VPN connection while the service is limited.", comment: "")
|
|
|
- let plan = UserDefaults.standard.integer(forKey: "KMOCRCurrentPlanKey")
|
|
|
- if plan == 0 {
|
|
|
- textView.string = "\(tStrAuto)\n\n\(tStrVPN)"
|
|
|
+ // "Choose automatic language detection for better OCR results."
|
|
|
+ //MARK: -Notification
|
|
|
+
|
|
|
+ @objc func batchFilesCountNotification(notification: Notification) {
|
|
|
+ let files: Array? = notification.object as? [KMBatchOperateFile]
|
|
|
+ self.files? = files ?? []
|
|
|
+ let cnt = self.files?.count ?? 0
|
|
|
+ if cnt > 0 {
|
|
|
+ self._updateActionButtonEnable(true)
|
|
|
} else {
|
|
|
- textView.frame = NSRect(x: 0, y: 0, width: 300.0, height: 40.0)
|
|
|
- textView.string = tStrAuto
|
|
|
+ self._updateActionButtonEnable(false)
|
|
|
}
|
|
|
- helpController.view = textView
|
|
|
- let popover = NSPopover()
|
|
|
- popover.delegate = self
|
|
|
- popover.contentViewController = helpController
|
|
|
- popover.animates = true
|
|
|
- popover.behavior = .transient
|
|
|
- popover.show(relativeTo: sender.bounds, of: sender as NSView, preferredEdge: .minY)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //MARK: KMImageToPDFMethodDelegate
|
|
|
- func imageToPDFMethod(_ method: KMImageToPDFMethod, progress: Float) {
|
|
|
-
|
|
|
+ func OCRSelectedPlanChangeAction() {
|
|
|
+ KMGOCRManager.default().selectedLanguages = NSMutableArray()
|
|
|
+ self.updateLanguageButton(KMGOCRManager.default().selectedLanguages?.value(forKeyPath: KMGOCRLanguageStringKey) as? [String])
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// MAKR: - NSPopoverDelegate
|
|
|
+// MARK: - KMImageToPDFMethodDelegate
|
|
|
|
|
|
-extension KMBatchOperateImageToPDFViewController: NSPopoverDelegate {
|
|
|
-
|
|
|
+extension KMBatchOperateImageToPDFViewController: KMImageToPDFMethodDelegate {
|
|
|
+ func imageToPDFMethod(_ method: KMImageToPDFMethod, progress: Float) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-// MARK: - KMImageToPDFMethodDelegate
|
|
|
+// MARK: - ComponentSelectDelegate
|
|
|
|
|
|
-extension KMBatchOperateImageToPDFViewController: KMImageToPDFMethodDelegate {
|
|
|
-
|
|
|
+extension KMBatchOperateImageToPDFViewController: ComponentSelectDelegate {
|
|
|
+ func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
|
|
|
+ let idx = view?.indexOfSelect() ?? 0
|
|
|
+
|
|
|
+ let languages = KMGOCRManager.languages() as NSArray
|
|
|
+ let lanuage = languages[idx]
|
|
|
+ KMGOCRManager.default().selectedLanguages = [lanuage]
|
|
|
+ }
|
|
|
}
|