Commit e5c9269d authored by T.J. Corona's avatar T.J. Corona

Resolve resource surrogates when resource is added to manager.

parent 70f8a9da
......@@ -409,6 +409,14 @@ bool Manager::add(const Resource::Index& index, const smtk::resource::ResourcePt
resource->m_manager = this->shared_from_this();
m_resources.insert(resource);
// Resolve resource surrogate links between the new resource and currently
// managed resources.
for (auto rsrc : m_resources)
{
resource->links().resolve(rsrc);
rsrc->links().resolve(resource);
}
// Tell observers we just added a resource:
m_observers(resource, smtk::resource::EventType::ADDED);
......
......@@ -41,6 +41,19 @@ const Resource* ResourceLinks::leftHandSideResource() const
{
return m_resource;
}
bool ResourceLinks::resolve(const ResourcePtr& resource) const
{
for (const Surrogate& surrogate : m_data)
{
if (surrogate.typeName() == resource->typeName() && surrogate.id() == resource->id())
{
surrogate.resolve(resource);
return true;
}
}
return false;
}
}
}
}
......@@ -86,6 +86,10 @@ public:
ResourceLinkData& data() { return m_data; }
const ResourceLinkData& data() const { return m_data; }
// Resolve any surrogates with the given resource. Returns true if a surrogate
// is successfully resolved.
bool resolve(const ResourcePtr&) const;
private:
ResourceLinks(Resource*);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment