ASBOOLPropertyCell.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // ASIntPropertyCell.swift
  3. // KdanAuto
  4. //
  5. // Created by 朱东勇 on 2023/4/17.
  6. //
  7. import Cocoa
  8. class ASBOOLPropertyCell: ASPropertyCell {
  9. @IBOutlet var m_checkBtn:NSButton!
  10. override class func shared() -> ASPropertyCell? {
  11. var objects : NSArray!
  12. Bundle.main.loadNibNamed("ASBOOLPropertyCell", owner: nil, topLevelObjects: &objects)
  13. for tView in objects {
  14. if let tv = tView as? ASBOOLPropertyCell {
  15. return tv
  16. }
  17. }
  18. return nil
  19. }
  20. /// Setter
  21. override func setPropertyInfo(_ info:NSDictionary) {
  22. super.setPropertyInfo(info)
  23. self.m_checkBtn.title = "\(info.value(forKey: "Name") ?? ""):"
  24. setValue((info.value(forKey: "DefaultValue") ?? "0") as AnyObject)
  25. }
  26. override func setValue(_ value:AnyObject) {
  27. super.setValue(value)
  28. if (value as? NSNumber)?.boolValue == true {
  29. self.m_checkBtn.state = .on
  30. }else {
  31. self.m_checkBtn.state = .off
  32. }
  33. }
  34. override func value() -> AnyObject {
  35. if (m_checkBtn.state == .on) {
  36. return NSNumber(booleanLiteral: true)
  37. }
  38. return NSNumber(booleanLiteral: false)
  39. }
  40. override func setEnabled(_ enabled:Bool) {
  41. super.setEnabled(enabled)
  42. self.alphaValue = enabled ? 1 : 0.8
  43. self.m_checkBtn.isEnabled = enabled;
  44. }
  45. ///IBAction
  46. @IBAction func valueChanged(_ sender:NSButton) {
  47. m_valueChange(self.value(), self)
  48. }
  49. }