mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
Merge pull request #1119 from mitchellh/macos-close-win
macos: close_window binding works properly again
This commit is contained in:
@ -268,7 +268,53 @@ class TerminalController: NSWindowController, NSWindowDelegate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func closeWindow(_ sender: Any) {
|
@IBAction func closeWindow(_ sender: Any) {
|
||||||
self.window?.performClose(sender)
|
guard let window = window else { return }
|
||||||
|
guard let tabGroup = window.tabGroup else {
|
||||||
|
// No tabs, no tab group, just perform a normal close.
|
||||||
|
window.performClose(sender)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If have one window then we just do a normal close
|
||||||
|
if tabGroup.windows.count == 1 {
|
||||||
|
window.performClose(sender)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any windows require close confirmation.
|
||||||
|
var needsConfirm: Bool = false
|
||||||
|
for tabWindow in tabGroup.windows {
|
||||||
|
guard let c = tabWindow.windowController as? TerminalController else { continue }
|
||||||
|
if (c.surfaceTree?.needsConfirmQuit() ?? false) {
|
||||||
|
needsConfirm = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If none need confirmation then we can just close all the windows.
|
||||||
|
if (!needsConfirm) {
|
||||||
|
for tabWindow in tabGroup.windows {
|
||||||
|
tabWindow.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we need confirmation by any, show one confirmation for all windows
|
||||||
|
// in the tab group.
|
||||||
|
let alert = NSAlert()
|
||||||
|
alert.messageText = "Close Window?"
|
||||||
|
alert.informativeText = "All terminal sessions in this window will be terminated."
|
||||||
|
alert.addButton(withTitle: "Close Window")
|
||||||
|
alert.addButton(withTitle: "Cancel")
|
||||||
|
alert.alertStyle = .warning
|
||||||
|
alert.beginSheetModal(for: window, completionHandler: { response in
|
||||||
|
if (response == .alertFirstButtonReturn) {
|
||||||
|
for tabWindow in tabGroup.windows {
|
||||||
|
tabWindow.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func splitHorizontally(_ sender: Any) {
|
@IBAction func splitHorizontally(_ sender: Any) {
|
||||||
|
Reference in New Issue
Block a user