|
@@ -57,14 +57,13 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
public override func awakeFromNib() {
|
|
|
super.awakeFromNib()
|
|
|
|
|
|
- self.inputField.componentDelegate = self
|
|
|
- self.inputField.focusRingType = .none
|
|
|
+ inputField.componentDelegate = self
|
|
|
+ inputField.focusRingType = .none
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidBeginEditingNotification(_:)), name: NSControl.textDidBeginEditingNotification, object: inputField)
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChangeNotification(_:)), name: NSControl.textDidChangeNotification, object: inputField)
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidEndEditingNotification(_:)), name: NSControl.textDidEndEditingNotification, object: inputField)
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//Setter
|
|
@@ -77,9 +76,9 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
|
|
|
ComponentLibrary.shared.configSelectComponent(properties: _properties)
|
|
|
|
|
|
- self.reloadData()
|
|
|
+ reloadData()
|
|
|
|
|
|
- self.window?.makeFirstResponder(nil)
|
|
|
+ window?.makeFirstResponder(nil)
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -87,13 +86,13 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
//MARK: - Public
|
|
|
public func reloadData() {
|
|
|
|
|
|
- self.setupUI()
|
|
|
+ setupUI()
|
|
|
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
}
|
|
|
|
|
|
public func updateMenuItemsArr(_ propertys: [ComponentMenuitemProperty]) {
|
|
|
- self.menuitemPropertys = propertys
|
|
|
+ menuitemPropertys = propertys
|
|
|
|
|
|
}
|
|
|
|
|
@@ -101,10 +100,10 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
if index >= 0 && index < menuitemPropertys.count {
|
|
|
let chooseIndex: Int = index
|
|
|
let chooseProperty = menuitemPropertys[chooseIndex]
|
|
|
- self.inputField.stringValue = chooseProperty.text
|
|
|
- self.properties.state = .normal
|
|
|
- self.refreshUI()
|
|
|
- self.selItemProperty = chooseProperty
|
|
|
+ inputField.stringValue = chooseProperty.text
|
|
|
+ properties.state = .normal
|
|
|
+ refreshUI()
|
|
|
+ selItemProperty = chooseProperty
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -119,99 +118,99 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
|
|
|
//MARK: - SetupUI
|
|
|
func setupUI() {
|
|
|
- if self.properties.showLeftIcon == true {
|
|
|
- self.leftIconImage.isHidden = false
|
|
|
- self.leftIconWidthConst.constant = self.properties.propertyInfo.leftIconWidth ?? 16
|
|
|
+ if properties.showLeftIcon == true {
|
|
|
+ leftIconImage.isHidden = false
|
|
|
+ leftIconWidthConst.constant = properties.propertyInfo.leftIconWidth ?? 16
|
|
|
|
|
|
- self.fieldLeftConst.constant = self.leftIconWidthConst.constant + 12
|
|
|
+ fieldLeftConst.constant = leftIconWidthConst.constant + 12
|
|
|
} else {
|
|
|
- self.leftIconImage.isHidden = true
|
|
|
- self.fieldLeftConst.constant = 8
|
|
|
+ leftIconImage.isHidden = true
|
|
|
+ fieldLeftConst.constant = 8
|
|
|
}
|
|
|
|
|
|
- if self.properties.isError == true {
|
|
|
- self.contendBoxBottomConst.constant = 18
|
|
|
- self.errorTipLabel.isHidden = false
|
|
|
+ if properties.isError == true {
|
|
|
+ contendBoxBottomConst.constant = 18
|
|
|
+ errorTipLabel.isHidden = false
|
|
|
} else {
|
|
|
- self.contendBoxBottomConst.constant = 0
|
|
|
- self.errorTipLabel.isHidden = true
|
|
|
+ contendBoxBottomConst.constant = 0
|
|
|
+ errorTipLabel.isHidden = true
|
|
|
}
|
|
|
|
|
|
- if self.properties.isDisabled == false {
|
|
|
- self.inputField.isEditable = true
|
|
|
- if self.properties.creatable == false {
|
|
|
- self.inputField.isEditable = false
|
|
|
+ if properties.isDisabled == false {
|
|
|
+ inputField.isEditable = true
|
|
|
+ if properties.creatable == false {
|
|
|
+ inputField.isEditable = false
|
|
|
}
|
|
|
} else {
|
|
|
- self.inputField.isEditable = false
|
|
|
+ inputField.isEditable = false
|
|
|
}
|
|
|
- self.inputField.font = self.properties.propertyInfo.textFont
|
|
|
- self.inputField.stringValue = properties.text ?? ""
|
|
|
+ inputField.font = properties.propertyInfo.textFont
|
|
|
+ inputField.stringValue = properties.text ?? ""
|
|
|
|
|
|
- if let chooseProperty = self.selItemProperty {
|
|
|
- self.inputField.stringValue = chooseProperty.text
|
|
|
+ if let chooseProperty = selItemProperty {
|
|
|
+ inputField.stringValue = chooseProperty.text
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
func refreshUI() {
|
|
|
|
|
|
- self.contendBox.cornerRadius = self.properties.propertyInfo.cornerRadius
|
|
|
- self.contendBox.borderWidth = self.properties.propertyInfo.borderWidth
|
|
|
+ contendBox.cornerRadius = properties.propertyInfo.cornerRadius
|
|
|
+ contendBox.borderWidth = properties.propertyInfo.borderWidth
|
|
|
|
|
|
var fillColor: NSColor?
|
|
|
var borderColor: NSColor?
|
|
|
- if self.properties.state == .normal {
|
|
|
- fillColor = self.properties.propertyInfo.color_nor
|
|
|
- borderColor = self.properties.propertyInfo.borderColor_nor
|
|
|
+ if properties.state == .normal {
|
|
|
+ fillColor = properties.propertyInfo.color_nor
|
|
|
+ borderColor = properties.propertyInfo.borderColor_nor
|
|
|
|
|
|
- } else if self.properties.state == .hover {
|
|
|
- fillColor = self.properties.propertyInfo.color_hov
|
|
|
- if self.properties.isError == true {
|
|
|
- fillColor = self.properties.propertyInfo.color_error_hov
|
|
|
+ } else if properties.state == .hover {
|
|
|
+ fillColor = properties.propertyInfo.color_hov
|
|
|
+ if properties.isError == true {
|
|
|
+ fillColor = properties.propertyInfo.color_error_hov
|
|
|
}
|
|
|
- borderColor = self.properties.propertyInfo.borderColor_hov
|
|
|
+ borderColor = properties.propertyInfo.borderColor_hov
|
|
|
|
|
|
- } else if self.properties.state == .pressed {
|
|
|
- fillColor = self.properties.propertyInfo.color_active
|
|
|
- borderColor = self.properties.propertyInfo.borderColor_active
|
|
|
+ } else if properties.state == .pressed {
|
|
|
+ fillColor = properties.propertyInfo.color_active
|
|
|
+ borderColor = properties.propertyInfo.borderColor_active
|
|
|
|
|
|
}
|
|
|
|
|
|
var textColor: NSColor = properties.propertyInfo.textColor
|
|
|
- if self.properties.isDisabled == true {
|
|
|
- fillColor = self.properties.propertyInfo.color_dis
|
|
|
- borderColor = self.properties.propertyInfo.borderColor_dis
|
|
|
+ if properties.isDisabled == true {
|
|
|
+ fillColor = properties.propertyInfo.color_dis
|
|
|
+ borderColor = properties.propertyInfo.borderColor_dis
|
|
|
textColor = properties.propertyInfo.textColor_dis
|
|
|
}
|
|
|
|
|
|
- if self.properties.isError == true {
|
|
|
- borderColor = self.properties.propertyInfo.borderColor_error
|
|
|
+ if properties.isError == true {
|
|
|
+ borderColor = properties.propertyInfo.borderColor_error
|
|
|
}
|
|
|
|
|
|
if let color = fillColor {
|
|
|
- self.contendBox.fillColor = color
|
|
|
+ contendBox.fillColor = color
|
|
|
}
|
|
|
|
|
|
if let color = borderColor {
|
|
|
- self.contendBox.borderColor = color
|
|
|
+ contendBox.borderColor = color
|
|
|
}
|
|
|
|
|
|
if let placeholder = properties.placeholder {
|
|
|
- self.inputField.placeholderString = placeholder
|
|
|
+ inputField.placeholderString = placeholder
|
|
|
}
|
|
|
- self.inputField.textColor = textColor
|
|
|
+ inputField.textColor = textColor
|
|
|
|
|
|
- self.rightIconImage.image = ComponentLibrary.shared.image(forResource: "suffix")
|
|
|
+ rightIconImage.image = ComponentLibrary.shared.image(forResource: "suffix")
|
|
|
if properties.isDisabled {
|
|
|
rightIconImage.image = ComponentLibrary.shared.image(forResource: "suffix_dis")
|
|
|
}
|
|
|
|
|
|
- self.errorTipLabel.textColor = self.properties.propertyInfo.errorTipTextColor
|
|
|
+ errorTipLabel.textColor = properties.propertyInfo.errorTipTextColor
|
|
|
|
|
|
- self.errorTipLabel.font = self.properties.propertyInfo.errorTipTextFont
|
|
|
+ errorTipLabel.font = properties.propertyInfo.errorTipTextFont
|
|
|
if let errorText = properties.errorText {
|
|
|
- self.errorTipLabel.stringValue = errorText
|
|
|
+ errorTipLabel.stringValue = errorText
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -222,7 +221,7 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
}
|
|
|
|
|
|
var viewHeight: CGFloat = 8.0
|
|
|
- for item in self.menuitemPropertys {
|
|
|
+ for item in menuitemPropertys {
|
|
|
item.state = .normal
|
|
|
item.itemSelected = false
|
|
|
if item == selItemProperty {
|
|
@@ -243,13 +242,13 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
groupView.groupDelegate = self
|
|
|
groupView.show(relativeTo: self)
|
|
|
groupView?.updateGroupInfo(menuitemPropertys)
|
|
|
- self.isGroupViewShow = true
|
|
|
+ isGroupViewShow = true
|
|
|
}
|
|
|
|
|
|
func hideGroupView() {
|
|
|
- self.groupView?.removeGroupView()
|
|
|
+ groupView?.removeGroupView()
|
|
|
|
|
|
- self.isGroupViewShow = false
|
|
|
+ isGroupViewShow = false
|
|
|
}
|
|
|
|
|
|
//MARK: - TextNotification
|
|
@@ -258,7 +257,7 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
}
|
|
|
|
|
|
@objc func textFieldDidChangeNotification(_ notification: Notification) {
|
|
|
- self.selItemProperty = nil
|
|
|
+ selItemProperty = nil
|
|
|
|
|
|
}
|
|
|
|
|
@@ -270,12 +269,12 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
public override func mouseEntered(with event: NSEvent) {
|
|
|
super.mouseEntered(with: event)
|
|
|
|
|
|
- if self.properties.isDisabled == false &&
|
|
|
- self.inputField.isResponder == false &&
|
|
|
- self.isGroupViewShow == false {
|
|
|
- self.properties.state = .hover
|
|
|
+ if properties.isDisabled == false &&
|
|
|
+ inputField.isResponder == false &&
|
|
|
+ isGroupViewShow == false {
|
|
|
+ properties.state = .hover
|
|
|
}
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
}
|
|
|
|
|
|
public override func mouseMoved(with event: NSEvent) {
|
|
@@ -286,13 +285,13 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
public override func mouseExited(with event: NSEvent) {
|
|
|
super.mouseExited(with: event)
|
|
|
|
|
|
- if self.properties.isDisabled == false &&
|
|
|
- self.inputField.isResponder == false &&
|
|
|
- self.isGroupViewShow == false {
|
|
|
- self.properties.state = .normal
|
|
|
+ if properties.isDisabled == false &&
|
|
|
+ inputField.isResponder == false &&
|
|
|
+ isGroupViewShow == false {
|
|
|
+ properties.state = .normal
|
|
|
}
|
|
|
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
}
|
|
|
|
|
|
public override func mouseDown(with event: NSEvent) {
|
|
@@ -303,24 +302,24 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
public override func mouseUp(with event: NSEvent) {
|
|
|
super.mouseUp(with: event)
|
|
|
|
|
|
- if self.properties.isDisabled == false {
|
|
|
+ if properties.isDisabled == false {
|
|
|
let point = convert(event.locationInWindow, from: nil)
|
|
|
- if CGRectContainsPoint(self.rightIconImage.frame, point) {
|
|
|
- self.properties.state = .pressed
|
|
|
+ if CGRectContainsPoint(rightIconImage.frame, point) {
|
|
|
+ properties.state = .pressed
|
|
|
|
|
|
- self.showGroupView()
|
|
|
+ showGroupView()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- if self.properties.isDisabled == false &&
|
|
|
- self.inputField.isResponder == false &&
|
|
|
- self.isGroupViewShow == false {
|
|
|
- self.properties.state = .normal
|
|
|
+ if properties.isDisabled == false &&
|
|
|
+ inputField.isResponder == false &&
|
|
|
+ isGroupViewShow == false {
|
|
|
+ properties.state = .normal
|
|
|
|
|
|
}
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -328,16 +327,18 @@ public class ComponentSelect: ComponentBaseXibView {
|
|
|
extension ComponentSelect: ComponentTextFieldDelegate {
|
|
|
|
|
|
func componentTextFieldDidResponderChanged(textField: NSTextField) {
|
|
|
- if self.properties.isDisabled == false {
|
|
|
- if self.inputField.isResponder {
|
|
|
- self.properties.state = .pressed
|
|
|
+ if properties.isDisabled == false {
|
|
|
+ if inputField.isResponder {
|
|
|
+ properties.state = .pressed
|
|
|
|
|
|
- self.showGroupView()
|
|
|
+ if properties.autoShowPopupView == true {
|
|
|
+ showGroupView()
|
|
|
+ }
|
|
|
} else {
|
|
|
- self.properties.state = .normal
|
|
|
+ properties.state = .normal
|
|
|
}
|
|
|
}
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
|
|
|
|
|
|
}
|
|
@@ -345,25 +346,25 @@ extension ComponentSelect: ComponentTextFieldDelegate {
|
|
|
|
|
|
extension ComponentSelect: ComponentGroupDelegate {
|
|
|
public func componentGroupDidDismiss(group: ComponentGroup?) {
|
|
|
- self.properties.state = .normal
|
|
|
- self.isGroupViewShow = false
|
|
|
+ properties.state = .normal
|
|
|
+ isGroupViewShow = false
|
|
|
|
|
|
- self.window?.makeFirstResponder(nil)
|
|
|
+ window?.makeFirstResponder(nil)
|
|
|
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
}
|
|
|
|
|
|
public func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
|
|
|
- self.inputField.stringValue = menuItemProperty?.text ?? ""
|
|
|
+ inputField.stringValue = menuItemProperty?.text ?? ""
|
|
|
|
|
|
- self.properties.state = .normal
|
|
|
+ properties.state = .normal
|
|
|
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
|
|
|
- self.selItemProperty = menuItemProperty
|
|
|
+ selItemProperty = menuItemProperty
|
|
|
|
|
|
- self.delegate?.componentSelectDidSelect?(view: self, menuItemProperty: menuItemProperty)
|
|
|
+ delegate?.componentSelectDidSelect?(view: self, menuItemProperty: menuItemProperty)
|
|
|
|
|
|
- self.window?.makeFirstResponder(nil)
|
|
|
+ window?.makeFirstResponder(nil)
|
|
|
}
|
|
|
}
|