1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-11 17:38:38 +00:00
This commit is contained in:
Serg 2018-05-10 15:41:57 +00:00 committed by GitHub
commit 23b7ebb019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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