AlertWindow/NativeMessageBox::show() return value clarification

in BREAKING_CHANGES.md I read:

The value returned by AlertWindow::show() has been changed so that it is consistent between native and non-native windows. The documentation has been updated to describe the new behaviour.

It’s these kinds of changes that make me wake up in the middle of the night drenched in sweat.

For example, the setup routine uses NativeMessageBox to ask whether a failed write operation should be retried, canceled, or ignored. A change could have massive impact on my software.

Does “native-window” refer to NativeMessageBox? I’m confused.

When I read the documentation:

AltertWindow::show()

 - Three buttons:
            - button[0] returns 1
            - button[1] returns 2
            - button[2] returns 0

        Another way of expressing this is that, when there are N buttons, then the result code for
        button X is equal to ((X + 1) % N).

NativeMessageBox::show()

@returns the index of the button that was clicked.

PS: every behavior changed should always result in an API change

3 Likes

Wow, I would have filed that API under comedy…

If you cannot return the button index, which would be the expected, how about letting the user attach an int or a juce::var in .withButton() ?

auto result = juce::AlertWindow::show (MessageBoxOptions()
    .withButton ("Ok", 1)
    .withButton ("Cancel", 2)
    .withButton ("Whatever", 3));

That way the user can use their own enum or magic numbers, if they prefer that.
A default of -1 could restore the original behaviour and ether return the button index, or if there is a technical advantage, return your proposed formula.

3 Likes

I think that would be a nice change! The old form could be marked as deprecated.

1 Like