if (inset->lyxCode() != FLEX_CODE)
// FIXME: Should we verify all InsetCollapsable?
continue;
- docstring const name = inset->name();
- InsetLayout const & il = tclass2.insetlayout(name);
- inset->setLayout(il);
- if (il.labelstring != from_utf8("UNDEFINED"))
+ inset->setLayout(c2);
+ if (inset->getLayout().labelstring != from_utf8("UNDEFINED"))
continue;
// The flex inset is undefined in tclass2
docstring const s = bformat(_(
"Flex inset %1$s is "
"undefined because of class "
"conversion from\n%2$s to %3$s"),
- name, from_utf8(tclass1.name()),
+ inset->name(), from_utf8(tclass1.name()),
from_utf8(tclass2.name()));
// To warn the user that something had to be done.
errorlist.push_back(ErrorItem(
case LFUN_FLEX_INSERT: {
string s = cmd.getArg(0);
- TextClass const & tclass = params.getTextClass();
- InsetLayout const & il = tclass.insetlayout(from_utf8(s));
- return new InsetFlex(params, il);
+ return new InsetFlex(params, params.getTextClassPtr(), s);
}
case LFUN_NOTE_INSERT: {
auto_ptr<Inset> inset;
- TextClass const & tclass = buf.params().getTextClass();
-
lex.next();
string tmptok = lex.getString();
} else if (tmptok == "Flex") {
lex.next();
string s = lex.getString();
- InsetLayout const & il = tclass.insetlayout(from_utf8(s));
- inset.reset(new InsetFlex(buf.params(), il));
+ inset.reset(new InsetFlex(buf.params(),
+ buf.params().getTextClassPtr(), s));
} else if (tmptok == "Branch") {
inset.reset(new InsetBranch(buf.params(),
InsetBranchParams()));
InsetCollapsable::InsetCollapsable(BufferParams const & bp,
- CollapseStatus status, InsetLayout const * il)
- : InsetText(bp), layout_(il), status_(status),
+ CollapseStatus status, TextClassPtr tc)
+ : InsetText(bp), status_(status),
openinlined_(false), autoOpen_(false), mouse_hover_(false)
{
+ setLayout(tc);
setAutoBreakRows(true);
setDrawFrame(true);
setFrameColor(Color_collapsableframe);
InsetCollapsable::InsetCollapsable(InsetCollapsable const & rhs)
: InsetText(rhs),
+ textClass_(rhs.textClass_),
layout_(rhs.layout_),
labelstring_(rhs.labelstring_),
button_dim(rhs.button_dim),
void InsetCollapsable::setLayout(BufferParams const & bp)
{
- setLayout(bp.getTextClass().insetlayout(name()));
+ setLayout(bp.getTextClassPtr());
}
-void InsetCollapsable::setLayout(InsetLayout const & il)
+void InsetCollapsable::setLayout(TextClassPtr tc)
{
- layout_ = &il;
- labelstring_ = layout_->labelstring;
+ textClass_ = tc;
+ if ( tc.get() != 0 ) {
+ layout_ = &tc->insetlayout(name());
+ labelstring_ = layout_->labelstring;
+ } else {
+ layout_ = 0;
+ labelstring_ = _("UNDEFINED");
+ }
setButtonLabel();
}
#include "InsetText.h"
#include "Box.h"
+#include "TextClass.h"
+#include "TextClassPtr.h"
#include <string>
InsetCollapsable(
BufferParams const &,
CollapseStatus status = Inset::Open,
- InsetLayout const * il = 0
+ TextClassPtr tc = TextClassPtr((TextClass *)0)
);
///
InsetCollapsable(InsetCollapsable const & rhs);
docstring name() const { return from_ascii("Collapsable"); }
InsetLayout const & getLayout(BufferParams const &) const
{ return *layout_; }
+ InsetLayout const & getLayout() const
+ { return *layout_; }
///
void setLayout(BufferParams const &);
- /// (Re-)set the character style parameters from \p il
- void setLayout(InsetLayout const & il);
+ /// (Re-)set the character style parameters from \p tc according
+ /// to name()
+ void setLayout(TextClassPtr tc);
///
void read(Buffer const &, Lexer &);
///
///
virtual void resetParagraphsFont();
-protected:
- ///
- InsetLayout const * layout_;
private:
+ /// text class to keep the InsetLayout above in memory
+ TextClassPtr textClass_;
+ /// cache for the layout_. Make sure it is in sync with the text class!
+ InsetLayout const * layout_;
///
Dimension dimensionCollapsed() const;
///
InsetFlex::InsetFlex(BufferParams const & bp,
- InsetLayout const & il)
- : InsetCollapsable(bp, Collapsed, &il)
+ TextClassPtr tc, string const & layoutName)
+ : InsetCollapsable(bp, Collapsed, tc),
+ name_(layoutName)
{
- name_ = il.name;
- packages_ = il.requires;
- preamble_ = il.preamble;
+ setLayout(tc); // again, because now the name is initialized
+ packages_ = getLayout().requires;
+ preamble_ = getLayout().preamble;
}
bool InsetFlex::undefined() const
{
- return layout_->labelstring == from_utf8("UNDEFINED");
+ return getLayout().labelstring == from_utf8("UNDEFINED");
}
ParagraphList::const_iterator end = paragraphs().end();
if (!undefined())
- sgml::openTag(os, layout_->latexname,
- par->getID(buf, runparams) + layout_->latexparam);
+ sgml::openTag(os, getLayout().latexname,
+ par->getID(buf, runparams) + getLayout().latexparam);
for (; par != end; ++par) {
par->simpleDocBookOnePar(buf, os, runparams,
}
if (!undefined())
- sgml::closeTag(os, layout_->latexname);
+ sgml::closeTag(os, getLayout().latexname);
return 0;
}
#include "InsetCollapsable.h"
+using std::string;
namespace lyx {
class InsetFlex : public InsetCollapsable {
public:
///
- InsetFlex(BufferParams const &, InsetLayout const &);
+ InsetFlex(BufferParams const &,
+ TextClassPtr tc, string const & layoutName);
///
docstring name() const { return from_utf8(name_); }