Fix dataloss when flex inset is undefined.

Regression at cfeddb929. If a flex inset has no layout upon saving (e.g. if a
module has been deleted) then its name became lost. This checks whether the name
resolution, introduced with the ObsoletedBy tag, comes back empty-handed (which
it will if the layout is not defined). In this case, we do as was done before
cfeddb929.

In addition, the use of support::token to strip "Flex:" off the beginning of the
name introduces a regression if somebody used a name containing ":". This
replaces it with support::split.
This commit is contained in:
Guillaume Munch 2016-04-11 17:33:14 +01:00
parent 7c3fd63646
commit f180e813fe

View File

@ -68,19 +68,24 @@ InsetLayout::InsetDecoration InsetFlex::decoration() const
void InsetFlex::write(ostream & os) const
{
os << "Flex ";
InsetLayout const & il = getLayout();
string name;
if (name_.empty())
os << "undefined";
name = "undefined";
else {
// use il.name(), since this resolves obsoleted
// InsetLayout names
string name = to_utf8(il.name());
// Remove the "Flex:" prefix, if it is present
if (support::prefixIs(name, "Flex:"))
name = support::token(name, ':', 1);
os << name;
InsetLayout const & il = getLayout();
// use il.name(), since this resolves obsoleted InsetLayout names
if (il.name() == "undefined")
// This is the name of the plain_insetlayout_. We assume that the
// name resolution has failed.
name = name_;
else {
name = to_utf8(il.name());
// Remove the "Flex:" prefix, if it is present
if (support::prefixIs(name, "Flex:"))
name = support::split(name, ':');
}
}
os << "\n";
os << name << "\n";
InsetCollapsable::write(os);
}