NativeMessageBox::showYesNoCancelBox () doesn’t allow custom button text


#1

JUCE AlertWindow::showYesNoCancelBox() allows one to set ones own custom text for buttons . Likewise, AlertWindow::showOkCancelBox() allows custom button 1 and button2  valiues.

However if we opt to use NATIVE OSX  alerts via LookandFeel   the custom button text gets ignored: This means for example we cannot use native alerts that incorporate "Abort", "Retry" etc etc..

Basically  ALL the OSX  native  Alerts - have hard-coded button text !!. 

int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconType iconType,
const String& title, const String& message,Component* /*associatedComponent*/, ModalComponentManager::Callback* callback)
{
return OSXMessageBox::show (iconType, title, message, callback,
"Yes", "Cancel", "No", callback != nullptr);
}

 

Can we please have an added option that allows ( for OSX ) us to use our own text !  this then would at least give consistency when opting for

native OSX dialogs 

int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconType iconType,
const String& title, const String& message, const String& button1 , const String& button2 , const String& button3 , Component* /*associatedComponent*/, ModalComponentManager::Callback* callback)
{
return OSXMessageBox::show (iconType, title, message, callback,
button1, button2, button3, callback != nullptr);
}


Failing this - how do i write code and change #includes etc etc so that I can just use 
OSXMessageBox::show()  in my own code ? 

 

 


#2

This is the same for all platforms, basically for consistency across platforms that don't allow you to set the text (I think win32 is like that).

But on OSX Apple have just deprecated this whole API, so I'll need to write something new to replace it. That might be a good time to look at all platforms and review whether a better system with customisable text might be possible.


#3

I think he is just asking for a fix like this, which is likely what you originally intended:

int AlertWindow::showYesNoCancelBox (AlertIconType iconType,

                                     const String& title,

                                     const String& message,

                                     const String& button1Text,

                                     const String& button2Text,

                                     const String& button3Text,

                                     Component* associatedComponent,

                                     ModalComponentManager::Callback* callback)

{

    if (LookAndFeel::getDefaultLookAndFeel().isUsingNativeAlertWindows())

        return NativeMessageBox::showYesNoCancelBox (iconType, title, message, button1Text, button2Text, button3Text,associatedComponent, callback);


    AlertWindowInfo info (title, message, associatedComponent, iconType, 3, callback, callback == nullptr);

    info.button1 = button1Text.isEmpty() ? TRANS("Yes")     : button1Text;

    info.button2 = button2Text.isEmpty() ? TRANS("No")      : button2Text;

    info.button3 = button3Text.isEmpty() ? TRANS("Cancel")  : button3Text;


    return info.invoke();

}

 

int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (AlertWindow::AlertIconType iconType,

                                                        const String& title, const String& message,

                                                        const String &b1Text, const String &b2Text, const String &b3Text,

                                                        Component* /*associatedComponent*/,

                                                        ModalComponentManager::Callback* callback)

{

    return OSXMessageBox::show (iconType, title, message, callback,

                                b1Text.isEmpty() ? "Yes" : b1Text.toUTF8(),

                                b2Text.isEmpty() ? "No" : b2Text.toUTF8(),

                                b3Text.isEmpty() ? "Cancel" : b3Text.toUTF8(),

                                callback != nullptr);

}


#4

I could certainly do that, but I really don't think that's what the OP meant, I think he was asking to be able to pass in strings to the function.


#5

Yes, and in the original code, the custom strings passed into the function weren't getting passed along to the OSX Native Box.  I just modified it to pass them along, which is certainly what you must have intended.

Thanks!

Steve