1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 20:10:08 +02:00
Files
app/phpmon/Common/Helpers/Alert.swift
2023-01-19 18:09:42 +01:00

41 lines
1.1 KiB
Swift

//
// Alert.swift
// PHP Monitor
//
// Copyright © 2023 Nico Verbruggen. All rights reserved.
//
import Cocoa
class Alert {
public static func confirm(
onWindow window: NSWindow,
messageText: String,
informativeText: String,
buttonTitle: String = "generic.ok".localized,
secondButtonTitle: String = "generic.cancel".localized,
style: NSAlert.Style = .warning,
onFirstButtonPressed: @escaping (() -> Void)
) {
if !Thread.isMainThread {
fatalError("You should always present alerts on the main thread!")
}
let alert = NSAlert.init()
alert.alertStyle = style
alert.messageText = messageText
alert.informativeText = informativeText
alert.addButton(withTitle: buttonTitle)
if !secondButtonTitle.isEmpty {
alert.addButton(withTitle: secondButtonTitle)
}
alert.beginSheetModal(for: window) { response in
if response == .alertFirstButtonReturn {
onFirstButtonPressed()
}
}
}
}