Using PluginListComponent

The class fills all of my needs, and i was delighted something like that existed! However, i dont see why you can't register any listeners / events.. Like, it would be logical to somehow figure out which plugin is selected and / or do an action on doubleclick of an row. Otherwise, why would you be able to select stuff?

 

Forgive me if such functionality already exists and i overlooked it, but it doesn't seem so, given the class extensive use of private inheritance.. 

 

Regards

I only designed it as a quick GUI for managing a KnownPluginList, but sure, it could be extended. I'm happy to review any suggested changes!

Yeah i thought that was the case. I'll post an idea later!

This is how i imagined it would work:


/* usage */
class View : public PluginListComponent::PluginComponentListener
{
    AudioFormatManager manager;
    KnownPluginList pluginList;
    PluginListComponent pluginView;
    
    View()
        : manager(), pluginList(), pluginView(manager, pluginList, File::nonexistent, nullptr)
    {
        pluginView.setSelectionListener(this);
    }
    
    ....
    
    void onPluginSelection(int index) override
    {
        // user selected this plugin:
        PluginDescription * desc = pluginList.getType(index);    
    }
}

Requires following changes to:

modules/juce_audio_processors/scanning/juce_PluginListComponent.h:


/*
    class additions:
*/
class PluginListComponent
{
public:
    class PluginComponentListener
    {
    public:
        /*    called when the user double clicks a plugin. the index corrosponds to associated KnownPluginList::getType(index) */
        virtual void onPluginSelection(int index) = 0;
        virtual ~PluginComponentListener() {}
    };
    /*    sets a listener that will be notified when the user double-clicks a plugin in the list    */
    void setSelectionListener(PluginComponentListener * listener);
    
    /*    returns the current selected row index (corrosponds to associated KnownPluginList::getType(index))
        returns -1 is no selection, no rows or multiple files selected */
    int getSelectedIndex();
    ...
    
};

full file: http://pastebin.com/LUXrSjAY

modules/juce_audio_processors/scanning/juce_PluginListComponent.cpp:


class PluginListComponent::TableModel  : public TableListBoxModel
{
private:
    PluginListComponent::PluginComponentListener * listener;
    
    ...
    
public:
    
    /*
        inline class functions:
    */
    void setSelectionListener(PluginComponentListener * listener)
    {
        this->listener = listener;
    }
    virtual void cellDoubleClicked (int rowNumber, int columnId, const MouseEvent &e) override
    {
        if(listener)
        {
            listener->onPluginSelection(rowNumber);
        }
        TableListBoxModel::cellDoubleClicked(rownNumber, columnId, MouseEvent); // this is needed?
    }
    
    ...
};
/*
    class functions:
*/
int PluginListComponent::getSelectedIndex()
{
    // not sure if table.getLastRowSelected() is correct - should return the current row selected
    return table.getNumSelectedRows() > 1 ? -1 : table.getLastRowSelected(); 
}
void PluginListComponent::setSelectionListener(PluginComponentListener * listener)
{
    tableModel->setSelectionListener(listener);
}

full file: http://pastebin.com/dgZNxN8n

 

Notes: Usually in juce, there can be multiple listeners but i dont really see it making sense in this case. Also not so sure about returning -1 in getSelectedIndex() on error as it will be used as an array index afterwards (usually). Let me know what you think, though.