fix: close attached sheet on window close (#28967)

This commit is contained in:
Shelley Vohr 2021-05-04 12:11:16 +02:00 committed by GitHub
parent 41bb3f1321
commit 3d6343ed51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View file

@ -473,6 +473,12 @@ void NativeWindowMac::Close() {
return;
}
// If a sheet is attached to the window when we call
// [window_ performClose:nil], the window won't close properly
// even after the user has ended the sheet.
// Ensure it's closed before calling [window_ performClose:nil].
SetEnabled(true);
[window_ performClose:nil];
// Closing a sheet doesn't trigger windowShouldClose,
@ -540,8 +546,7 @@ void NativeWindowMac::Hide() {
// If a sheet is attached to the window when we call [window_ orderOut:nil],
// the sheet won't be able to show again on the same window.
// Ensure it's closed before calling [window_ orderOut:nil].
if ([window_ attachedSheet])
[window_ endSheet:[window_ attachedSheet]];
SetEnabled(true);
if (is_modal() && parent()) {
[window_ orderOut:nil];
@ -575,14 +580,14 @@ bool NativeWindowMac::IsEnabled() {
}
void NativeWindowMac::SetEnabled(bool enable) {
if (enable) {
[window_ endSheet:[window_ attachedSheet]];
} else {
if (!enable) {
[window_ beginSheet:window_
completionHandler:^(NSModalResponse returnCode) {
NSLog(@"modal enabled");
return;
}];
} else if ([window_ attachedSheet]) {
[window_ endSheet:[window_ attachedSheet]];
}
}