KMComparativeTableView.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // KMComparativeTableView.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2023/2/24.
  6. //
  7. import Cocoa
  8. typealias KMComparativeTableViewCloseAction = (_ view: KMComparativeTableView) -> Void
  9. typealias KMComparativeTableViewLoginAction = (_ view: KMComparativeTableView) -> Void
  10. typealias KMComparativeTableViewSignUpAction = (_ view: KMComparativeTableView) -> Void
  11. typealias KMComparativeTableViewSubscriptionAction = (_ view: KMComparativeTableView) -> Void
  12. typealias KMComparativeTableViewRestoreAction = (_ view: KMComparativeTableView) -> Void
  13. class KMComparativeTableView: KMBaseXibView {
  14. @IBOutlet weak var closeBox: KMBox!
  15. @IBOutlet weak var closeButton: NSButton!
  16. @IBOutlet weak var signUpButton: NSButton!
  17. @IBOutlet weak var loginButton: NSButton!
  18. @IBOutlet weak var outlineView: KMComparativeOutlineView!
  19. @IBOutlet weak var restoreButton: NSButton!
  20. @IBOutlet weak var waterMarkButton: NSButton!
  21. var closeAction: KMComparativeTableViewCloseAction?
  22. var loginAction: KMComparativeTableViewLoginAction?
  23. var signUpAction: KMComparativeTableViewSignUpAction?
  24. var subscriptionAction: KMComparativeTableViewSubscriptionAction?
  25. var restoreAction: KMComparativeTableViewRestoreAction?
  26. override func draw(_ dirtyRect: NSRect) {
  27. super.draw(dirtyRect)
  28. // Drawing code here.
  29. }
  30. override func setup() {
  31. super.setup()
  32. self.closeBox.moveCallback = { [weak self] (mouseEntered, mouseBox) in
  33. if mouseEntered {
  34. self?.closeButton.image = NSImage(named: "control_btn_icon_close_hov")
  35. } else {
  36. self?.closeButton.image = NSImage(named: "control_btn_icon_close")
  37. }
  38. }
  39. }
  40. override func updateUI() {
  41. super.updateUI()
  42. #if VERSION_FREE
  43. self.restoreButton.isHidden = false
  44. #endif
  45. if KMPurchaseManager.manager.state == .subscription {
  46. self.waterMarkButton.isHidden = true
  47. }
  48. self.backgroundColor(NSColor.km_init(hex: "#F2F9FF"))
  49. self.loginButton.backgroundColor(NSColor.km_init(hex: "#1770F4"))
  50. self.loginButton.border(NSColor.km_init(hex: "#1770F4"), 1, 4)
  51. self.loginButton.contentTintColor = NSColor.km_init(hex: "FFFFFF")
  52. self.signUpButton.contentTintColor = NSColor.km_init(hex: "#1770F4")
  53. }
  54. override func reloadData() {
  55. super.reloadData()
  56. }
  57. override func updateLanguage() {
  58. super.updateLanguage()
  59. self.signUpButton.title = NSLocalizedString("Sign Up", comment: "")
  60. self.loginButton.title = NSLocalizedString("Log In", comment: "")
  61. }
  62. }
  63. protocol KMComparativeTableViewAction {}
  64. extension KMComparativeTableView: KMComparativeTableViewAction {
  65. @IBAction func closeButtonAction(_ sender: Any) {
  66. guard let callBack = closeAction else { return }
  67. callBack(self)
  68. }
  69. @IBAction func signUpButtonAction(_ sender: Any) {
  70. guard let callBack = signUpAction else { return }
  71. callBack(self)
  72. }
  73. @IBAction func loginButtonAction(_ sender: Any) {
  74. guard let callBack = loginAction else { return }
  75. callBack(self)
  76. }
  77. @IBAction func subscriptionButtonAction(_ sender: Any) {
  78. guard let callBack = subscriptionAction else { return }
  79. callBack(self)
  80. }
  81. @IBAction func restoreButtonAction(_ sender: Any) {
  82. guard let callBack = restoreAction else { return }
  83. callBack(self)
  84. }
  85. @IBAction func waterMarkButtonAction(_ sender: Any) {
  86. KMSubscribeWaterMarkWindowController.show(window: self.window ?? NSWindow()) { isSubscribeSuccess, isWaterMark, isClose in
  87. }
  88. }
  89. }