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..
/*
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();
...
};
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.