From 7dcffe09f42c7f2b17c018ba69c53e1fd6b00c46 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Tue, 19 Feb 2008 02:35:07 +0000 Subject: [PATCH] It used to be that things like InsetFlex, InsetCaption, and the like used the default layout, whatever that is---usually Standard. That gave rise to bug 2178, the solution to which is to define a new empty layout, which insets like these use instead of the default. See r22966. 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 --- src/Buffer.cpp | 5 +---- src/Text.cpp | 8 +++++--- src/Text.h | 8 +++++++- src/insets/InsetText.cpp | 14 +++++++------- src/insets/InsetText.h | 7 +++---- src/paragraph_funcs.cpp | 4 ++-- 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 7858c42ce8..c95054b72b 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -567,10 +567,7 @@ bool Buffer::readDocument(Lexer & lex) } // 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(); diff --git a/src/Text.cpp b/src/Text.cpp index de1ae45843..50ac94aa08 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -101,10 +101,10 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex, 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(); @@ -1159,7 +1159,8 @@ void Text::write(Buffer const & buf, ostream & os) const } -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; @@ -1188,6 +1189,7 @@ bool Text::read(Buffer const & buf, Lexer & lex, ErrorList & errorList) 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 diff --git a/src/Text.h b/src/Text.h index eba2b153a7..387cc6e428 100644 --- a/src/Text.h +++ b/src/Text.h @@ -259,7 +259,13 @@ public: /// 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. diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 04841ff780..f06381ca40 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -69,11 +69,12 @@ InsetText::InsetText(BufferParams const & bp) : 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); } @@ -84,7 +85,7 @@ InsetText::InsetText(InsetText const & in) drawFrame_ = in.drawFrame_; frame_color_ = in.frame_color_; text_.paragraphs() = in.text_.paragraphs(); - init(); + setParagraphOwner(); } @@ -92,7 +93,7 @@ InsetText::InsetText() {} -void InsetText::init() +void InsetText::setParagraphOwner() { for_each(paragraphs().begin(), paragraphs().end(), bind(&Paragraph::setInsetOwner, _1, this)); @@ -145,8 +146,7 @@ void InsetText::read(Buffer const & buf, Lexer & lex) 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. " diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index fcb776296d..561b33f698 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -40,6 +40,8 @@ public: explicit InsetText(BufferParams const &); /// InsetText(); + /// + InsetText(InsetText const &); /// Dimension const dimension(BufferView const &) const; @@ -133,8 +135,6 @@ public: 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 &); @@ -147,8 +147,7 @@ protected: private: /// - void init(); - + void setParagraphOwner(); /// bool drawFrame_; /// diff --git a/src/paragraph_funcs.cpp b/src/paragraph_funcs.cpp index 278478f483..4dece7ae03 100644 --- a/src/paragraph_funcs.cpp +++ b/src/paragraph_funcs.cpp @@ -72,14 +72,14 @@ void breakParagraph(BufferParams const & bparams, Paragraph & par = pars[par_offset]; + // remember to set the inset_owner + tmp->setInsetOwner(par.inInset()); // without doing that we get a crash when typing 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) { -- 2.39.2