123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //
- // KMBatchOCRView.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2025/1/8.
- //
- import Cocoa
- import KMComponentLibrary
- class KMBatchOCRView: KMBatchSettingItemView {
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var titleContentView: NSView!
- @IBOutlet weak var ocrPageView: KMOCRPageView!
- @IBOutlet weak var applyButton: ComponentButton!
-
- var groupView: ComponentGroup!
-
- var model: KMOCRModel = KMOCRModel()
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- override func setup() {
- self.titleContentView.border(ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider"), 0.5, 0)
-
- applyButton.properties = ComponentButtonProperty(type: .primary, size: .m, showRightIcon: true, buttonText: KMLocalizedString("Apply"), keepPressState: false)
- applyButton.properties.propertyInfo.rightIcon_nor = NSImage(named: "arrowDown")
- applyButton.properties.propertyInfo.rightIcon_press = NSImage(named: "arrowDown_press")
- applyButton.setTarget(self, action: #selector(saveButtonClicked(_:)))
-
- applyButton.properties.buttonText = KMLocalizedString("Save as PDF")
- applyButton.properties.showRightIcon = true
-
- ocrPageView.type = .batch
- model.pageRangeType = .all
- model.saveAsPDF = true
- }
-
- //MARK: - GroupView
- func showGroupView() {
- var viewHeight: CGFloat = 8
- var menuItemArr: [ComponentMenuitemProperty] = []
- for i in ["Save as PDF", "Save as TXT"] {
- if i == " " {
- let property: ComponentMenuitemProperty = ComponentMenuitemProperty.divider()
- menuItemArr.append(property)
- viewHeight += 8
- } else {
- let properties_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: KMLocalizedString(i))
- menuItemArr.append(properties_Menuitem)
- viewHeight += 36
- }
- }
-
- if groupView == nil {
- groupView = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
- }
- groupView.groupDelegate = self
- groupView?.frame = CGRectMake(310, 0, CGRectGetWidth(applyButton.bounds), viewHeight)
- groupView.updateGroupInfo(menuItemArr)
-
- var point = self.convert(applyButton.frame.origin, to: nil)
- point.y += applyButton.bounds.size.height + 4
- groupView.showWithPoint(point, relativeTo: applyButton)
-
- applyButton.properties.state = .pressed
- applyButton.reloadData()
-
- }
-
- func removeGroupView() {
- if groupView != nil {
- groupView.removeFromSuperview()
- }
- applyButton.properties.state = .normal
- applyButton.reloadData()
- }
-
- override func bacthProcessingNotification() {
- self.ocrPageView.isDisabled = self.isDisable
- self.applyButton.properties.isDisabled = self.isDisable
- self.applyButton.reloadData()
- }
- }
- //MARK: Action
- extension KMBatchOCRView {
- @objc func saveButtonClicked(_ sender: ComponentButton) {
- showGroupView()
- }
- }
- extension KMBatchOCRView: ComponentGroupDelegate {
- func componentGroupDidDismiss(group: ComponentGroup?) {
- removeGroupView()
-
- applyButton.properties.state = .normal
- applyButton.reloadData()
- }
-
- func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
- if menuItemProperty?.text == KMLocalizedString("Save as PDF") {
- model.saveType = .PDF
- } else if menuItemProperty?.text == KMLocalizedString("Save as TXT") {
- model.saveType = .TXT
- }
-
- guard let callBack = batchExport else { return }
-
- callBack(self, model)
- }
- }
|