fix: fixed popup view behavior when pinned. Now a pinned popup will not close if click on the settings window. Additionally fixed bug when popup view does not hide if previously was pinned and closed.

This commit is contained in:
Serhiy Mytrovtsiy
2021-07-31 15:39:46 +02:00
parent 120b8c7b2a
commit d499b9d020
2 changed files with 14 additions and 7 deletions

View File

@@ -21,7 +21,6 @@ internal class PopupWindow: NSWindow, NSWindowDelegate {
init(title: String, view: Popup_p?, visibilityCallback: @escaping (_ state: Bool) -> Void) {
self.viewController.setup(title: title, view: view)
self.viewController.visibilityCallback = visibilityCallback
super.init(
contentRect: NSRect(
@@ -35,6 +34,11 @@ internal class PopupWindow: NSWindow, NSWindowDelegate {
defer: true
)
self.viewController.visibilityCallback = { [weak self] state in
self?.locked = false
visibilityCallback(state)
}
self.contentViewController = self.viewController
self.titlebarAppearsTransparent = true
self.animationBehavior = .default
@@ -315,11 +319,6 @@ internal class HeaderView: NSStackView {
@objc func openActivityMonitor(_ sender: Any) {
self.window?.setIsVisible(false)
if self.isCloseAction {
self.setCloseButton(false)
return
}
NSWorkspace.shared.launchApplication(
withBundleIdentifier: "com.apple.ActivityMonitor",
options: [.default],
@@ -333,14 +332,22 @@ internal class HeaderView: NSStackView {
NotificationCenter.default.post(name: .toggleSettings, object: nil, userInfo: ["module": self.title])
}
@objc private func closePopup() {
self.window?.setIsVisible(false)
self.setCloseButton(false)
return
}
public func setCloseButton(_ state: Bool) {
if state && !self.isCloseAction {
self.activityButton?.image = Bundle(for: type(of: self)).image(forResource: "close")!
self.activityButton?.toolTip = localizedString("Close popup")
self.activityButton?.action = #selector(self.closePopup)
self.isCloseAction = true
} else if !state && self.isCloseAction {
self.activityButton?.image = Bundle(for: type(of: self)).image(forResource: "chart")!
self.activityButton?.toolTip = localizedString("Open Activity Monitor")
self.activityButton?.action = #selector(self.openActivityMonitor)
self.isCloseAction = false
}
}