1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- //
- // KMBookCellView.swift
- // PDF Reader Pro
- //
- // Created by lxy on 2022/11/14.
- //
- import Cocoa
- class KMBookCellView: NSTableCellView {
- @IBOutlet weak var bookTitle: NSTextField!
- @IBOutlet weak var iconIv: NSImageView!
- @IBOutlet weak var inputBox: NSBox!
- @IBOutlet weak var inputTF: KMTextField!
- @IBOutlet weak var dateLabel: NSTextField!
-
- var textFieldDidEndEditingCallback: ((NSTextField)->Void)?
-
- override func awakeFromNib() {
- super.awakeFromNib()
- bookTitle.isHidden = true
- bookTitle.font = NSFont.SFProTextRegularFont(13.0)
- bookTitle.textColor = KMAppearance.titleColor()
- dateLabel.font = NSFont.SFProTextRegularFont(12)
- dateLabel.textColor = NSColor.km_init(hex: "#757780")
- inputTF.isBordered = false
- inputTF.drawsBackground = false
- inputTF.delegate = self
- inputBox.cornerRadius = 0
- inputTF.isHighlighted = false
-
- inputTF.firstResponderHandler = { [weak self] firstResp in
- if firstResp {
- DispatchQueue.main.async {
- self?.inputBox.borderWidth = 1
- self?.inputBox.borderColor = NSColor.km_init(hex: "#4982E6")
- if KMAppearance.isDarkMode() {
- self?.inputBox.fillColor = .black
- } else {
- self?.inputBox.fillColor = .white
- }
- }
- }
- }
- }
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- }
- }
- extension KMBookCellView: NSTextFieldDelegate {
- func controlTextDidEndEditing(_ obj: Notification) {
- if self.inputTF.isEqual(to: obj.object) {
- self.inputBox.borderWidth = 0
- self.inputBox.fillColor = .clear
-
- self.textFieldDidEndEditingCallback?(self.inputTF)
- }
- }
- }
|