KMLeftSideViewSearchField.swift 939 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. // KMLeftSideViewSearchField.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/11/15.
  6. //
  7. import Cocoa
  8. class KMLeftSideViewSearchField: NSSearchField {
  9. var changeCallBack: ((_ changeContent: String?) -> Void)?
  10. var endEditCallBack: ((_ isEndEdit: Bool)->Void)?
  11. override func draw(_ dirtyRect: NSRect) {
  12. super.draw(dirtyRect)
  13. // Drawing code here.
  14. }
  15. override func textDidChange(_ notification: Notification) {
  16. super.textDidChange(notification)
  17. let searchField = notification.object as? NSTextView
  18. if (self.changeCallBack != nil) {
  19. self.changeCallBack?(searchField?.string)
  20. }
  21. }
  22. override func textDidEndEditing(_ notification: Notification) {
  23. super.textDidEndEditing(notification)
  24. guard let callback = self.endEditCallBack else {
  25. return
  26. }
  27. callback(true)
  28. }
  29. }