SourceList: Drop references as requested

This commit is contained in:
Robin Gareus
2020-02-25 15:36:53 +01:00
parent e926a580a9
commit 589437c74a
2 changed files with 24 additions and 0 deletions

View File

@@ -319,6 +319,23 @@ EditorSources::remove_source (boost::shared_ptr<ARDOUR::Source> source)
}
}
void
EditorSources::remove_weak_region (boost::weak_ptr<ARDOUR::Region> r)
{
boost::shared_ptr<ARDOUR::Region> region = r.lock();
if (!region) {
return;
}
TreeModel::Children rows = _model->children();
for (TreeModel::iterator i = rows.begin(); i != rows.end(); ++i) {
boost::shared_ptr<ARDOUR::Region> rr = (*i)[_columns.region];
if (rr = region) {
_model->erase(i);
break;
}
}
}
void
EditorSources::populate_row (TreeModel::Row row, boost::shared_ptr<ARDOUR::Region> region)
{
@@ -409,10 +426,12 @@ EditorSources::redisplay ()
return;
}
remove_region_connections.drop_connections ();
_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
_model->clear ();
_model->set_sort_column (-2, SORT_ASCENDING); //Disable sorting to gain performance
//Ask the region factory to fill our list of whole-file regions
RegionFactory::foreach_region (sigc::mem_fun (*this, &EditorSources::add_source));
@@ -439,6 +458,8 @@ EditorSources::add_source (boost::shared_ptr<ARDOUR::Region> region)
return;
}
region->DropReferences.connect (remove_region_connections, MISSING_INVALIDATOR, boost::bind (&EditorSources::remove_weak_region, this, boost::weak_ptr<Region> (region)), gui_context());
TreeModel::Row row = *(_model->append());
populate_row (row, region);
}
@@ -828,6 +849,7 @@ EditorSources::get_dragged_region ()
void
EditorSources::clear ()
{
remove_region_connections.drop_connections ();
_display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
_model->clear ();
_display.set_model (_model);

View File

@@ -120,6 +120,7 @@ private:
void add_source (boost::shared_ptr<ARDOUR::Region>);
void remove_source (boost::shared_ptr<ARDOUR::Source>);
void remove_weak_region (boost::weak_ptr<ARDOUR::Region>);
void remove_weak_source (boost::weak_ptr<ARDOUR::Source>);
void clock_format_changed ();
@@ -150,6 +151,7 @@ private:
PBD::ScopedConnection source_property_connection;
PBD::ScopedConnection add_source_connection;
PBD::ScopedConnection remove_source_connection;
PBD::ScopedConnectionList remove_region_connections;
PBD::ScopedConnection editor_freeze_connection;
PBD::ScopedConnection editor_thaw_connection;