PopupMenu::Options::withDeletionCheck() behaviour clarification

Re: PopupMenu::Options::withDeletionCheck()

While there is no documentation for this function, @jules said:

Just a follow-up note re: this new menu stuff - I’ve added a PopupMenu::Options::withDeletionCheck() method now, which you can give a Component, and if that component is deleted while the menu is open no action will be performed.

However, this is not universally true. It only applies to PopupMenu::addItem (String itemText, std::function< void()> action), it does not apply to PopupMenu::showMenuAsync(). If this is the intended behaviour, that needs to be clearly documented.

And even then, I’m not convinced it works. Isn’t it completely pointless to do the deletion check before async call rather than after?

            auto resultID = options.hasWatchedComponentBeenDeleted() ? 0 : getResultItemID (item);

            exitModalState (resultID);

            if (makeInvisible && deletionChecker != nullptr)
                setVisible (false);

            if (resultID != 0
                 && item != nullptr
                 && item->action != nullptr)
                MessageManager::callAsync (item->action);

Here is my proposed fix:

I also propose when you set a target component, it should set the component to watch for deletion as well. I can think of no case where you’d still want a menu to fire once the target has been deleted.

1 Like