|
@@ -13,7 +13,10 @@ class KMSecureEncryptPasswordCellView: NSTableCellView {
|
|
private var passwordView: KMSecureTextFiled = KMSecureTextFiled()
|
|
private var passwordView: KMSecureTextFiled = KMSecureTextFiled()
|
|
private var openOrClosePasswordButton: NSButton?
|
|
private var openOrClosePasswordButton: NSButton?
|
|
|
|
|
|
|
|
+ private var hover = KMCoverButton()
|
|
|
|
+
|
|
var kmEnabled = false
|
|
var kmEnabled = false
|
|
|
|
+ private var isFocus = false
|
|
|
|
|
|
var itemClick: KMItemClickBlock<KMSecureEncryptPasswordCellView>?
|
|
var itemClick: KMItemClickBlock<KMSecureEncryptPasswordCellView>?
|
|
var valueChange: KMValueDidChangeBlock?
|
|
var valueChange: KMValueDidChangeBlock?
|
|
@@ -42,14 +45,31 @@ class KMSecureEncryptPasswordCellView: NSTableCellView {
|
|
self.addSubview(self.checkBox)
|
|
self.addSubview(self.checkBox)
|
|
self.addSubview(self.passwordView)
|
|
self.addSubview(self.passwordView)
|
|
|
|
|
|
|
|
+ self.hover.isBordered = false
|
|
|
|
+ self.hover.title = ""
|
|
|
|
+ self.hover.wantsLayer = true
|
|
|
|
+ self.hover.layer?.backgroundColor = .clear
|
|
|
|
+ self.addSubview(self.hover, positioned: .below, relativeTo: self.passwordView)
|
|
|
|
+ self.hover.coverAction = { [unowned self] _, action in
|
|
|
|
+ if (!self.passwordViewCanHover()) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (action == .enter) {
|
|
|
|
+ self.refreshPasswordView(state: .Hov)
|
|
|
|
+ } else if (action == .exit) {
|
|
|
|
+ self.refreshPasswordView(state: .Norm)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
self.checkBox.target = self
|
|
self.checkBox.target = self
|
|
self.checkBox.action = #selector(checkBoxAction)
|
|
self.checkBox.action = #selector(checkBoxAction)
|
|
|
|
|
|
self.passwordView.backgroundView.wantsLayer = true
|
|
self.passwordView.backgroundView.wantsLayer = true
|
|
self.passwordView.backgroundView.layer?.borderWidth = 1
|
|
self.passwordView.backgroundView.layer?.borderWidth = 1
|
|
- self.passwordView.backgroundView.layer?.borderColor = NSColor(hex: "#DFE1E5").cgColor
|
|
|
|
self.passwordView.backgroundView.layer?.cornerRadius = 4
|
|
self.passwordView.backgroundView.layer?.cornerRadius = 4
|
|
self.passwordView.kmEnabled = false
|
|
self.passwordView.kmEnabled = false
|
|
|
|
+ self.isFocus = false
|
|
|
|
+ self.refreshPasswordView(state: .Norm)
|
|
|
|
|
|
let rightView = NSView()
|
|
let rightView = NSView()
|
|
rightView.frame = NSMakeRect(0, 0, 32, 32);
|
|
rightView.frame = NSMakeRect(0, 0, 32, 32);
|
|
@@ -67,6 +87,9 @@ class KMSecureEncryptPasswordCellView: NSTableCellView {
|
|
self.openOrClosePasswordButton = openPasswordButton
|
|
self.openOrClosePasswordButton = openPasswordButton
|
|
|
|
|
|
self.passwordView.valueDidChange = { [unowned self] string in
|
|
self.passwordView.valueDidChange = { [unowned self] string in
|
|
|
|
+ self.isFocus = true
|
|
|
|
+ self.refreshPasswordView(state: .Focus)
|
|
|
|
+
|
|
guard let callback = self.valueChange else {
|
|
guard let callback = self.valueChange else {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -75,9 +98,13 @@ class KMSecureEncryptPasswordCellView: NSTableCellView {
|
|
callback(string, nil)
|
|
callback(string, nil)
|
|
}
|
|
}
|
|
self.passwordView.becomeFirstResponderHandler = { [unowned self] result in
|
|
self.passwordView.becomeFirstResponderHandler = { [unowned self] result in
|
|
|
|
+ self.isFocus = true
|
|
|
|
+ self.refreshPasswordView(state: .Focus)
|
|
self.updatePasswordViewRightViewState()
|
|
self.updatePasswordViewRightViewState()
|
|
}
|
|
}
|
|
self.passwordView.didEndEditHandler = { [unowned self] _ in
|
|
self.passwordView.didEndEditHandler = { [unowned self] _ in
|
|
|
|
+ self.isFocus = false
|
|
|
|
+ self.refreshPasswordView(state: .Norm)
|
|
self.updatePasswordViewRightViewState()
|
|
self.updatePasswordViewRightViewState()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -90,6 +117,8 @@ class KMSecureEncryptPasswordCellView: NSTableCellView {
|
|
|
|
|
|
let passwordY: CGFloat = self.checkBox.frame.maxY + 8
|
|
let passwordY: CGFloat = self.checkBox.frame.maxY + 8
|
|
self.passwordView.frame = NSMakeRect(8, passwordY, width-8-8, 32)
|
|
self.passwordView.frame = NSMakeRect(8, passwordY, width-8-8, 32)
|
|
|
|
+
|
|
|
|
+ self.hover.frame = self.passwordView.frame
|
|
}
|
|
}
|
|
|
|
|
|
@objc func checkBoxAction(sender: NSButton) {
|
|
@objc func checkBoxAction(sender: NSButton) {
|
|
@@ -98,17 +127,11 @@ class KMSecureEncryptPasswordCellView: NSTableCellView {
|
|
self.kmEnabled = true
|
|
self.kmEnabled = true
|
|
self.openOrClosePasswordButton?.isEnabled = true
|
|
self.openOrClosePasswordButton?.isEnabled = true
|
|
|
|
|
|
- self.passwordView.backgroundView.wantsLayer = true
|
|
|
|
- self.passwordView.backgroundView.layer?.borderColor = NSColor(hex: "#DFE1E5").cgColor
|
|
|
|
-
|
|
|
|
let _ = self.passwordView.becomeFirstResponder()
|
|
let _ = self.passwordView.becomeFirstResponder()
|
|
} else {
|
|
} else {
|
|
self.passwordView.kmEnabled = false
|
|
self.passwordView.kmEnabled = false
|
|
self.kmEnabled = false
|
|
self.kmEnabled = false
|
|
self.openOrClosePasswordButton?.isEnabled = false
|
|
self.openOrClosePasswordButton?.isEnabled = false
|
|
-
|
|
|
|
- self.passwordView.backgroundView.wantsLayer = true
|
|
|
|
- self.passwordView.backgroundView.layer?.borderColor = NSColor(hex: "#DFE1E5").cgColor
|
|
|
|
}
|
|
}
|
|
|
|
|
|
self.updatePasswordViewRightViewState()
|
|
self.updatePasswordViewRightViewState()
|
|
@@ -136,4 +159,24 @@ class KMSecureEncryptPasswordCellView: NSTableCellView {
|
|
self.passwordView.rightView?.isHidden = false
|
|
self.passwordView.rightView?.isHidden = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private func passwordViewCanHover() -> Bool {
|
|
|
|
+ if (!self.passwordView.kmEnabled) {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ if (self.isFocus) {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private func refreshPasswordView(state: KMDesignTokenState) {
|
|
|
|
+ if (state == .Focus) {
|
|
|
|
+ self.passwordView.backgroundView.layer?.borderColor = NSColor(hex: "#1770F4").cgColor
|
|
|
|
+ } else if (state == .Norm) {
|
|
|
|
+ self.passwordView.backgroundView.layer?.borderColor = NSColor(hex: "#DFE1E5").cgColor
|
|
|
|
+ } else if (state == .Hov) {
|
|
|
|
+ self.passwordView.backgroundView.layer?.borderColor = NSColor(hex: "#68ACF8").cgColor
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|