mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 21:40:19 +00:00
Add empty InsetLayout for undefined cases. Should avoid possible bugs caused by empty layout_ pointer in InsetCollapsable.
NOTE: Some cleanup is needed here, and I'll do it shortly. Doing it properly, though, requires making InsetLayout a proper class. (At the moment, it's just a C-style struct.) That should be committed separately. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23103 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f9cb8309a3
commit
a51525c416
@ -449,7 +449,7 @@ void switchBetweenClasses(TextClassPtr const & oldone,
|
||||
// FIXME: Should we verify all InsetCollapsable?
|
||||
continue;
|
||||
inset->setLayout(newone);
|
||||
if (inset->getLayout().labelstring != from_utf8("UNDEFINED"))
|
||||
if (!inset->undefined())
|
||||
continue;
|
||||
// The flex inset is undefined in newtc
|
||||
docstring const s = bformat(_(
|
||||
|
@ -133,6 +133,9 @@ TextClass::TextClass(string const & fn, string const & cln,
|
||||
docstring const TextClass::emptylayout_ = from_ascii("PlainLayout");
|
||||
|
||||
|
||||
InsetLayout TextClass::empty_insetlayout_;
|
||||
|
||||
|
||||
bool TextClass::isTeXClassAvailable() const
|
||||
{
|
||||
return texClassAvail_;
|
||||
@ -1168,12 +1171,7 @@ InsetLayout const & TextClass::insetlayout(docstring const & name) const
|
||||
break;
|
||||
n = n.substr(0,i);
|
||||
}
|
||||
static InsetLayout empty;
|
||||
empty.labelstring = from_utf8("UNDEFINED");
|
||||
empty.labelfont = sane_font;
|
||||
empty.labelfont.setColor(Color_error);
|
||||
empty.bgcolor = Color_error;
|
||||
return empty;
|
||||
return empty_insetlayout_;
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,6 +182,8 @@ public:
|
||||
int max_toclevel() const;
|
||||
/// returns true if the class has a ToC structure
|
||||
bool hasTocLevels() const;
|
||||
///
|
||||
static InsetLayout const & emptyInsetLayout() { return empty_insetlayout_; }
|
||||
private:
|
||||
///
|
||||
bool deleteLayout(docstring const &);
|
||||
@ -265,6 +267,8 @@ private:
|
||||
int min_toclevel_;
|
||||
/// The maximal TocLevel of sectioning layouts
|
||||
int max_toclevel_;
|
||||
///
|
||||
static InsetLayout empty_insetlayout_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -132,7 +132,7 @@ void InsetCollapsable::setLayout(TextClassPtr tc)
|
||||
layout_ = &tc->insetlayout(name());
|
||||
labelstring_ = layout_->labelstring;
|
||||
} else {
|
||||
layout_ = 0;
|
||||
layout_ = &TextClass::emptyInsetLayout();
|
||||
labelstring_ = _("UNDEFINED");
|
||||
}
|
||||
|
||||
@ -885,4 +885,11 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const
|
||||
}
|
||||
|
||||
|
||||
bool InsetCollapsable::undefined() const
|
||||
{
|
||||
std::string const & n = getLayout().name;
|
||||
return n.empty() || n == TextClass::emptyInsetLayout().name;
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -161,7 +161,9 @@ public:
|
||||
virtual bool forceLTR() const { return layout_->forceltr; }
|
||||
///
|
||||
virtual bool useEmptyLayout() const { return true; }
|
||||
|
||||
/// Is this inset's layout defined in the document's textclass?
|
||||
/// May be wrong after textclass change or paste from another document
|
||||
bool undefined() const;
|
||||
protected:
|
||||
///
|
||||
virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
|
||||
|
@ -61,12 +61,6 @@ Inset * InsetFlex::clone() const
|
||||
}
|
||||
|
||||
|
||||
bool InsetFlex::undefined() const
|
||||
{
|
||||
return getLayout().labelstring == from_utf8("UNDEFINED");
|
||||
}
|
||||
|
||||
|
||||
docstring const InsetFlex::editMessage() const
|
||||
{
|
||||
return _("Opened Flex Inset");
|
||||
|
@ -31,9 +31,6 @@ public:
|
||||
///
|
||||
docstring name() const { return from_utf8(name_); }
|
||||
|
||||
/// Is this character style defined in the document's textclass?
|
||||
/// May be wrong after textclass change or paste from another document
|
||||
bool undefined() const;
|
||||
///
|
||||
virtual docstring const editMessage() const;
|
||||
///
|
||||
|
@ -23,6 +23,12 @@ namespace lyx {
|
||||
///
|
||||
class InsetLayout {
|
||||
public:
|
||||
InsetLayout() :
|
||||
name("undefined"),
|
||||
labelstring(from_utf8("UNDEFINED")),
|
||||
font(sane_font), labelfont(sane_font),
|
||||
bgcolor(Color_error)
|
||||
{ labelfont.setColor(Color_error); };
|
||||
std::string name;
|
||||
std::string lyxtype;
|
||||
docstring labelstring;
|
||||
|
Loading…
Reference in New Issue
Block a user