KMRedactToolbarController.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // KMRedactToolbarController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/12/18.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. @objc protocol KMRedactToolbarControllerDelegate: AnyObject {
  10. @objc optional func redactToolbarControllerDidButtonClick(controller: KMRedactToolbarController, buttonIndex: Int)
  11. }
  12. class KMRedactToolbarController: NSViewController {
  13. @IBOutlet var contendView: NSView!
  14. @IBOutlet var titleLabel: NSTextField!
  15. @IBOutlet var redactButton: ComponentButton!
  16. @IBOutlet var propertyButton: ComponentButton!
  17. @IBOutlet var applyButton: ComponentButton!
  18. @IBOutlet var exitButton: ComponentButton!
  19. weak open var delegate: KMRedactToolbarControllerDelegate?
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22. // Do view setup here.
  23. self.setupProperty()
  24. self.updateUI()
  25. self.reloadData()
  26. }
  27. func setupProperty() {
  28. titleLabel.stringValue = KMLocalizedString("Redact")
  29. titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
  30. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  31. redactButton.properties = ComponentButtonProperty(type: .text_gray_opacity,
  32. size: .xs,
  33. state: .pressed,
  34. showLeftIcon: true,
  35. buttonText: KMLocalizedString("Redact"),
  36. icon: NSImage(named: "redact_sec_Toolbar"),
  37. keepPressState: true,
  38. identifier: "")
  39. propertyButton.properties = ComponentButtonProperty(type: .text_gray_opacity,
  40. size: .xs,
  41. state: .normal,
  42. showLeftIcon: true,
  43. buttonText: KMLocalizedString("Properties"),
  44. icon: NSImage(named: "redact_Properties"),
  45. keepPressState: false,
  46. identifier: "")
  47. applyButton.properties = ComponentButtonProperty(type: .primary,
  48. size: .xs,
  49. state: .normal,
  50. buttonText: KMLocalizedString("Apply"),
  51. keepPressState: false,
  52. identifier: "")
  53. exitButton.properties = ComponentButtonProperty(type: .default_tertiary,
  54. size: .xs,
  55. state: .normal,
  56. buttonText: KMLocalizedString("Exit"),
  57. keepPressState: false,
  58. identifier: "")
  59. redactButton.setTarget(self, action: #selector(buttonClicked(_:)))
  60. propertyButton.setTarget(self, action: #selector(buttonClicked(_:)))
  61. applyButton.setTarget(self, action: #selector(buttonClicked(_:)))
  62. exitButton.setTarget(self, action: #selector(buttonClicked(_:)))
  63. }
  64. func updateUI() {
  65. self.contendView.wantsLayer = true
  66. self.contendView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor
  67. }
  68. func reloadData() {
  69. redactButton.reloadData()
  70. propertyButton.reloadData()
  71. applyButton.reloadData()
  72. exitButton.reloadData()
  73. }
  74. @objc func buttonClicked(_ sender: ComponentButton) {
  75. if sender == redactButton {
  76. } else if sender == propertyButton {
  77. delegate?.redactToolbarControllerDidButtonClick?(controller: self, buttonIndex: 1)
  78. } else if sender == applyButton {
  79. delegate?.redactToolbarControllerDidButtonClick?(controller: self, buttonIndex: 2)
  80. } else if sender == exitButton {
  81. delegate?.redactToolbarControllerDidButtonClick?(controller: self, buttonIndex: 3)
  82. }
  83. }
  84. }