UserBundle: Allow adding/removing ports

Clean up internal API confusion
- can_add_channels_proxy () -- checks presence of io
- can_add_channel_proxy () -- checks io->can_add_port()

UserBundle don't have a PortGroup::_bundle reference
that can be used to lookup the IO via io_from_bundle().

While BundleEditorMatrix::can_add_channels_proxy() was overriden
to allow adding I/Os, can_add_channel_proxy() later prevented that.

This further prevents removing the last port, preventing empty bundles.
This commit is contained in:
Robin Gareus 2021-02-26 14:06:04 +01:00
parent 017b272864
commit 4716f34c28
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
4 changed files with 28 additions and 10 deletions

View file

@ -112,6 +112,17 @@ BundleEditorMatrix::can_add_channels (boost::shared_ptr<Bundle> b) const
return PortMatrix::can_add_channels (b);
}
bool
BundleEditorMatrix::can_add_port (boost::shared_ptr<Bundle> b, DataType t) const
{
#if 1
return true; // anything goes
#else
/* Do not allow to mix datatypes */
return _bundle->nchannels().get (t) > 0;
#endif
}
void
BundleEditorMatrix::add_channel (boost::shared_ptr<Bundle> b, DataType t)
{
@ -136,11 +147,10 @@ BundleEditorMatrix::add_channel (boost::shared_ptr<Bundle> b, DataType t)
bool
BundleEditorMatrix::can_remove_channels (boost::shared_ptr<Bundle> b) const
{
if (b == _bundle) {
return true;
if (b != _bundle) {
return false;
}
return PortMatrix::can_remove_channels (b);
return _bundle->n_total () > 1;
}
void