From 961d11a49a7d8fa1dfe26d4ceb9a04b2324dc6b1 Mon Sep 17 00:00:00 2001 From: Serg Date: Thu, 10 May 2018 22:38:23 +0700 Subject: [PATCH 1/2] fix button titles misbehaviour --- MTMR/CustomButtonTouchBarItem.swift | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/MTMR/CustomButtonTouchBarItem.swift b/MTMR/CustomButtonTouchBarItem.swift index 5848892..e24bf4f 100644 --- a/MTMR/CustomButtonTouchBarItem.swift +++ b/MTMR/CustomButtonTouchBarItem.swift @@ -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 { From 20dd3374935c78cf433e8832a1144660bcf2bd44 Mon Sep 17 00:00:00 2001 From: Serg Date: Thu, 10 May 2018 22:41:44 +0700 Subject: [PATCH 2/2] and fix empty keyboard layout widget too --- MTMR/CustomButtonTouchBarItem.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MTMR/CustomButtonTouchBarItem.swift b/MTMR/CustomButtonTouchBarItem.swift index e24bf4f..af229d1 100644 --- a/MTMR/CustomButtonTouchBarItem.swift +++ b/MTMR/CustomButtonTouchBarItem.swift @@ -55,6 +55,7 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat private func reinstallButton() { let title = button.attributedTitle + let image = button.image let cell = CustomButtonCell() button.cell = cell if let color = backgroundColor { @@ -66,6 +67,7 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat button.bezelStyle = isBordered ? .rounded : .inline } button.attributedTitle = title + button.image = image self.view = button }