123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // ASPropertyCell.swift
- // KdanAuto
- //
- // Created by 朱东勇 on 2023/4/17.
- //
- import Cocoa
- class ASPropertyCell: NSView {
- var m_propertyInfo:NSDictionary? = nil
-
- var m_enabled:Bool = true
-
- var m_valueChange: (_ value:AnyObject, _ object:ASPropertyCell?) -> () = {(value, object) in
-
- }
-
- class func propertyCellFor(_ info:NSDictionary) -> ASPropertyCell? {
- let valueType = info.value(forKey: "ValueType") as! String
-
- var object : ASPropertyCell? = nil;
-
- if (NSArray(array: ["BOOL", "bool"]).contains(valueType)) {
- object = ASBOOLPropertyCell.shared()
- }else if (NSArray(array: ["int",
- "size_t",
- "uint8_t",
- "int16_t",
- "uint16_t",
- "int32_t",
- "uint32_t",
- "int64_t",
- "uint64_t",
- "NSInteger",
- "NSUInteger"]).contains(valueType)) {
- if (info.value(forKey: "Values") == nil){
- object = ASIntPropertyCell.shared()
- }else {
- object = ASSelectPropertyCell.shared()
- }
- }else if (NSArray(array: ["float",
- "double"]).contains(valueType)) {
- if (info.value(forKey: "Values") == nil){
- object = ASFloatPropertyCell.shared()
- }else {
- object = ASSelectPropertyCell.shared()
- }
- }else if (NSArray(array: ["CGSize", "NSSize"]).contains(valueType)) {
- if (info.value(forKey: "Values") == nil){
- object = ASSizePropertyCell.shared()
- }else {
- object = ASSelectPropertyCell.shared()
- }
- }else if (NSArray(array: ["CGRect", "NSRect"]).contains(valueType)) {
- if (info.value(forKey: "Values") == nil){
- object = ASRectPropertyCell.shared()
- }else {
- object = ASSelectPropertyCell.shared()
- }
- }
-
- if (object != nil) {
- object?.setPropertyInfo(info)
- return object
- }
-
- return nil
- }
-
- class func shared() -> ASPropertyCell? {
-
- var objects : NSArray!
-
- Bundle.main.loadNibNamed("ASPropertyCell", owner: nil, topLevelObjects: &objects)
-
- for tView in objects {
- if let tv = tView as? ASPropertyCell {
- return tv
- }
- }
-
- return nil
- }
-
- /// Setter
- func setPropertyInfo(_ info:NSDictionary) {
- m_propertyInfo = info;
- }
-
- func propertyInfo() -> NSDictionary {
- return m_propertyInfo ?? NSDictionary()
- }
-
- func setValue(_ value:AnyObject) {
-
- }
-
- func value() -> AnyObject {
- return NSNumber(value: 0)
- }
-
- func setEnabled(_ enabled:Bool) {
- m_enabled = enabled;
-
- }
-
- func enabled() -> Bool {
- return m_enabled
- }
-
- func setValueChangedCallBack(_ callBack:@escaping (_ value:AnyObject, _ object:ASPropertyCell?) -> ()) {
- m_valueChange = callBack
- }
- }
|