remove needsConfirm

pull/9509/head
Lars 2025-11-07 16:21:45 +01:00 committed by Mitchell Hashimoto
parent f94cb01ec8
commit 1eecd448e9
1 changed files with 12 additions and 32 deletions

View File

@ -817,17 +817,12 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
/// Close all windows, asking for confirmation if necessary. /// Close all windows, asking for confirmation if necessary.
static func closeAllWindows() { static func closeAllWindows() {
var confirmWindow: NSWindow? let confirmWindow: NSWindow? = all
var needsConfirm = false .first { $0.surfaceTree.contains(where: { $0.needsConfirmQuit }) }?
for controller in all { .surfaceTree.first { $0.needsConfirmQuit }?
if let surfaceToConfirm = controller.surfaceTree.first(where: { $0.needsConfirmQuit }) { .window
needsConfirm = true
confirmWindow = surfaceToConfirm.window
break
}
}
guard needsConfirm else { guard let confirmWindow else {
closeAllWindowsImmediately() closeAllWindowsImmediately()
return return
} }
@ -838,15 +833,6 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
alert.addButton(withTitle: "Close All Windows") alert.addButton(withTitle: "Close All Windows")
alert.addButton(withTitle: "Cancel") alert.addButton(withTitle: "Cancel")
alert.alertStyle = .warning alert.alertStyle = .warning
guard let confirmWindow else {
if (alert.runModal() == .alertFirstButtonReturn) {
// This is important so that we avoid losing focus when Stage
// Manager is used (#8336)
alert.window.orderOut(nil)
closeAllWindowsImmediately()
}
return
}
alert.beginSheetModal(for: confirmWindow, completionHandler: { response in alert.beginSheetModal(for: confirmWindow, completionHandler: { response in
if (response == .alertFirstButtonReturn) { if (response == .alertFirstButtonReturn) {
// This is important so that we avoid losing focus when Stage // This is important so that we avoid losing focus when Stage
@ -1168,22 +1154,16 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
// reason we check ourselves. // reason we check ourselves.
let windows: [NSWindow] = window.tabGroup?.windows ?? [window] let windows: [NSWindow] = window.tabGroup?.windows ?? [window]
var confirmWindow: NSWindow? let confirmWindow: NSWindow? = windows
var needsConfirm = false .first {
// Check if any windows require close confirmation. ($0.windowController as? TerminalController)?.surfaceTree.contains(where: { $0.needsConfirmQuit }) == true
for tabWindow in windows {
guard let controller = tabWindow.windowController as? TerminalController else {
continue
} }
if let surfaceToConfirm = controller.surfaceTree.first(where: { $0.needsConfirmQuit }) { .flatMap {
needsConfirm = true ($0.windowController as? TerminalController)?.surfaceTree.first(where: { $0.needsConfirmQuit })
confirmWindow = surfaceToConfirm.window }?.window
break
}
}
// If none need confirmation then we can just close all the windows. // If none need confirmation then we can just close all the windows.
if !needsConfirm { guard let confirmWindow else {
closeWindowImmediately() closeWindowImmediately()
return return
} }