// // KMBatchCompressView.swift // PDF Master // // Created by lizhe on 2023/1/16. // import Cocoa import KMComponentLibrary class KMBatchCompressView: KMBatchSettingItemView { @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var titleContentView: NSView! @IBOutlet weak var applyButton: ComponentButton! @IBOutlet weak var compressView: KMCompressContentView! @IBOutlet weak var cancelButton: ComponentButton! var data: KMCompressSettingModel = KMCompressSettingModel(modelsType: .standard) override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } override func setup() { titleLabel.stringValue = KMLocalizedString("Modes") titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1") titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium") self.titleContentView.border(ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider"), 0.5, 0) self.applyButton.properties = ComponentButtonProperty(type: .primary, size: .m, state: .normal, buttonText: KMLocalizedString("Apply"), keepPressState: false) self.applyButton.setTarget(self, action: #selector(compressButtonAction(_:))) self.applyButton.reloadData() self.compressView.selectTypeAction = {[unowned self] view, tModel in self.data = tModel } self.compressView.compressAction = { [unowned self] view, model, showView in self.compressView.closeSettingWindow() self.compressButtonAction(self.applyButton as Any) } self.cancelButton.properties = ComponentButtonProperty(type: .primary, size: .m, state: .normal, buttonText: KMLocalizedString("Cancel"), keepPressState: false) self.cancelButton.setTarget(self, action: #selector(cancelButtonAction)) self.cancelButton.reloadData() self.cancelButton.isHidden = true } override func reloadData() { let type = KMCompressSettingModel.fetchCompressType() self.compressView.model = KMCompressSettingModel(modelsType: type) } override func bacthProcessingNotification() { self.compressView.isDisable = self.isDisable self.applyButton.properties.isDisabled = self.isDisable self.applyButton.reloadData() self.updateCancelButtonState() } func updateCancelButtonState() { if self.isDisable { self.applyButton.isHidden = true self.cancelButton.isHidden = false } else { self.applyButton.isHidden = false self.cancelButton.isHidden = true } } } protocol KMBatchCompressViewAction {} extension KMBatchCompressView: KMBatchCompressViewAction { func compressButtonAction(_ sender: Any) { if KMMemberInfo.shared.isLogin == false { KMLoginWindowsController.shared.showWindow(nil) return } self.data = self.compressView.model //保存默认参数 KMCompressSettingModel.saveCompressType(type: self.data.modelsType) if self.batchExport != nil { self.batchExport!(self, self.data) } } @objc func cancelButtonAction() { self.cancelAction?(self) self.updateCancelButtonState() } }