macos: if alert is already showing, don't check if need confirm

This commit is contained in:
Mitchell Hashimoto
2023-10-31 09:41:40 -07:00
parent 6a024897a6
commit 60e1ca81f0

View File

@ -114,31 +114,32 @@ class TerminalController: NSWindowController, NSWindowDelegate, TerminalViewDele
// If we have no surfaces, close. // If we have no surfaces, close.
guard let node = self.surfaceTree else { return true } guard let node = self.surfaceTree else { return true }
// If we already have an alert, continue with it
guard alert == nil else { return false }
// If our surfaces don't require confirmation, close. // If our surfaces don't require confirmation, close.
if (!node.needsConfirmQuit()) { return true } if (!node.needsConfirmQuit()) { return true }
// We require confirmation, so show an alert as long as we aren't already. // We require confirmation, so show an alert as long as we aren't already.
if (alert == nil) { let alert = NSAlert()
let alert = NSAlert() alert.messageText = "Close Terminal?"
alert.messageText = "Close Terminal?" alert.informativeText = "The terminal still has a running process. If you close the " +
alert.informativeText = "The terminal still has a running process. If you close the " + "terminal the process will be killed."
"terminal the process will be killed." alert.addButton(withTitle: "Close the Terminal")
alert.addButton(withTitle: "Close the Terminal") alert.addButton(withTitle: "Cancel")
alert.addButton(withTitle: "Cancel") alert.alertStyle = .warning
alert.alertStyle = .warning alert.beginSheetModal(for: window, completionHandler: { response in
alert.beginSheetModal(for: window, completionHandler: { response in self.alert = nil
self.alert = nil switch (response) {
switch (response) { case .alertFirstButtonReturn:
case .alertFirstButtonReturn: window.close()
window.close()
default: default:
break break
} }
}) })
self.alert = alert self.alert = alert
}
return false return false
} }