FileBasedDocument::saveIfNeededAndUserAgrees behavior change?

I have a bug in my app that uses FileBasedDocument::saveIfNeededAndUserAgrees. The behavior of the dialog does not map properly (maybe the order of the buttons changed?)

UPDATE: This only happens when using the native AlertWindow when not using the Async versions. I have been meaning to disable modal loops anyway so no time like the present.

  • “Save” behaves like “Cancel”.
  • “Discard changes” behaves like ”Save”
  • “Cancel” behaves like “Discard changes”

On macOS Sequoia / JUCE 8.

In the JUCE code below

Click “Save” alertResult == 0

Click “Discard changes” alertResult == 1

Click “Cancel” alertResult == 2

    void saveIfNeededAndUserAgreesImpl (SafeParentPointer parent,
                                        std::function<void (SaveResult)> completed,
                                        DoAskToSaveChanges&& doAskToSaveChanges,
                                        DoSave&& doSave)
    {
        if (parent.shouldExitAsyncCallback())
            return;

        if (! hasChangedSinceSaved())
        {
            NullCheckedInvocation::invoke (completed, savedOk);
            return;
        }

        auto afterAsking = [save = std::forward<DoSave> (doSave),
                            cb = std::move (completed)] (SafeParentPointer ptr,
                                                         int alertResult)
        {
            if (ptr.shouldExitAsyncCallback())
                return;

            switch (alertResult)
            {
                case 1:  // save changes
                    save (true, true, [ptr, cb] (SaveResult result)
                    {
                        if (ptr.shouldExitAsyncCallback())
                            return;

                        NullCheckedInvocation::invoke (cb, result);
                    });
                    return;

                case 2:  // discard changes
                    NullCheckedInvocation::invoke (cb, savedOk);
                    return;
            }

            NullCheckedInvocation::invoke (cb, userCancelledSave);
        };

        doAskToSaveChanges (parent, std::move (afterAsking));
    }

Thanks, this looks like a bug across AlertWindow and FileBasedDocument. It should be fixed by the commit below, although I’d recommend moving to the async functions if possible, as you mentioned.