ASPropertyCell.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // ASPropertyCell.swift
  3. // KdanAuto
  4. //
  5. // Created by 朱东勇 on 2023/4/17.
  6. //
  7. import Cocoa
  8. class ASPropertyCell: NSView {
  9. var m_propertyInfo:NSDictionary? = nil
  10. var m_enabled:Bool = true
  11. var m_valueChange: (_ value:AnyObject, _ object:ASPropertyCell?) -> () = {(value, object) in
  12. }
  13. class func propertyCellFor(_ info:NSDictionary) -> ASPropertyCell? {
  14. let valueType = info.value(forKey: "ValueType") as! String
  15. var object : ASPropertyCell? = nil;
  16. if (NSArray(array: ["BOOL", "bool"]).contains(valueType)) {
  17. object = ASBOOLPropertyCell.shared()
  18. }else if (NSArray(array: ["int",
  19. "size_t",
  20. "uint8_t",
  21. "int16_t",
  22. "uint16_t",
  23. "int32_t",
  24. "uint32_t",
  25. "int64_t",
  26. "uint64_t",
  27. "NSInteger",
  28. "NSUInteger"]).contains(valueType)) {
  29. if (info.value(forKey: "Values") == nil){
  30. object = ASIntPropertyCell.shared()
  31. }else {
  32. object = ASSelectPropertyCell.shared()
  33. }
  34. }else if (NSArray(array: ["float",
  35. "double"]).contains(valueType)) {
  36. if (info.value(forKey: "Values") == nil){
  37. object = ASFloatPropertyCell.shared()
  38. }else {
  39. object = ASSelectPropertyCell.shared()
  40. }
  41. }else if (NSArray(array: ["CGSize", "NSSize"]).contains(valueType)) {
  42. if (info.value(forKey: "Values") == nil){
  43. object = ASSizePropertyCell.shared()
  44. }else {
  45. object = ASSelectPropertyCell.shared()
  46. }
  47. }else if (NSArray(array: ["CGRect", "NSRect"]).contains(valueType)) {
  48. if (info.value(forKey: "Values") == nil){
  49. object = ASRectPropertyCell.shared()
  50. }else {
  51. object = ASSelectPropertyCell.shared()
  52. }
  53. }
  54. if (object != nil) {
  55. object?.setPropertyInfo(info)
  56. return object
  57. }
  58. return nil
  59. }
  60. class func shared() -> ASPropertyCell? {
  61. var objects : NSArray!
  62. Bundle.main.loadNibNamed("ASPropertyCell", owner: nil, topLevelObjects: &objects)
  63. for tView in objects {
  64. if let tv = tView as? ASPropertyCell {
  65. return tv
  66. }
  67. }
  68. return nil
  69. }
  70. /// Setter
  71. func setPropertyInfo(_ info:NSDictionary) {
  72. m_propertyInfo = info;
  73. }
  74. func propertyInfo() -> NSDictionary {
  75. return m_propertyInfo ?? NSDictionary()
  76. }
  77. func setValue(_ value:AnyObject) {
  78. }
  79. func value() -> AnyObject {
  80. return NSNumber(value: 0)
  81. }
  82. func setEnabled(_ enabled:Bool) {
  83. m_enabled = enabled;
  84. }
  85. func enabled() -> Bool {
  86. return m_enabled
  87. }
  88. func setValueChangedCallBack(_ callBack:@escaping (_ value:AnyObject, _ object:ASPropertyCell?) -> ()) {
  89. m_valueChange = callBack
  90. }
  91. }