KMCreatPDFView.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if KMAppearance.isDarkMode() {
  26. self.creatLabel.textColor = NSColor.white
  27. } else {
  28. self.creatLabel.textColor = KMAppearance.Interactive.m0Color()
  29. }
  30. self.openBox.fillColor = KMAppearance.Interactive.m0Color()
  31. self.openBox.toolTip = NSLocalizedString("Open PDF", comment: "")
  32. self.openBox.downCallback = { [unowned self] downEntered, mouseBox, event in
  33. if (downEntered) {
  34. self.openBox.fillColor = KMAppearance.Interactive.m_1Color()
  35. self.openPDFButtonAction()
  36. } else {
  37. self.openBox.fillColor = KMAppearance.Interactive.m0Color()
  38. }
  39. };
  40. self.openBox.moveCallback = { [unowned self] mouseEntered, mouseBox in
  41. if (mouseEntered) {
  42. self.openBox.fillColor = KMAppearance.Interactive.m1Color()
  43. } else {
  44. self.openBox.fillColor = KMAppearance.Interactive.m0Color()
  45. }
  46. };
  47. self.creatBox.toolTip = NSLocalizedString("Create PDF", comment: "")
  48. self.creatBox.fillColor = KMAppearance.Layout.l0Color()
  49. self.creatBox.borderWidth = 1.0;
  50. self.creatBox.borderColor = KMAppearance.Interactive.m0Color()
  51. self.creatBox.downCallback = { [unowned self] downEntered, mouseBox, event in
  52. if (downEntered) {
  53. self.creatBox.fillColor = KMAppearance.Status.preColor()
  54. self.createPDFButtonAction()
  55. } else {
  56. self.creatBox.fillColor = KMAppearance.Layout.l0Color()
  57. }
  58. };
  59. self.creatBox.moveCallback = { [unowned self] mouseEntered, mouseBox in
  60. if (mouseEntered) {
  61. self.creatBox.fillColor = KMAppearance.Status.hovColor()
  62. } else {
  63. self.creatBox.fillColor = KMAppearance.Layout.l0Color()
  64. }
  65. };
  66. }
  67. @objc func openPDFButtonAction() {
  68. guard let callBack = openPDFAction else { return }
  69. callBack(self, self.openBox)
  70. }
  71. @objc func createPDFButtonAction() {
  72. guard let callBack = creatPDFAction else { return }
  73. callBack(self, self.creatBox)
  74. }
  75. }