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.
