Skip to content

Commit

Permalink
feat: added help button to the Preferences Row
Browse files Browse the repository at this point in the history
  • Loading branch information
exelban committed Sep 12, 2024
1 parent 4b213c4 commit 6fc3b58
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Kit/helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,11 @@ private class PreferencesSeparator: NSView {
}

public class PreferencesRow: NSStackView {
public init(_ title: String? = nil, _ description: String? = nil, id: String? = nil, component: NSView) {
private var helpCallback: (() -> Void)?

public init(_ title: String? = nil, _ description: String? = nil, id: String? = nil, component: NSView, help: (() -> Void)? = nil) {
self.helpCallback = help

super.init(frame: .zero)

self.orientation = .horizontal
Expand All @@ -1345,6 +1349,18 @@ public class PreferencesRow: NSStackView {
}

self.addArrangedSubview(self.text(title, description))
if help != nil {
let helpBtn = NSButton()
helpBtn.bezelStyle = .helpButton
helpBtn.controlSize = .small
helpBtn.title = ""
helpBtn.action = #selector(self.help)
helpBtn.target = self
let space = NSView()
space.widthAnchor.constraint(equalToConstant: 5).isActive = true
self.addArrangedSubview(space)
self.addArrangedSubview(helpBtn)
}
self.addArrangedSubview(NSView())
self.addArrangedSubview(component)
}
Expand Down Expand Up @@ -1382,6 +1398,10 @@ public class PreferencesRow: NSStackView {

return view
}

@objc private func help() {
self.helpCallback?()
}
}

public func restartApp(_ sender: Any, afterDelay seconds: TimeInterval = 0.5) -> Never {
Expand Down

0 comments on commit 6fc3b58

Please sign in to comment.