TextEditor as PopupMenu::CustomComponent

Hi,

I was trying to create my custom menuItem that is basically a TextEditor that needs me to filters following choices of the menu. (For example if menu has items “banana”, “apple”, “lemon”, “orange”, if I type on TextEditor “orange” only items called “orange” are shown).

I done this PopupMenu::CustomComponent, but then when I try to type in TextEditor I can’t (and with right click on TextEditor, when the popupMenu containing “cut”, “copy”, ecc is shown, clicking on one item all popUps are closed…)

How can I?

this is my PopupMenu::CustomComponent

struct SearchPluginComponent  : public PopupMenu::CustomComponent
{
    SearchPluginComponent ()
        : PopupMenu::CustomComponent (false)
    {
        addAndMakeVisible(searcher);
        searcher.setWantsKeyboardFocus(true);
        searcher.setText("filter", NotificationType::dontSendNotification);
        searcher.setBounds(0, 0, idealWidth, idealHeight);
    }
    
    void getIdealSize (int& width, int& height) override
    {
        width = idealWidth;
        height = idealHeight;
    }

    int idealWidth = 200;
    int idealHeight = 24;
    TextEditor searcher{"searcher"};
};

and in “showPopupMenu()”

//other stuffs....
PopupMenu pluginSubMenu;
std::unique_ptr<SearchPluginComponent> searcher = std::make_unique<SearchPluginComponent>();
pluginSubMenu.addCustomItem(-1, std::move(searcher));
mainWindow->addPluginsToMenu(pluginSubMenu);
//other stuffs....

Also… there’s a way (maybe a callback) to rebuild items in popupMenu…?

No one has an idea about? :blush:

It seems what you are trying to do is quite similar to this: Augmenting PopupMenu with a quick search option

2 Likes

Wow!!! It’s exactly what I search for :pray: really thank you!!

I started to use PopupMenuQuickSearch and wow it’s a really good job!

just one thing:

  1. when I launch it with showPopupMenuWithQuickSearch it doesn’t appears at the mouse position as it happens with menu.showMenuAsync but its topLeftPosition is getX() and getHeight() of targetComponent, how to fix? in this moment the problem is that in big component it is shown really far from mouse position

If you call PopupMenu::Options::withTargetScreenArea after PopupMenu::Options::withTargetComponent , then it should work.

1 Like