1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

AlertWindow: Show AlertWindows as modal sheets on macOS when associated component is present

This commit is contained in:
reuk 2022-01-20 19:52:36 +00:00
parent 00e7fbf1c2
commit 88853f7eda

View file

@ -43,7 +43,7 @@ public:
int getResult() const
{
switch (getRawResult())
switch ([getAlert() runModal])
{
case NSAlertFirstButtonReturn: return 0;
case NSAlertSecondButtonReturn: return 1;
@ -60,8 +60,30 @@ public:
private:
void handleAsyncUpdate() override
{
auto result = getResult();
if (auto* comp = options.getAssociatedComponent())
{
if (auto* peer = comp->getPeer())
{
if (auto* view = static_cast<NSView*> (peer->getNativeHandle()))
{
if (auto* window = [view window])
{
[getAlert() beginSheetModalForWindow: window completionHandler: ^(NSModalResponse result)
{
handleModalFinished ((int) result);
}];
return;
}
}
}
}
handleModalFinished ((int) [getAlert() runModal]);
}
void handleModalFinished (int result)
{
if (callback != nullptr)
callback->modalStateFinished (result);
@ -74,7 +96,7 @@ private:
[alert addButtonWithTitle: juceStringToNS (button)];
}
NSInteger getRawResult() const
NSAlert* getAlert() const
{
NSAlert* alert = [[[NSAlert alloc] init] autorelease];
@ -90,7 +112,7 @@ private:
addButton (alert, options.getButtonText (1));
addButton (alert, options.getButtonText (2));
return [alert runModal];
return alert;
}
MessageBoxOptions options;