case TC_DEFAULTSTYLE:
if (lexrc.next()) {
- string const name = subst(lowercase(lexrc.getString()), '_', ' ');
+ string const name = subst(lexrc.getString(),
+ '_', ' ');
defaultlayout_ = name;
}
break;
case TC_STYLE:
if (lexrc.next()) {
- string const name = subst(lowercase(lexrc.getString()),
+ string const name = subst(lexrc.getString(),
'_', ' ');
if (hasLayout(name)) {
- LyXLayout & lay = operator[](name);
+ LyXLayout & lay =
+ const_cast<LyXLayout &>(operator[](name));
error = do_readStyle(lexrc, lay);
} else {
LyXLayout lay;
lay.setName(name);
if (!(error = do_readStyle(lexrc, lay)))
layoutlist.push_back(lay);
+ if (defaultlayout_.empty()) {
+ // We do not have a default
+ // layout yet, so we choose
+ // the first layout we
+ // encounter.
+ defaultlayout_ = name;
+ }
}
}
else {
case TC_NOSTYLE:
if (lexrc.next()) {
- string const style = subst(lowercase(lexrc.getString()),
+ string const style = subst(lexrc.getString(),
'_', ' ');
if (!delete_layout(style))
lyxerr << "Cannot delete style `" << style << "'" << endl;
bool LyXTextClass::hasLayout(string const & n) const
{
- string const name = (n.empty() ? defaultLayoutName() : lowercase(n));
+ string const name = (n.empty() ? defaultLayoutName() : n);
return find_if(layoutlist.begin(), layoutlist.end(),
lyx::compare_memfun(&LyXLayout::name, name))
LyXLayout const & LyXTextClass::operator[](string const & n) const
{
+ lyx::Assert(!n.empty());
+
if (n.empty())
lyxerr << "Operator[] called with empty n" << endl;
- string const name = (n.empty() ? defaultLayoutName() : lowercase(n));
-
- LayoutList::const_iterator cit =
- find_if(layoutlist.begin(),
- layoutlist.end(),
- lyx::compare_memfun(&LyXLayout::name, name));
-
- if (cit == layoutlist.end()) {
- lyxerr << "We failed to find the layout '" << name
- << "' in the layout list. You MUST investigate!"
- << endl;
-
- // we require the name to exist
- lyx::Assert(false);
- }
-
- return *cit;
-}
+ string const name = (n.empty() ? defaultLayoutName() : n);
+ static string lastLayoutName;
+ static LayoutList::difference_type lastLayoutIndex;
-LyXLayout & LyXTextClass::operator[](string const & n)
-{
- if (n.empty())
- lyxerr << "Operator[] called with empty n" << endl;
+ if (name == lastLayoutName)
+ return layoutlist[lastLayoutIndex];
- string const name = (n.empty() ? defaultLayoutName() : lowercase(n));
- LayoutList::iterator it =
+ LayoutList::const_iterator cit =
find_if(layoutlist.begin(),
layoutlist.end(),
lyx::compare_memfun(&LyXLayout::name, name));
- if (it == layoutlist.end()) {
+ if (cit == layoutlist.end()) {
lyxerr << "We failed to find the layout '" << name
<< "' in the layout list. You MUST investigate!"
<< endl;
// we require the name to exist
lyx::Assert(false);
}
+
+ lastLayoutName = name;
+ lastLayoutIndex = std::distance(layoutlist.begin(), cit);
- return *it;
+ return *cit;
}
-bool LyXTextClass::delete_layout(string const & n)
+bool LyXTextClass::delete_layout(string const & name)
{
- string const name = lowercase(n);
-
if (name == defaultLayoutName())
return false;
}
-LyXLayout & LyXTextClass::defaultLayout()
-{
- return operator[](defaultLayoutName());
-}
-
-
string const & LyXTextClass::name() const
{
return name_;