Add macOS message box with buttons
This commit is contained in:
@@ -56,36 +56,94 @@ DialogResult MessageBox::Show(Window* parent, const StringView& text, const Stri
|
|||||||
{
|
{
|
||||||
if (CommandLine::Options.Headless)
|
if (CommandLine::Options.Headless)
|
||||||
return DialogResult::None;
|
return DialogResult::None;
|
||||||
CFStringRef textRef = AppleUtils::ToString(text);
|
NSAlert* alert = [[NSAlert alloc] init];
|
||||||
CFStringRef captionRef = AppleUtils::ToString(caption);
|
ASSERT(alert);
|
||||||
CFOptionFlags flags = 0;
|
|
||||||
switch (buttons)
|
switch (buttons)
|
||||||
{
|
{
|
||||||
case MessageBoxButtons::AbortRetryIgnore:
|
case MessageBoxButtons::AbortRetryIgnore:
|
||||||
|
[alert addButtonWithTitle:@"Abort"];
|
||||||
|
[alert addButtonWithTitle:@"Retry"];
|
||||||
|
[alert addButtonWithTitle:@"Ignore"];
|
||||||
|
break;
|
||||||
|
case MessageBoxButtons::OK:
|
||||||
|
[alert addButtonWithTitle:@"OK"];
|
||||||
|
break;
|
||||||
case MessageBoxButtons::OKCancel:
|
case MessageBoxButtons::OKCancel:
|
||||||
|
[alert addButtonWithTitle:@"OK"];
|
||||||
|
[alert addButtonWithTitle:@"Cancel"];
|
||||||
|
break;
|
||||||
case MessageBoxButtons::RetryCancel:
|
case MessageBoxButtons::RetryCancel:
|
||||||
|
[alert addButtonWithTitle:@"Retry"];
|
||||||
|
[alert addButtonWithTitle:@"Cancel"];
|
||||||
|
break;
|
||||||
case MessageBoxButtons::YesNo:
|
case MessageBoxButtons::YesNo:
|
||||||
|
[alert addButtonWithTitle:@"Yes"];
|
||||||
|
[alert addButtonWithTitle:@"No"];
|
||||||
|
break;
|
||||||
case MessageBoxButtons::YesNoCancel:
|
case MessageBoxButtons::YesNoCancel:
|
||||||
flags |= kCFUserNotificationCancelResponse;
|
[alert addButtonWithTitle:@"Yes"];
|
||||||
|
[alert addButtonWithTitle:@"No"];
|
||||||
|
[alert addButtonWithTitle:@"Cancel"];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (icon)
|
switch (icon)
|
||||||
{
|
{
|
||||||
case MessageBoxIcon::Information:
|
case MessageBoxIcon::Information:
|
||||||
flags |= kCFUserNotificationNoteAlertLevel;
|
[alert setAlertStyle:NSAlertStyleCritical];
|
||||||
break;
|
break;
|
||||||
case MessageBoxIcon::Error:
|
case MessageBoxIcon::Error:
|
||||||
case MessageBoxIcon::Stop:
|
case MessageBoxIcon::Stop:
|
||||||
flags |= kCFUserNotificationStopAlertLevel;
|
[alert setAlertStyle:NSAlertStyleInformational];
|
||||||
break;
|
break;
|
||||||
case MessageBoxIcon::Warning:
|
case MessageBoxIcon::Warning:
|
||||||
flags |= kCFUserNotificationCautionAlertLevel;
|
[alert setAlertStyle:NSAlertStyleWarning];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SInt32 result = CFUserNotificationDisplayNotice(0, flags, nullptr, nullptr, nullptr, captionRef, textRef, nullptr);
|
[alert setMessageText:(NSString*)AppleUtils::ToString(caption)];
|
||||||
CFRelease(captionRef);
|
[alert setInformativeText:(NSString*)AppleUtils::ToString(text)];
|
||||||
CFRelease(textRef);
|
NSInteger button = [alert runModal];
|
||||||
return DialogResult::OK;
|
DialogResult result = DialogResult::OK;
|
||||||
|
switch (buttons)
|
||||||
|
{
|
||||||
|
case MessageBoxButtons::AbortRetryIgnore:
|
||||||
|
if (button == NSAlertFirstButtonReturn)
|
||||||
|
result = DialogResult::Abort;
|
||||||
|
else if (button == NSAlertSecondButtonReturn)
|
||||||
|
result = DialogResult::Retry;
|
||||||
|
else
|
||||||
|
result = DialogResult::Ignore;
|
||||||
|
break;
|
||||||
|
case MessageBoxButtons::OK:
|
||||||
|
result = DialogResult::OK;
|
||||||
|
break;
|
||||||
|
case MessageBoxButtons::OKCancel:
|
||||||
|
if (button == NSAlertFirstButtonReturn)
|
||||||
|
result = DialogResult::OK;
|
||||||
|
else
|
||||||
|
result = DialogResult::Cancel;
|
||||||
|
break;
|
||||||
|
case MessageBoxButtons::RetryCancel:
|
||||||
|
if (button == NSAlertFirstButtonReturn)
|
||||||
|
result = DialogResult::Retry;
|
||||||
|
else
|
||||||
|
result = DialogResult::Cancel;
|
||||||
|
break;
|
||||||
|
case MessageBoxButtons::YesNo:
|
||||||
|
if (button == NSAlertFirstButtonReturn)
|
||||||
|
result = DialogResult::Yes;
|
||||||
|
else
|
||||||
|
result = DialogResult::No;
|
||||||
|
break;
|
||||||
|
case MessageBoxButtons::YesNoCancel:
|
||||||
|
if (button == NSAlertFirstButtonReturn)
|
||||||
|
result = DialogResult::Yes;
|
||||||
|
else if (button == NSAlertSecondButtonReturn)
|
||||||
|
result = DialogResult::No;
|
||||||
|
else
|
||||||
|
result = DialogResult::Cancel;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Float2 AppleUtils::PosToCoca(const Float2& pos)
|
Float2 AppleUtils::PosToCoca(const Float2& pos)
|
||||||
|
|||||||
Reference in New Issue
Block a user