KMBookCellView.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // KMBookCellView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lxy on 2022/11/14.
  6. //
  7. import Cocoa
  8. class KMBookCellView: NSTableCellView {
  9. @IBOutlet weak var bookTitle: NSTextField!
  10. @IBOutlet weak var iconIv: NSImageView!
  11. @IBOutlet weak var inputBox: NSBox!
  12. @IBOutlet weak var inputTF: KMTextField!
  13. @IBOutlet weak var dateLabel: NSTextField!
  14. var textFieldDidEndEditingCallback: ((NSTextField)->Void)?
  15. override func awakeFromNib() {
  16. super.awakeFromNib()
  17. bookTitle.isHidden = true
  18. bookTitle.font = NSFont.SFProTextRegularFont(13.0)
  19. bookTitle.textColor = KMAppearance.titleColor()
  20. dateLabel.font = NSFont.SFProTextRegularFont(12)
  21. dateLabel.textColor = NSColor.km_init(hex: "#757780")
  22. inputTF.isBordered = false
  23. inputTF.drawsBackground = false
  24. inputTF.delegate = self
  25. inputBox.cornerRadius = 0
  26. inputTF.isHighlighted = false
  27. inputTF.firstResponderHandler = { [weak self] firstResp in
  28. if firstResp {
  29. DispatchQueue.main.async {
  30. self?.inputBox.borderWidth = 1
  31. self?.inputBox.borderColor = NSColor.km_init(hex: "#4982E6")
  32. if KMAppearance.isDarkMode() {
  33. self?.inputBox.fillColor = .black
  34. } else {
  35. self?.inputBox.fillColor = .white
  36. }
  37. }
  38. }
  39. }
  40. }
  41. override func draw(_ dirtyRect: NSRect) {
  42. super.draw(dirtyRect)
  43. }
  44. }
  45. extension KMBookCellView: NSTextFieldDelegate {
  46. func controlTextDidEndEditing(_ obj: Notification) {
  47. if self.inputTF.isEqual(to: obj.object) {
  48. self.inputBox.borderWidth = 0
  49. self.inputBox.fillColor = .clear
  50. self.textFieldDidEndEditingCallback?(self.inputTF)
  51. }
  52. }
  53. }