KMCreatPDFView.swift 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // KMCreatPDFView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lizhe on 2023/10/23.
  6. //
  7. import Cocoa
  8. typealias KMCreatPDFViewOpenPDFAction = (_ view: KMCreatPDFView, _ sender: KMBox) -> Void
  9. typealias KMCreatPDFViewCreatAction = (_ view: KMCreatPDFView, _ sender: KMBox) -> Void
  10. class KMCreatPDFView: KMBaseXibView {
  11. @IBOutlet weak var openBox: KMBox!
  12. @IBOutlet weak var openLabel: NSTextField!
  13. @IBOutlet weak var creatBox: KMBox!
  14. @IBOutlet weak var creatLabel: NSTextField!
  15. var openPDFAction: KMCreatPDFViewOpenPDFAction?
  16. var creatPDFAction: KMCreatPDFViewCreatAction?
  17. override func draw(_ dirtyRect: NSRect) {
  18. super.draw(dirtyRect)
  19. // Drawing code here.
  20. }
  21. override func setup() {
  22. self.openLabel.stringValue = NSLocalizedString("Open File", comment: "")
  23. self.openLabel.textColor = KMAppearance.Layout.w0Color()
  24. self.creatLabel.stringValue = NSLocalizedString("Create PDF", comment: "")
  25. self.creatLabel.textColor = KMAppearance.Layout.m_1Color()
  26. self.openBox.fillColor = KMAppearance.Interactive.m0Color()
  27. self.openBox.toolTip = NSLocalizedString("Open PDF", comment: "")
  28. self.openBox.downCallback = { [unowned self] downEntered, mouseBox, event in
  29. if (downEntered) {
  30. self.openBox.fillColor = KMAppearance.Interactive.m_1Color()
  31. self.openPDFButtonAction()
  32. } else {
  33. self.openBox.fillColor = KMAppearance.Interactive.m0Color()
  34. }
  35. };
  36. self.openBox.moveCallback = { [unowned self] mouseEntered, mouseBox in
  37. if (mouseEntered) {
  38. self.openBox.fillColor = KMAppearance.Interactive.m1Color()
  39. } else {
  40. self.openBox.fillColor = KMAppearance.Interactive.m0Color()
  41. }
  42. };
  43. self.creatBox.toolTip = NSLocalizedString("Create PDF", comment: "")
  44. self.creatBox.fillColor = KMAppearance.Layout.l0Color()
  45. self.creatBox.borderWidth = 1.0;
  46. self.creatBox.borderColor = KMAppearance.Interactive.m0Color()
  47. self.creatBox.downCallback = { [unowned self] downEntered, mouseBox, event in
  48. if (downEntered) {
  49. self.creatBox.fillColor = KMAppearance.Status.preColor()
  50. self.createPDFButtonAction()
  51. } else {
  52. self.creatBox.fillColor = KMAppearance.Layout.l0Color()
  53. }
  54. };
  55. self.creatBox.moveCallback = { [unowned self] mouseEntered, mouseBox in
  56. if (mouseEntered) {
  57. self.creatBox.fillColor = KMAppearance.Status.hovColor()
  58. } else {
  59. self.creatBox.fillColor = KMAppearance.Layout.l0Color()
  60. }
  61. };
  62. }
  63. @objc func openPDFButtonAction() {
  64. guard let callBack = openPDFAction else { return }
  65. callBack(self, self.openBox)
  66. }
  67. @objc func createPDFButtonAction() {
  68. guard let callBack = creatPDFAction else { return }
  69. callBack(self, self.creatBox)
  70. }
  71. }