Rename DocumentCLass:plainInsetLayout() to InsetLayout::undefined()

This makes the code easier to understand.
This commit is contained in:
Jean-Marc Lasgouttes 2024-06-20 18:26:50 +02:00
parent c4531741a9
commit 608929a857
7 changed files with 17 additions and 16 deletions

View File

@ -883,10 +883,10 @@ void switchBetweenClasses(DocumentClassConstPtr oldone,
docstring const layoutName = iit->layoutName(); docstring const layoutName = iit->layoutName();
docstring const & n = newone->insetLayout(layoutName).name(); docstring const & n = newone->insetLayout(layoutName).name();
bool const is_undefined = n.empty() || bool const is_undefined = n.empty() ||
n == DocumentClass::plainInsetLayout().name(); n == InsetLayout::undefined().name();
docstring const & oldn = oldone->insetLayout(layoutName).name(); docstring const & oldn = oldone->insetLayout(layoutName).name();
bool const was_undefined = oldn.empty() || bool const was_undefined = oldn.empty() ||
oldn == DocumentClass::plainInsetLayout().name(); oldn == InsetLayout::undefined().name();
if (!is_undefined || was_undefined) if (!is_undefined || was_undefined)
continue; continue;

View File

@ -1869,13 +1869,7 @@ InsetLayout const & DocumentClass::insetLayout(docstring const & name) const
n = n.substr(0, i); n = n.substr(0, i);
} }
// Layout "name" not found. // Layout "name" not found.
return plainInsetLayout(); return InsetLayout::undefined();
}
InsetLayout const & DocumentClass::plainInsetLayout() {
static const InsetLayout plain_insetlayout_;
return plain_insetlayout_;
} }

View File

@ -448,8 +448,6 @@ public:
/// If that doesn't work either, an empty object returns (shouldn't /// If that doesn't work either, an empty object returns (shouldn't
/// happen). -- Idea JMarc, comment MV /// happen). -- Idea JMarc, comment MV
InsetLayout const & insetLayout(docstring const & name) const; InsetLayout const & insetLayout(docstring const & name) const;
/// a plain inset layout for use as a default
static InsetLayout const & plainInsetLayout();
/// add a new layout \c name if it does not exist in layoutlist_ /// add a new layout \c name if it does not exist in layoutlist_
/// \return whether we had to add one. /// \return whether we had to add one.
bool addLayoutIfNeeded(docstring const & name) const; bool addLayoutIfNeeded(docstring const & name) const;

View File

@ -241,7 +241,7 @@ docstring Inset::layoutName() const
InsetLayout const & Inset::getLayout() const InsetLayout const & Inset::getLayout() const
{ {
if (!buffer_) if (!buffer_)
return DocumentClass::plainInsetLayout(); return InsetLayout::undefined();
return buffer().params().documentClass().insetLayout(layoutName()); return buffer().params().documentClass().insetLayout(layoutName());
} }
@ -622,7 +622,7 @@ bool Inset::covers(BufferView const & bv, int x, int y) const
bool Inset::undefined() const bool Inset::undefined() const
{ {
docstring const & n = getLayout().name(); docstring const & n = getLayout().name();
return n.empty() || n == DocumentClass::plainInsetLayout().name(); return n.empty() || n == InsetLayout::undefined().name();
} }

View File

@ -49,7 +49,7 @@ InsetFlex::InsetFlex(InsetFlex const & in)
InsetLayout const & InsetFlex::getLayout() const InsetLayout const & InsetFlex::getLayout() const
{ {
if (!buffer_) if (!buffer_)
return DocumentClass::plainInsetLayout(); return InsetLayout::undefined();
DocumentClass const & dc = buffer().params().documentClass(); DocumentClass const & dc = buffer().params().documentClass();
docstring const dname = from_utf8(name_); docstring const dname = from_utf8(name_);
@ -102,7 +102,7 @@ bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
InsetLyXType const type = InsetLyXType const type =
translateLyXType(to_utf8(cmd.argument())); translateLyXType(to_utf8(cmd.argument()));
if (il.lyxtype() == type if (il.lyxtype() == type
|| (il.name() == DocumentClass::plainInsetLayout().name() || (il.name() == InsetLayout::undefined().name()
&& type == InsetLyXType::CHARSTYLE)) { && type == InsetLyXType::CHARSTYLE)) {
FuncRequest temp_cmd(cmd.action()); FuncRequest temp_cmd(cmd.action());
return InsetCollapsible::getStatus(cur, temp_cmd, flag); return InsetCollapsible::getStatus(cur, temp_cmd, flag);
@ -127,7 +127,7 @@ void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
translateLyXType(to_utf8(cmd.argument())); translateLyXType(to_utf8(cmd.argument()));
if (il.lyxtype() == type if (il.lyxtype() == type
|| (il.name() == DocumentClass::plainInsetLayout().name() || (il.name() == InsetLayout::undefined().name()
&& type == InsetLyXType::CHARSTYLE)) { && type == InsetLyXType::CHARSTYLE)) {
FuncRequest temp_cmd(cmd.action()); FuncRequest temp_cmd(cmd.action());
InsetCollapsible::doDispatch(cur, temp_cmd); InsetCollapsible::doDispatch(cur, temp_cmd);

View File

@ -59,6 +59,12 @@ InsetLaTeXType translateLaTeXType(std::string const & str)
} // namespace } // namespace
InsetLayout const & InsetLayout::undefined() {
static const InsetLayout undefined_;
return undefined_;
}
bool InsetLayout::read(Lexer & lex, TextClass const & tclass, bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
bool validating) bool validating)
{ {

View File

@ -56,6 +56,9 @@ class InsetLayout {
public: public:
/// ///
InsetLayout() { labelfont_.setColor(Color_insetlabel); } InsetLayout() { labelfont_.setColor(Color_insetlabel); }
/// a plain inset layout for when there is no inset layout
static InsetLayout const & undefined();
/// ///
bool read(support::Lexer & lexrc, TextClass const & tclass, bool read(support::Lexer & lexrc, TextClass const & tclass,
bool validating = false); bool validating = false);