Problem using menubar in vst plugin


#1

I followed the example of the jucer demo for setting up the menubar. I can compile without errors and I see the menubar in my vst plugin with the new column names, but the pop up menu is not working. Not sure if the problem is related to the missing DocumentWindow or something I'm missing in my code.

Here is what I have so far:

ApplicationCommandManager commandManager;
enum Commands{

        command1 = 0,

        command2

    };
StringArray SessionComponent::getMenuBarNames()

{
    const char* const names[] = { "example", "settings",  nullptr };

    return StringArray (names);
}

PopupMenu SessionComponent::getMenuForIndex (int menuIndex, const String& /*menuName*/)

{
    ApplicationCommandManager *commandManager= &(session->commandManager);

    PopupMenu menu;

    if (menuIndex == 0)

    {

        menu.addCommandItem (commandManager, command1);

        menu.addSeparator();

        menu.addCommandItem (commandManager, command2);

        menu.addSeparator();
    }
    else if (menuIndex == 1)
    {

        menu.addCommandItem (commandManager, command1);

        menu.addSeparator();

        menu.addCommandItem (commandManager, command2);

    }

    return menu;

}

ApplicationCommandTarget* SessionComponent::getNextCommandTarget()

{

    // this will return the next parent component that is an ApplicationCommandTarget (in this

    // case, there probably isn't one, but it's best to use this method in your own apps).

    return findFirstTargetParentComponent();

}


void SessionComponent::getAllCommands (Array <CommandID>& commands)

{

    // this returns the set of all commands that this target can perform..

    const CommandID ids[] = {

        command1,

        command2

    };


    commands.addArray (ids, numElementsInArray (ids));

}


// This method is used when something needs to find out the details about one of the commands

// that this object can perform..

void SessionComponent::getCommandInfo (CommandID commandID, ApplicationCommandInfo& result)

{

    const String generalCategory ("General");

    const String demosCategory ("Demos");


    switch (commandID)

    {

        case command1:

            result.setInfo ("Graphics Rendering", "Shows the graphics demo", demosCategory, 0);

            //result.setTicked (currentDemoId == command1);

            result.addDefaultKeypress ('1', ModifierKeys::commandModifier);

            break;


        case command2:

            result.setInfo ("Fonts and Text", "Shows the fonts & text demo", demosCategory, 0);

            //result.setTicked (currentDemoId == showFontsAndText);

            result.addDefaultKeypress ('2', ModifierKeys::commandModifier);

            break;



        default:

            break;

    };

}


// this is the ApplicationCommandTarget method that is used to actually perform one of our commands..

bool SessionComponent::perform (const InvocationInfo& info)

{

    switch (info.commandID)

    {

        case command1:


            break;


        case command2:


            break;


        default:

            return false;

    };


    return true;

}

 

Thanks!

 

 


#2

Still stuck.

Any thoughts about this? Thanks!


#3

The menubar was certainly never designed for use in a plugin (and IMHO anything that attempts to pop-up any kind of window in a plugin is probably a bad idea). But can you give a bit more detail than "not working"? Have you stepped through it in the debugger to see what happens?


#4

Thanks Jules, finally I'm using a button with a popup menu and that works fine for me.

 


#5

This won't work due to window focus issues, you'll get the menus and all but they will be always greyed-out since the ApplicationManager won't see the focus. I wrote that in my app too and wen't too far with it and now i have to do nasty hacks to catch focus for the window so that the menus stay active. One way i found that helps, is clicking on a resizable corner component i have attached to my window and set always on top, clicking on it gives the window focus, clicking anywhere on the window doesn't.