1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-11 09:28:38 +00:00

fix button titles misbehaviour

This commit is contained in:
Serg 2018-05-10 22:38:23 +07:00
parent 9e10b2d3d1
commit 961d11a49a

View File

@ -21,16 +21,20 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
self.longTapClosure = callbackLong
super.init(identifier: identifier)
button = CustomHeightButton(title: title, target: nil, action: nil)
longClick = NSPressGestureRecognizer(target: self, action: #selector(handleGestureLong))
longClick.allowedTouchTypes = .direct
longClick.delegate = self
self.view.addGestureRecognizer(longClick)
singleClick = NSClickGestureRecognizer(target: self, action: #selector(handleGestureSingle))
singleClick.allowedTouchTypes = .direct
singleClick.delegate = self
self.view.addGestureRecognizer(singleClick)
installButton(titled: title, bordered: true, backgroundColor: nil)
reinstallButton()
button.title = title
}
required init?(coder: NSCoder) {
@ -39,18 +43,18 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
var isBordered: Bool = true {
didSet {
installButton(titled: self.button.title, bordered: isBordered, backgroundColor: backgroundColor)
reinstallButton()
}
}
var backgroundColor: NSColor? {
didSet {
installButton(titled: self.button.title, bordered: isBordered, backgroundColor: backgroundColor)
reinstallButton()
}
}
private func installButton(titled title: String, bordered: Bool, backgroundColor: NSColor?) {
button = CustomHeightButton(title: title, target: nil, action: nil)
private func reinstallButton() {
let title = button.attributedTitle
let cell = CustomButtonCell()
button.cell = cell
if let color = backgroundColor {
@ -58,14 +62,11 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
button.bezelColor = color
cell.backgroundColor = color
} else {
button.isBordered = bordered
button.bezelStyle = bordered ? .rounded : .inline
button.isBordered = isBordered
button.bezelStyle = isBordered ? .rounded : .inline
}
button.title = title
button.attributedTitle = title
self.view = button
self.view.addGestureRecognizer(longClick)
self.view.addGestureRecognizer(singleClick)
}
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: NSGestureRecognizer) -> Bool {