KMBatchCompressView.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // KMBatchCompressView.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/1/16.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMBatchCompressView: KMBatchSettingItemView {
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var titleContentView: NSView!
  12. @IBOutlet weak var applyButton: ComponentButton!
  13. @IBOutlet weak var compressView: KMCompressContentView!
  14. @IBOutlet weak var cancelButton: ComponentButton!
  15. var data: KMCompressSettingModel = KMCompressSettingModel(modelsType: .standard)
  16. override func draw(_ dirtyRect: NSRect) {
  17. super.draw(dirtyRect)
  18. // Drawing code here.
  19. }
  20. override func setup() {
  21. titleLabel.stringValue = KMLocalizedString("Modes")
  22. titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
  23. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  24. self.titleContentView.border(ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider"), 0.5, 0)
  25. self.applyButton.properties = ComponentButtonProperty(type: .primary,
  26. size: .m,
  27. state: .normal,
  28. buttonText: KMLocalizedString("Apply"),
  29. keepPressState: false)
  30. self.applyButton.setTarget(self, action: #selector(compressButtonAction(_:)))
  31. self.applyButton.reloadData()
  32. self.compressView.selectTypeAction = {[unowned self] view, tModel in
  33. self.data = tModel
  34. }
  35. self.compressView.compressAction = { [unowned self] view, model, showView in
  36. self.compressView.closeSettingWindow()
  37. self.compressButtonAction(self.applyButton as Any)
  38. }
  39. self.cancelButton.properties = ComponentButtonProperty(type: .primary,
  40. size: .m,
  41. state: .normal,
  42. buttonText: KMLocalizedString("Cancel"),
  43. keepPressState: false)
  44. self.cancelButton.setTarget(self, action: #selector(cancelButtonAction))
  45. self.cancelButton.reloadData()
  46. self.cancelButton.isHidden = true
  47. }
  48. override func reloadData() {
  49. let type = KMCompressSettingModel.fetchCompressType()
  50. self.compressView.model = KMCompressSettingModel(modelsType: type)
  51. }
  52. override func bacthProcessingNotification() {
  53. self.compressView.isDisable = self.isDisable
  54. self.applyButton.properties.isDisabled = self.isDisable
  55. self.applyButton.reloadData()
  56. self.updateCancelButtonState()
  57. }
  58. func updateCancelButtonState() {
  59. if self.isDisable {
  60. self.applyButton.isHidden = true
  61. self.cancelButton.isHidden = false
  62. } else {
  63. self.applyButton.isHidden = false
  64. self.cancelButton.isHidden = true
  65. }
  66. }
  67. }
  68. protocol KMBatchCompressViewAction {}
  69. extension KMBatchCompressView: KMBatchCompressViewAction {
  70. func compressButtonAction(_ sender: Any) {
  71. if KMMemberInfo.shared.isLogin == false {
  72. KMLoginWindowsController.shared.showWindow(nil)
  73. return
  74. }
  75. self.data = self.compressView.model
  76. //保存默认参数
  77. KMCompressSettingModel.saveCompressType(type: self.data.modelsType)
  78. if self.batchExport != nil {
  79. self.batchExport!(self, self.data)
  80. }
  81. }
  82. @objc func cancelButtonAction() {
  83. self.cancelAction?(self)
  84. self.updateCancelButtonState()
  85. }
  86. }