macos: simplify the code to a more understandable style
parent
1eecd448e9
commit
04563a16b6
|
|
@ -287,7 +287,6 @@ class BaseTerminalController: NSWindowController,
|
||||||
func confirmClose(
|
func confirmClose(
|
||||||
messageText: String,
|
messageText: String,
|
||||||
informativeText: String,
|
informativeText: String,
|
||||||
attachedWindow: NSWindow? = nil,
|
|
||||||
completion: @escaping () -> Void
|
completion: @escaping () -> Void
|
||||||
) {
|
) {
|
||||||
// If we already have an alert, we need to wait for that one.
|
// If we already have an alert, we need to wait for that one.
|
||||||
|
|
@ -295,7 +294,7 @@ class BaseTerminalController: NSWindowController,
|
||||||
|
|
||||||
// If there is no window to attach the modal then we assume success
|
// If there is no window to attach the modal then we assume success
|
||||||
// since we'll never be able to show the modal.
|
// since we'll never be able to show the modal.
|
||||||
guard let window = attachedWindow ?? self.window else {
|
guard let window else {
|
||||||
completion()
|
completion()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -817,12 +817,14 @@ 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() {
|
||||||
let confirmWindow: NSWindow? = all
|
// The window we use for confirmations. Try to find the first window that
|
||||||
.first { $0.surfaceTree.contains(where: { $0.needsConfirmQuit }) }?
|
// needs quit confirmation. This lets us attach the confirmation to something
|
||||||
.surfaceTree.first { $0.needsConfirmQuit }?
|
// that is running.
|
||||||
|
guard let confirmWindow = all
|
||||||
|
.first(where: { $0.surfaceTree.contains(where: { $0.needsConfirmQuit }) })?
|
||||||
|
.surfaceTree.first(where: { $0.needsConfirmQuit })?
|
||||||
.window
|
.window
|
||||||
|
else {
|
||||||
guard let confirmWindow else {
|
|
||||||
closeAllWindowsImmediately()
|
closeAllWindowsImmediately()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -1153,25 +1155,19 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
|
||||||
// if we're closing the window. If we don't have a tabgroup for any
|
// if we're closing the window. If we don't have a tabgroup for any
|
||||||
// reason we check ourselves.
|
// reason we check ourselves.
|
||||||
let windows: [NSWindow] = window.tabGroup?.windows ?? [window]
|
let windows: [NSWindow] = window.tabGroup?.windows ?? [window]
|
||||||
|
guard let confirmController = windows
|
||||||
let confirmWindow: NSWindow? = windows
|
.compactMap({ $0.windowController as? TerminalController })
|
||||||
.first {
|
.first(where: { $0.surfaceTree.contains(where: { $0.needsConfirmQuit }) })
|
||||||
($0.windowController as? TerminalController)?.surfaceTree.contains(where: { $0.needsConfirmQuit }) == true
|
else {
|
||||||
}
|
|
||||||
.flatMap {
|
|
||||||
($0.windowController as? TerminalController)?.surfaceTree.first(where: { $0.needsConfirmQuit })
|
|
||||||
}?.window
|
|
||||||
|
|
||||||
// If none need confirmation then we can just close all the windows.
|
|
||||||
guard let confirmWindow else {
|
|
||||||
closeWindowImmediately()
|
closeWindowImmediately()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmClose(
|
// We call confirmClose on the proper controller so the alert is
|
||||||
|
// attached to the window that needs confirmation.
|
||||||
|
confirmController.confirmClose(
|
||||||
messageText: "Close Window?",
|
messageText: "Close Window?",
|
||||||
informativeText: "All terminal sessions in this window will be terminated.",
|
informativeText: "All terminal sessions in this window will be terminated.",
|
||||||
attachedWindow: confirmWindow,
|
|
||||||
) {
|
) {
|
||||||
self.closeWindowImmediately()
|
self.closeWindowImmediately()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue