AITipIconView.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // AITipIconView.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2024/1/17.
  6. //
  7. import Cocoa
  8. @objcMembers class AITipIconView: NSView, NibLoadable {
  9. @IBOutlet weak var clickButton: KMButton!
  10. @IBOutlet weak var hoverImage: NSImageView!
  11. var clickHandle: ((_ view: AITipIconView) -> Void)?
  12. var rightClickHandle: ((_ view: AITipIconView) -> Void)?
  13. override func draw(_ dirtyRect: NSRect) {
  14. super.draw(dirtyRect)
  15. // Drawing code here.
  16. }
  17. @objc static func ocCreateFunction() -> AITipIconView{
  18. return AITipIconView.createFromNib()!
  19. }
  20. override func awakeFromNib() {
  21. super.awakeFromNib()
  22. self.clickButton.mouseMoveCallback = {[unowned self] mouseEntered in
  23. if mouseEntered {
  24. self.hoverImage.image = NSImage(named: "pop-btn_hover")
  25. } else {
  26. self.hoverImage.image = NSImage(named: "pop-btn")
  27. }
  28. }
  29. let menu = NSMenu.init()
  30. let string = NSLocalizedString("Hide AI robot icon", comment: "")
  31. let menuItem = NSMenuItem.init(title: string, action: #selector(menuItemClick(_:)), keyEquivalent: "")
  32. menuItem.tag = 1000
  33. menu.addItem(menuItem)
  34. self.clickButton?.menu = menu
  35. }
  36. @objc func menuItemClick(_ item: NSMenuItem) {
  37. guard let callBack = self.rightClickHandle else {
  38. return
  39. }
  40. callBack(self)
  41. }
  42. //MARK: IBAction
  43. @IBAction func clickAction(_ sender: Any) {
  44. guard let callBack = self.clickHandle else {
  45. return
  46. }
  47. callBack(self)
  48. }
  49. }