1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // ASIntPropertyCell.swift
- // KdanAuto
- //
- // Created by 朱东勇 on 2023/4/17.
- //
- import Cocoa
- class ASSelectPropertyCell: ASPropertyCell {
- @IBOutlet var m_titleLbl:NSTextField!
- @IBOutlet var m_comboBox:NSComboBox!
- override class func shared() -> ASPropertyCell? {
- var objects : NSArray!
-
- Bundle.main.loadNibNamed("ASSelectPropertyCell", owner: nil, topLevelObjects: &objects)
-
- for tView in objects {
- if let tv = tView as? ASSelectPropertyCell {
- return tv
- }
- }
-
- return nil
- }
-
-
- /// Setter
- override func setPropertyInfo(_ info:NSDictionary) {
- super.setPropertyInfo(info)
-
- loadComboxItem()
-
- self.m_titleLbl.stringValue = "\(info.value(forKey: "Name") ?? ""):"
- setValue((info.value(forKey: "DefaultValue") ?? "0") as AnyObject)
- }
-
- override func setValue(_ value:AnyObject) {
- super.setValue(value)
-
- let values = self.m_propertyInfo?.value(forKey: "Values") as? [NSDictionary]
- if (values != nil) {
- for tValue in values! {
- if ((tValue.value(forKey: "Value") as! AnyObject).isEqual(to: value)) {
- let index = values!.firstIndex(of: tValue) ?? 0
-
- if (index != NSNotFound) {
- self.m_comboBox.selectItem(at: index);
- }
- }
- }
- }
- }
-
- override func value() -> AnyObject {
- let index = self.m_comboBox.indexOfSelectedItem
-
- let values = self.m_propertyInfo?.value(forKey: "Values") as! [NSDictionary]
-
- if (values.count > index) {
- return ((values[index] as NSDictionary).value(forKey: "Value") as? AnyObject) ?? NSNumber(value: 0)
- }
- return NSNumber(value: 0)
- }
-
- override func setEnabled(_ enabled:Bool) {
- super.setEnabled(enabled)
-
- self.alphaValue = enabled ? 1 : 0.6
- self.m_comboBox.isEnabled = enabled;
- }
-
-
- /// load Items
- func loadComboxItem() {
- m_comboBox.removeAllItems()
-
- let values = self.m_propertyInfo?.value(forKey: "Values") as! [NSDictionary]
- for value in values {
- m_comboBox.addItem(withObjectValue: value.value(forKey: "Name"))
- }
- }
-
-
- }
|