Hi Juce team!
Something just came up as a result of your “modal” changes in develop.
class OSXMessageBox : private AsyncUpdater
...
const char* button1;
const char* button2;
const char* button3;
That is very likely to misbehave in the async case (in fact, I’ve just seen it fail while testing!).
You need to change those 3 values to (say) juce::String to capture the arguments which are passed-in, which might well not be const char*, but actually computed (temporary) values (e.g. from juce::String contents).
The fix becomes:
class OSXMessageBox : private AsyncUpdater
{
public:
OSXMessageBox (AlertWindow::AlertIconType type, const String& t, const String& m,
const String& b1, const String& b2, const String& b3,
ModalComponentManager::Callback* c, const bool runAsync)
: iconType (type), title (t), message (m), callback (c),
button1 (b1), button2 (b2), button3 (b3)
{
if (runAsync)
triggerAsyncUpdate();
}
int getResult() const
{
switch (getRawResult())
{
case NSAlertFirstButtonReturn: return 1;
case NSAlertThirdButtonReturn: return 2;
default: return 0;
}
}
static int show (AlertWindow::AlertIconType iconType, const String& title, const String& message,
ModalComponentManager::Callback* callback, const String& b1, const String& b2, const String& b3,
bool runAsync)
{
std::unique_ptr<OSXMessageBox> mb (new OSXMessageBox (iconType, title, message, b1, b2, b3,
callback, runAsync));
if (! runAsync)
return mb->getResult();
mb.release();
return 0;
}
private:
AlertWindow::AlertIconType iconType;
String title, message;
std::unique_ptr<ModalComponentManager::Callback> callback;
// MPC fix - begin - was const char*
String button1;
String button2;
String button3;
// MPC fix - end - was const char*
void handleAsyncUpdate() override
{
auto result = getResult();
if (callback != nullptr)
callback->modalStateFinished (result);
delete this;
}
NSInteger getRawResult() const
{
NSAlert* alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText: juceStringToNS (title)];
[alert setInformativeText: juceStringToNS (message)];
[alert setAlertStyle: iconType == AlertWindow::WarningIcon ? NSAlertStyleCritical
: NSAlertStyleInformational];
addButton (alert, button1);
addButton (alert, button2);
addButton (alert, button3);
return [alert runModal];
}
static void addButton (NSAlert* alert, const String& button)
{
if (button != "")
[alert addButtonWithTitle: juceStringToNS (TRANS (button))];
}
}
You also need to change these:
OSXMessageBox::show (iconType, title, message, callback, "OK", nullptr, nullptr, true);
...
OSXMessageBox::show (iconType, title, message, callback,
"OK", "Cancel", nullptr, callback != nullptr) == 1;
...
OSXMessageBox::show (iconType, title, message, callback,
"Yes", "No", nullptr, callback != nullptr);
to these:
OSXMessageBox::show (iconType, title, message, callback, "OK", "", "", true);
...
OSXMessageBox::show (iconType, title, message, callback,
"OK", "Cancel", "", callback != nullptr) == 1;
...
OSXMessageBox::show (iconType, title, message, callback,
"Yes", "No", "", callback != nullptr);
Hoping that helps,
Pete
