KMMergeSelect.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // KMMergeSelect.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/3/24.
  6. //
  7. import Cocoa
  8. class KMMergeSelect: KMDesignSelect {
  9. private var button: NSButton?
  10. private var rightButton: NSButton?
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. let button = NSButton()
  14. button.frame = self.view.bounds
  15. self.view.addSubview(button)
  16. button.autoresizingMask = [.width, .height]
  17. button.target = self
  18. button.action = #selector(buttonAction)
  19. button.wantsLayer = true
  20. button.isBordered = false
  21. button.layer?.backgroundColor = NSColor.clear.cgColor
  22. button.title = ""
  23. self.button = button
  24. let rightButton = NSButton()
  25. rightButton.frame = NSMakeRect(NSWidth(self.view.frame)-40, 0, 40, NSHeight(self.view.frame))
  26. self.view.addSubview(rightButton)
  27. rightButton.autoresizingMask = [.minXMargin, .height]
  28. rightButton.target = self
  29. rightButton.action = #selector(buttonAction)
  30. rightButton.wantsLayer = true
  31. rightButton.isBordered = false
  32. rightButton.layer?.backgroundColor = NSColor.clear.cgColor
  33. rightButton.title = ""
  34. self.rightButton = rightButton
  35. }
  36. override var editable: Bool {
  37. get {
  38. return super.editable
  39. }
  40. set {
  41. super.editable = newValue
  42. if (self.button != nil) {
  43. DispatchQueue.main.async {
  44. self.button?.isHidden = newValue
  45. }
  46. }
  47. }
  48. }
  49. @objc private func buttonAction() {
  50. guard let callback = self.mainBox.downCallback else {
  51. return
  52. }
  53. callback(true, self.mainBox, NSEvent())
  54. }
  55. }