KMNLinkMultiController.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // KMNLinkMultiController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/10/21.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. @objc protocol KMNLinkMultiControllerDelegate: AnyObject {
  10. @objc optional func multiControllerDidClick(_ controller: KMNLinkMultiController, _ alignmentType: KMAnnotationsAlignmentType)
  11. }
  12. class KMNLinkMultiController: NSViewController {
  13. @IBOutlet var contendBox: NSBox!
  14. @IBOutlet var titleLabel: NSTextField!
  15. @IBOutlet var aligLeftButton: ComponentButton!
  16. @IBOutlet var aligLeftCenterButton: ComponentButton!
  17. @IBOutlet var aligRightButton: ComponentButton!
  18. @IBOutlet var aligTopButton: ComponentButton!
  19. @IBOutlet var aligTopCenterButton: ComponentButton!
  20. @IBOutlet var aligBottomButton: ComponentButton!
  21. @IBOutlet var aligHorizontalXButton: ComponentButton!
  22. @IBOutlet var aligVerticalYButton: ComponentButton!
  23. weak open var delegate: KMNLinkMultiControllerDelegate?
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. // Do view setup here.
  27. titleLabel.stringValue = KMLocalizedString("Alignment")
  28. aligLeftButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true)
  29. aligLeftButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignLeft")
  30. aligLeftCenterButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true)
  31. aligLeftCenterButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignXCenter")
  32. aligRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true)
  33. aligRightButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignRight")
  34. aligTopButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true)
  35. aligTopButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignTop")
  36. aligTopCenterButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true)
  37. aligTopCenterButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignYCenter")
  38. aligBottomButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true)
  39. aligBottomButton.properties.propertyInfo.leftIcon_nor = NSImage(named: "alignBottom")
  40. aligHorizontalXButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true)
  41. aligHorizontalXButton.properties.propertyInfo.leftIcon_dis = NSImage(named: "alignHorizonal_dis")
  42. aligHorizontalXButton.properties.isDisabled = true
  43. aligVerticalYButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, onlyIcon: true)
  44. aligVerticalYButton.properties.propertyInfo.leftIcon_dis = NSImage(named: "alignAverageVertical_dis")
  45. aligVerticalYButton.properties.isDisabled = true
  46. for button in [aligLeftButton, aligLeftCenterButton, aligRightButton, aligTopButton,
  47. aligTopCenterButton, aligBottomButton, aligHorizontalXButton, aligVerticalYButton] {
  48. button?.reloadData()
  49. button?.setTarget(self, action: #selector(buttonClicked(_:)))
  50. }
  51. }
  52. @objc func buttonClicked(_ sender: ComponentButton) {
  53. var alignmentType: KMAnnotationsAlignmentType = .None
  54. if sender == aligLeftButton {
  55. alignmentType = .Left
  56. } else if sender == aligLeftCenterButton {
  57. alignmentType = .XCenter
  58. } else if sender == aligRightButton {
  59. alignmentType = .Right
  60. } else if sender == aligTopButton {
  61. alignmentType = .Top
  62. } else if sender == aligTopCenterButton {
  63. alignmentType = .YCenter
  64. } else if sender == aligBottomButton {
  65. alignmentType = .Bottom
  66. }
  67. delegate?.multiControllerDidClick?(self, alignmentType)
  68. }
  69. }