So, when we have an older LyX file, it will look like this:
\begin_inset ERT
status open
\begin_layout Standard
this that
\end_layout
\end_inset
which is now invalid, because ERT uses only PlainLayout. So I had put some code into Text::readParToken, where the layout for a paragraph gets set as it is read:
if (par.forceEmptyLayout()) {
// in this case only the empty layout is allowed
layoutname = tclass.emptyLayoutName();
} else if (par.useEmptyLayout()) {
// in this case, default layout maps to empty layout
if (layoutname == tclass.defaultLayoutName())
layoutname = tclass.emptyLayoutName();
} else {
// otherwise, the empty layout maps to the default
if (layoutname == tclass.emptyLayoutName())
layoutname = tclass.defaultLayoutName();
}
This turns out not to work, because par.forceEmptyLayout() and par.useEmptyLayout() always return false here, because par.inInset() always returns a null pointer, because the paragraph's inset hasn't yet been set when Text::readParagraph() gets called from Text::read() gets called from InsetText::read(). The solution is to set the paragraph's inset when it is created, which means passing a pointer to the various read() routines along the way.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23057
a592a061-630c-0410-9148-
cb99ea01b6c8
}
// read main text
- bool const res = text().read(*this, lex, errorList);
- for_each(text().paragraphs().begin(),
- text().paragraphs().end(),
- bind(&Paragraph::setInsetOwner, _1, &inset()));
+ bool const res = text().read(*this, lex, errorList, &inset());
updateMacros();
updateMacroInstances();
if (layoutname.empty())
layoutname = tclass.defaultLayoutName();
- if (par.forceEmptyLayout())
+ if (par.forceEmptyLayout()) {
// in this case only the empty layout is allowed
layoutname = tclass.emptyLayoutName();
- else if (par.useEmptyLayout()) {
+ } else if (par.useEmptyLayout()) {
// in this case, default layout maps to empty layout
if (layoutname == tclass.defaultLayoutName())
layoutname = tclass.emptyLayoutName();
}
-bool Text::read(Buffer const & buf, Lexer & lex, ErrorList & errorList)
+bool Text::read(Buffer const & buf, Lexer & lex,
+ ErrorList & errorList, Inset * insetPtr)
{
depth_type depth = 0;
Paragraph par;
par.params().depth(depth);
par.setFont(0, Font(inherit_font, buf.params().language));
+ par.setInsetOwner(insetPtr);
pars_.push_back(par);
// FIXME: goddamn InsetTabular makes us pass a Buffer
///
void write(Buffer const & buf, std::ostream & os) const;
/// returns whether we've seen our usual 'end' marker
- bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
+ /// insetPtr is the containing Inset
+ /// FIXME This should really take an InsetText, but it can't yet
+ /// do so because Buffer::inset() returns an Inset and we have no
+ /// access to the InsetText hidden away in Buffer::Impl. This is
+ /// easy enough to fix but will have to wait a bit.
+ bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList,
+ Inset * insetPtr);
/// delete double spaces, leading spaces, and empty paragraphs around old cursor.
/// \retval true if a change has happened and we need a redraw.
: drawFrame_(false), frame_color_(Color_insetframe)
{
paragraphs().push_back(Paragraph());
+ Paragraph & ourpar = paragraphs().back();
if (useEmptyLayout())
- paragraphs().back().layout(bp.getTextClass().emptyLayout());
+ ourpar.layout(bp.getTextClass().emptyLayout());
else
- paragraphs().back().layout(bp.getTextClass().defaultLayout());
- init();
+ ourpar.layout(bp.getTextClass().defaultLayout());
+ ourpar.setInsetOwner(this);
}
drawFrame_ = in.drawFrame_;
frame_color_ = in.frame_color_;
text_.paragraphs() = in.text_.paragraphs();
- init();
+ setParagraphOwner();
}
{}
-void InsetText::init()
+void InsetText::setParagraphOwner()
{
for_each(paragraphs().begin(), paragraphs().end(),
bind(&Paragraph::setInsetOwner, _1, this));
Paragraph oldpar = *paragraphs().begin();
paragraphs().clear();
ErrorList errorList;
- bool res = text_.read(buf, lex, errorList);
- init();
+ bool res = text_.read(buf, lex, errorList, this);
if (!res) {
lex.printError("Missing \\end_inset at this point. "
explicit InsetText(BufferParams const &);
///
InsetText();
+ ///
+ InsetText(InsetText const &);
///
Dimension const dimension(BufferView const &) const;
virtual bool isMacroScope(Buffer const &) const { return true; }
///
virtual bool allowMultiPar() const { return true; }
- ///
- InsetText(InsetText const &);
// Update the counters of this inset and of its contents
virtual void updateLabels(Buffer const &, ParIterator const &);
private:
///
- void init();
-
+ void setParagraphOwner();
///
bool drawFrame_;
///
Paragraph & par = pars[par_offset];
+ // remember to set the inset_owner
+ tmp->setInsetOwner(par.inInset());
// without doing that we get a crash when typing <Return> at the
// end of a paragraph
if (par.useEmptyLayout())
tmp->layout(bparams.getTextClass().emptyLayout());
else
tmp->layout(bparams.getTextClass().defaultLayout());
- // remember to set the inset_owner
- tmp->setInsetOwner(par.inInset());
// layout stays the same with latex-environments
if (keep_layout) {