|
|
@@ -239,6 +239,68 @@ ElementPtr Factory::InstanceElement(Element* parent, const String& instancer_nam
|
|
|
element->SetAttributes(attributes);
|
|
|
ElementUtilities::BindEventAttributes(element.get());
|
|
|
|
|
|
+
|
|
|
+ {
|
|
|
+ // Look for the data-model attribute or otherwise copy it from the parent element
|
|
|
+ auto it = attributes.find("data-model");
|
|
|
+ if (it != attributes.end())
|
|
|
+ {
|
|
|
+ String error_msg;
|
|
|
+
|
|
|
+ if (auto context = parent->GetContext())
|
|
|
+ {
|
|
|
+ String name = it->second.Get<String>();
|
|
|
+ if (auto model = context->GetDataModel(name))
|
|
|
+ element->data_model = model;
|
|
|
+ else
|
|
|
+ Log::Message(Log::LT_WARNING, "Could not locate data model '%s'.", name.c_str());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::Message(Log::LT_WARNING, "Could not add data model to element '%s' because the context is not available.", element->GetAddress().c_str());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (parent && parent->data_model)
|
|
|
+ {
|
|
|
+ element->data_model = parent->data_model;
|
|
|
+ }
|
|
|
+
|
|
|
+ // If we have an active data model, check the attributes for any data bindings
|
|
|
+ if (DataModel* data_model = element->data_model)
|
|
|
+ {
|
|
|
+ for (auto& attribute : attributes)
|
|
|
+ {
|
|
|
+ auto& name = attribute.first;
|
|
|
+
|
|
|
+ if (name.size() > 5 && name[0] == 'd' && name[1] == 'a' && name[2] == 't' && name[3] == 'a' && name[4] == '-')
|
|
|
+ {
|
|
|
+ const size_t data_type_end = name.find('-', 5);
|
|
|
+ if (data_type_end != String::npos)
|
|
|
+ {
|
|
|
+ const String data_type = name.substr(5, data_type_end - 5);
|
|
|
+
|
|
|
+ if (data_type == "attr")
|
|
|
+ {
|
|
|
+ const String attr_bind_name = name.substr(5 + data_type.size() + 1);
|
|
|
+ const String value_bind_name = attribute.second.Get<String>();
|
|
|
+
|
|
|
+ DataViewAttribute data_view(*data_model, element.get(), attr_bind_name, value_bind_name);
|
|
|
+ if (data_view)
|
|
|
+ {
|
|
|
+ data_model->views.AddView(std::move(data_view));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::Message(Log::LT_WARNING, "Could not add data binding view to element '%s'.", parent->GetAddress().c_str());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
PluginRegistry::NotifyElementCreate(element.get());
|
|
|
}
|
|
|
|
|
|
@@ -303,7 +365,28 @@ bool Factory::InstanceElementText(Element* parent, const String& text)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- text_element->SetText(translated_data);
|
|
|
+ // See if this text element uses data bindings.
|
|
|
+ bool data_view_added = false;
|
|
|
+ if (DataModel* data_model = element->data_model)
|
|
|
+ {
|
|
|
+ const size_t i_brackets = translated_data.find("{{", 0);
|
|
|
+ if (i_brackets != String::npos)
|
|
|
+ {
|
|
|
+ DataViewText data_view(*data_model, text_element, translated_data, i_brackets);
|
|
|
+ if (data_view)
|
|
|
+ {
|
|
|
+ data_model->views.AddView(std::move(data_view));
|
|
|
+ data_view_added = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log::Message(Log::LT_WARNING, "Could not add data binding view to element '%s'.", parent->GetAddress().c_str());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!data_view_added)
|
|
|
+ text_element->SetText(translated_data);
|
|
|
|
|
|
// Add to active node.
|
|
|
parent->AppendChild(std::move(element));
|