]> git.lyx.org Git - features.git/commitdiff
It used to be that things like InsetFlex, InsetCaption, and the like used the default...
authorRichard Heck <rgheck@comcast.net>
Tue, 19 Feb 2008 02:35:07 +0000 (02:35 +0000)
committerRichard Heck <rgheck@comcast.net>
Tue, 19 Feb 2008 02:35:07 +0000 (02:35 +0000)
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
src/Text.cpp
src/Text.h
src/insets/InsetText.cpp
src/insets/InsetText.h
src/paragraph_funcs.cpp

index 7858c42ce8f15c324cfd2b2d48a03997ca866bd4..c95054b72bed0edac67981d8b09f7e5aaadffda6 100644 (file)
@@ -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();
index de1ae45843d484ba558e118a5bfae58cc6326b86..50ac94aa08d1d212131a7bb606e7b2313cfa9f40 100644 (file)
@@ -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
index eba2b153a71123a7a069ab6441088a1d57eaba94..387cc6e428f17b7a9f4bc0d928c950c465e8dd4a 100644 (file)
@@ -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.
index 04841ff780c763e1fd3a28aeb0dd02eb8e11c256..f06381ca407336337707782cfa53ae8324987b17 100644 (file)
@@ -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. "
index fcb776296dd0510f2ad7fd86700795bb1e108fc7..561b33f698170363643e1b1b459f3b9d0481a4cd 100644 (file)
@@ -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_;
        ///
index 278478f483a0d06c9bdb19cd643fe86b86eb2c09..4dece7ae03eefd46603579a4b2818baacef13bf4 100644 (file)
@@ -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 <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) {