]> git.lyx.org Git - features.git/commitdiff
on the way to a usable insetenv
authorAndré Pönitz <poenitz@gmx.net>
Mon, 19 May 2003 07:12:09 +0000 (07:12 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 19 May 2003 07:12:09 +0000 (07:12 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6975 a592a061-630c-0410-9148-cb99ea01b6c8

15 files changed:
src/ChangeLog
src/buffer.C
src/insets/ChangeLog
src/insets/insetenv.C
src/insets/insetenv.h
src/insets/insettext.C
src/lyxlayout.C
src/lyxlayout.h
src/lyxtextclass.C
src/lyxtextclass.h
src/paragraph.C
src/paragraph_funcs.C
src/paragraph_funcs.h
src/text2.C
src/text3.C

index a364b855c4f26f7e55c76acc43a6ec018f08fc67..54f18be7b95205cbb3c5a6ea49731a79f66f5a2f 100644 (file)
@@ -1,7 +1,24 @@
+
+2003-05-19  André Pönitz  <poenitz@gmx.net>
+
+       * buffer.C:
+       * lyxlayout.[Ch]:
+       * lyxtextclass.[Ch]:
+       * paragraph.C:
+       * paragraph_funcs.[Ch]:
+       * text2.C:
+       * text3.C: more insetenv work
+
 2003-05-16  Alfredo Braunstein  <abraunst@libero.it>
 
        * ParagraphParameters.C (params2string): small bug fixed
 
+2003-05-16  André Pönitz  <poenitz@gmx.net>
+       
+       * debug.C:
+       * bufferview_funcs.C: patch from Kornel Benko to prevent 
+         crash when _(...) is called twice in a statement
+
 2003-05-16  André Pönitz  <poenitz@gmx.net>
        
        * BufferView.C:
index 07b9ccbf2c5b4114e39b737a8aec8d164162ba8c..8783c6a876af91d9cf40ed0a2fc2ae16acccd5f9 100644 (file)
@@ -1046,7 +1046,7 @@ void Buffer::makeLaTeXFile(ostream & os,
                texrow.newline();
        }
 
-       latexParagraphs(this, paragraphs, paragraphs.begin(), paragraphs.end(), os, texrow);
+       latexParagraphs(this, paragraphs, os, texrow, false);
 
        // add this just in case after all the paragraphs
        os << endl;
index 053abfaff9047319fa1cc9624a2fac38e7ee8648..80b522f5991f305c34c96c72162499b689f74b64 100644 (file)
@@ -1,11 +1,16 @@
 
-2003-05-16 André Pönitz  <poenitz@gmx.net>
+2003-05-19  André Pönitz  <poenitz@gmx.net>
+
+       * insetenv.[Ch]:
+       * insettext.C: more insetenv 
+
+2003-05-16  André Pönitz  <poenitz@gmx.net>
 
        * insetcommand.C:
        * insetminimpage.[Ch]:
        * insetcollapsable.[Ch]: fix #832 
 
-2003-05-16 André Pönitz  <poenitz@gmx.net>
+2003-05-16  André Pönitz  <poenitz@gmx.net>
 
        * inset.[Ch]:
        * insetbibitem.[Ch]:
@@ -31,7 +36,7 @@
        * inseturl.[Ch]:
        * updatableinset.[Ch]: edit() -> LFUN_INSET_EDIT
        
-2003-05-13 André Pönitz <poenitz@gmx.net>
+2003-05-13  André Pönitz <poenitz@gmx.net>
 
        * insetbibitem.C:
        * insetcollapsable.C:
@@ -53,7 +58,7 @@
        * insetwrap.C: STRCONV
 
 
-2003-05-12 André Pönitz <poenitz@gmx.net>
+2003-05-12  André Pönitz <poenitz@gmx.net>
 
        * insetcaption.C:
        * insetexternal.C:
@@ -67,7 +72,7 @@
        * insettext.C:
        * insetwwrap.C:  boost::format -> bformat  all over the place
 
-2003-05-05 André Pönitz <poenitz@gmx.net>
+2003-05-05  André Pönitz <poenitz@gmx.net>
 
        * insettext.h: add missing #include <map>
 
@@ -92,7 +97,7 @@
        * insetfloat.h:
        * insetfloat.C: remove unneeded type() function
 
-2003-05-05 André Pönitz <poenitz@gmx.net>
+2003-05-05  André Pönitz <poenitz@gmx.net>
 
        * inset.h:
        * insettext.[Ch]:
        hideInsetCursor(), toggleInsetCursor(), isCursorVisible(). Add
        getCursor(). Remove explicit cursor hides.
 
-2003-05-02 André Pönitz <poenitz@gmx.net>
+2003-05-02  André Pönitz <poenitz@gmx.net>
 
        * insettext.C: remove unneeded &*
 
        (setFont): ditto
        (tabularFeatures): ditto
 
-2003-04-29 André Pönitz <poenitz@gmx.net>
+2003-04-29  André Pönitz <poenitz@gmx.net>
 
        * inset.h: introduce "haveParagraph" from Lars' parlist-14-b.
 
-2003-04-28 André Pönitz <poenitz@gmx.net>
+2003-04-28  André Pönitz <poenitz@gmx.net>
 
        * insettext.[Ch]: part of Lars' Paragraph * -> ParagraphList::iterator
          Changes
        * insettabular.C (string2params): ditto
        * insetwrap.C (string2params): ditto
 
-2003-04-24 André Pönitz <poenitz@gmx.net>
+2003-04-24  André Pönitz <poenitz@gmx.net>
 
        * insetref.C: support for eqref
 
        * insettext.C (edit): replace Dialogs::updateParagraph with
        BufferView::dispatch(LFUN_PARAGRAPH_UPDATE).
 
-2003-03-13 André Pönitz <poenitz@gmx.net>
+2003-03-13  André Pönitz <poenitz@gmx.net>
 
        * Makefile.am: insert insetenv
 
 
        * insettext.C: name change to readToken()
 
-2003-03-11 André Pönitz <poenitz@gmx.net>
+2003-03-11  André Pönitz <poenitz@gmx.net>
 
        * Makefile.am: insert insethfill
 
        * insetinclude.C (loadIfNeeded): ensure loading also works when
        child document is under version control.
 
-2003-02-17 André Pönitz <poenitz@gmx.net>
+2003-02-17  André Pönitz <poenitz@gmx.net>
 
        * insetbib.[Ch]: Adjust access to bibkeys
 
        * insetcite.C (getNatbibLabel): correct logic of when and when not to
        reload the BibTeX keys.
 
-2002-10-11 André Pönitz <poenitz@gmx.net>
+2002-10-11  André Pönitz <poenitz@gmx.net>
 
        * insettext.h: handle LFUN_PRIOR/NEXT
 
index 52e478f35abd47d00b3b75b35b4dbeb349452f5c..e8ba7fde584bc04d6e04ca5611e669a2add47b91 100644 (file)
@@ -14,6 +14,7 @@
 #include "insetenv.h"
 #include "gettext.h"
 #include "lyxtextclass.h"
+#include "paragraph_funcs.h"
 #include "lyxlayout.h"
 #include "bufferparams.h"
 #include "support/LOstream.h"
@@ -26,24 +27,16 @@ using std::endl;
 
 InsetEnvironment::InsetEnvironment
                (BufferParams const & bp, string const & name)
-       : InsetText(bp)
+       : InsetText(bp), layout_(bp.getLyXTextClass()[name])
 {
-       //setLabel(name);
        setInsetName(name);
        autoBreakRows = true;
        drawFrame_ = ALWAYS;
-       // needs more stuff in lyxlayout. coming in later patches.
-       //LyXTextClass const & tc = bp.getLyXTextClass();
-       //LyXLayout_ptr const & layout = tc.getEnv(name);
-       //header_ = layout->latexheader;
-       //footer_ = layout->latexfooter;
-       header_ = "\\begin{" + name + "}";
-       footer_ = "\\end{" + name + "}";
 }
 
 
 InsetEnvironment::InsetEnvironment(InsetEnvironment const & in, bool same_id)
-       : InsetText(in, same_id), header_(in.header_), footer_(in.footer_)
+       : InsetText(in, same_id), layout_(in.layout_)
 {}
 
 
@@ -73,10 +66,18 @@ string const InsetEnvironment::editMessage() const
 
 
 int InsetEnvironment::latex(Buffer const * buf,
-                        ostream & os, bool fragile, bool fp) const
+                        ostream & os, bool fragile, bool) const
 {
-       os << header_;
-       int i = InsetText::latex(buf, os, fragile, fp);
-       os << footer_;
-       return i;
+       os << layout_->latexheader;
+       TexRow texrow;
+       latexParagraphs(buf, paragraphs, os, texrow, fragile,
+               layout_->latexparagraph);
+       os << layout_->latexfooter;
+       return texrow.rows();
+}
+
+
+LyXLayout_ptr const & InsetEnvironment::layout() const
+{
+       return layout_;
 }
index 2f67c2f0a76cd49fc9d4636925f20c9c1b12701b..a42b903d6776bf7f188672235c3f2c6878b4f736 100644 (file)
@@ -13,6 +13,7 @@
 #define INSETENVIRONMENT_H
 
 #include "insettext.h"
+#include "lyxlayout_ptr_fwd.h"
 
 class InsetEnvironment : public InsetText {
 public:
@@ -37,6 +38,8 @@ public:
        ///
        bool isTextInset() const { return true; }
        ///
+       LyXLayout_ptr const & layout() const;
+       ///
        bool needFullRow() const { return true; }
        /** returns true if, when outputing LaTeX, font changes should
             be closed before generating this inset. This is needed for
@@ -44,10 +47,8 @@ public:
        bool noFontChange() const { return true; }
 
 private:
-       /// LaTeX footer
-       string header_;
-       /// LaTeX footer
-       string footer_;
+       /// the layout
+       LyXLayout_ptr layout_;
 };
 
 #endif
index 51eac4683adb56bd16237e49dc98bce23eb5fcf2..85845d18f8fe376baf08ac955656e60e6abe6f2d 100644 (file)
@@ -1467,13 +1467,10 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
 }
 
 
-int InsetText::latex(Buffer const * buf, ostream & os,
-                    bool moving_arg, bool) const
+int InsetText::latex(Buffer const * buf, ostream & os, bool fragile, bool) const
 {
        TexRow texrow;
-       latexParagraphs(buf, paragraphs,
-                       paragraphs.begin(), paragraphs.end(),
-                       os, texrow, moving_arg);
+       latexParagraphs(buf, paragraphs, os, texrow, fragile);
        return texrow.rows();
 }
 
index 9aa7684798a7771fe60cec8aed48654290b3c293..6f20fc49e899c015caea26e456a4817473aa7eee 100644 (file)
@@ -59,6 +59,7 @@ enum LayoutTags {
        LT_LATEXTYPE,
        LT_LATEXHEADER,
        LT_LATEXFOOTER,
+       LT_LATEXPARAGRAPH,
        LT_LEFTMARGIN,
        LT_NEED_PROTECT,
        LT_NEWLINE,
@@ -107,6 +108,7 @@ LyXLayout::LyXLayout ()
        newline_allowed = true;
        free_spacing = false;
        pass_thru = false;
+       is_environment = false;
 }
 
 
@@ -140,6 +142,7 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
                { "latexfooter",                LT_LATEXFOOTER },
                { "latexheader",                LT_LATEXHEADER },
                { "latexname",          LT_LATEXNAME },
+               { "latexparagraph",             LT_LATEXPARAGRAPH },
                { "latexparam",         LT_LATEXPARAM },
                { "latextype",          LT_LATEXTYPE },
                { "leftmargin",         LT_LEFTMARGIN },
@@ -236,24 +239,29 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
                        }
                        break;
 
-               case LT_MARGIN:         // Margin style definition.
+               case LT_MARGIN:         // margin style definition.
                        readMargin(lexrc);
                        break;
 
-               case LT_LATEXTYPE:      // Latex style definition.
+               case LT_LATEXTYPE:      // LaTeX style definition.
                        readLatexType(lexrc);
                        break;
 
-               case LT_LATEXHEADER:    // Latex style definition.
+               case LT_LATEXHEADER:    // header for environments
                        lexrc.next();
                        latexheader = lexrc.getString();
                        break;
 
-               case LT_LATEXFOOTER:    // Latex style definition.
+               case LT_LATEXFOOTER:    // footer for environments
                        lexrc.next();
                        latexfooter = lexrc.getString();
                        break;
 
+               case LT_LATEXPARAGRAPH:
+                       lexrc.next();
+                       latexparagraph = lexrc.getString();
+                       break;
+
                case LT_INTITLE:
                        intitle = lexrc.next() && lexrc.getInteger();
                        break;
index 079b79a85374fda99ad08ad6d449557fd9db3492..1700811cf8ad62a83c641f6f08f1bfdc313f19f0 100644 (file)
@@ -136,10 +136,14 @@ public:
        bool free_spacing;
        ///
        bool pass_thru;
+       ///
+       bool is_environment;
        /// for new environment insets
        string latexheader;
        /// for new environment insets
        string latexfooter;
+       /// for new environment insets
+       string latexparagraph;
 
        /** true when the fragile commands in the paragraph need to be
            \protect'ed. */
index 462e9ed74c58c21a820afd09e37ca41f02d239c8..f406915a858adc943093c714759d3e768885ea3b 100644 (file)
@@ -215,6 +215,7 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                        }
                        break;
 
+               case TC_ENVIRONMENT:
                case TC_STYLE:
                        if (lexrc.next()) {
                                string const name = subst(lexrc.getString(),
@@ -225,6 +226,8 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                                } else {
                                        LyXLayout lay;
                                        lay.setName(name);
+                                       if (le == TC_ENVIRONMENT)
+                                               lay.is_environment = true;
                                        if (!(error = do_readStyle(lexrc, lay)))
                                                layoutlist_.push_back
                                                        (boost::shared_ptr<LyXLayout>(new LyXLayout(lay)));
@@ -243,29 +246,6 @@ bool LyXTextClass::Read(string const & filename, bool merge)
                        }
                        break;
 
-               case TC_ENVIRONMENT:
-                       if (lexrc.next()) {
-                               string const name = subst(lexrc.getString(),
-                                                   '_', ' ');
-                               if (hasLayout(name)) {
-                                       LyXLayout * lay = operator[](name).get();
-                                       error = do_readStyle(lexrc, *lay);
-                               } else {
-                                       LyXLayout lay;
-                                       lay.setName(name);
-                                       if (!(error = do_readStyle(lexrc, lay)))
-                                               envlist_.push_back
-                                                       (boost::shared_ptr<LyXLayout>(new LyXLayout(lay)));
-                                       else
-                                               lexrc.printError("Problems reading environment: `$$Token'.");
-                               }
-                       }
-                       else {
-                               lexrc.printError("No name given for style: `$$Token'.");
-                               error = true;
-                       }
-                       break;
-
                case TC_NOSTYLE:
                        if (lexrc.next()) {
                                string const style = subst(lexrc.getString(),
@@ -772,6 +752,7 @@ bool LyXTextClass::hasLayout(string const & n) const
 }
 
 
+
 LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const
 {
        lyx::Assert(!n.empty());
@@ -796,6 +777,9 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const
                lyxerr << "We failed to find the layout '" << name
                       << "' in the layout list. You MUST investigate!"
                       << endl;
+               for (LayoutList::const_iterator it = layoutlist_.begin();
+                        it != layoutlist_.end(); ++it)
+                       lyxerr  << " " << it->get()->name() << endl;
 
                // we require the name to exist
                lyx::Assert(false);
@@ -808,27 +792,6 @@ LyXLayout_ptr const & LyXTextClass::operator[](string const & n) const
 }
 
 
-LyXLayout_ptr const & LyXTextClass::getEnv(string const & name) const
-{
-       lyx::Assert(!name.empty());
-
-       if (name.empty())
-               lyxerr << "LyXTextClass::getEnv() called with empty n" << endl;
-
-       LayoutList::const_iterator cit =
-               find_if(envlist_.begin(), envlist_.end(), compare_name(name));
-
-       if (cit == envlist_.end()) {
-               lyxerr << "We failed to find the environment '" << name
-                      << "' in the layout list. You MUST investigate!"
-                      << endl;
-               // we require the name to exist
-               lyx::Assert(false);
-       }
-
-       return *cit;
-}
-
 
 bool LyXTextClass::delete_layout(string const & name)
 {
index bc93f8d6fe40950ab5a8c51373f22710bb203bc8..70817d1ad83e5a95d6b4aa59e2f851d866adf0f8 100644 (file)
@@ -65,8 +65,6 @@ public:
 
        ///
        LyXLayout_ptr const & operator[](string const & vname) const;
-       ///
-       LyXLayout_ptr const & getEnv(string const & vname) const;
 
        /// Sees to that the textclass structure has been loaded
        bool load() const;
@@ -155,8 +153,6 @@ private:
        ///
        bool delete_layout(string const &);
        ///
-       bool delete_env(string const &);
-       ///
        bool do_readStyle(LyXLex &, LyXLayout &);
        /// Layout file name
        string name_;
@@ -210,9 +206,6 @@ private:
        /// Paragraph styles used in this layout
        LayoutList layoutlist_;
 
-       /// Environment styles used in this layout
-       LayoutList envlist_;
-
        /// available types of float, eg. figure, algorithm.
        boost::shared_ptr<FloatList> floatlist_;
 
index 321c50bd223aa3d0f1dd78529ad53c8fc9b2b155..d4f19258b3d44582770eff9080c522b59454ad8d 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "insets/insetbibitem.h"
 #include "insets/insetoptarg.h"
+#include "insets/insetenv.h"
 
 #include "support/filetools.h"
 #include "support/lstrings.h"
@@ -1405,6 +1406,9 @@ int Paragraph::id() const
 
 LyXLayout_ptr const & Paragraph::layout() const
 {
+       Inset * inset = inInset();
+       if (inset && inset->lyxCode() == Inset::ENVIRONMENT_CODE) 
+               return static_cast<InsetEnvironment*>(inset)->layout();
        return layout_;
 }
 
index ca99e26a538716bf02e80b3e8ddc8dd99a2f48fa..9ee4573abe36437807fa79bc11e5800f5b7cc7a8 100644 (file)
@@ -237,8 +237,7 @@ bool isFirstInSequence(ParagraphList::iterator pit,
 }
 
 
-int getEndLabel(ParagraphList::iterator p,
-               ParagraphList const & plist)
+int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist)
 {
        ParagraphList::iterator pit = p;
        Paragraph::depth_type par_depth = p->getDepth();
@@ -280,7 +279,8 @@ TeXOnePar(Buffer const * buf,
          ParagraphList const & paragraphs,
          ParagraphList::iterator pit,
          ostream & os, TexRow & texrow,
-         bool moving_arg);
+         bool moving_arg,
+         string const & everypar = string());
 
 
 ParagraphList::iterator
@@ -436,9 +436,11 @@ TeXOnePar(Buffer const * buf,
          ParagraphList const & paragraphs,
          ParagraphList::iterator pit,
          ostream & os, TexRow & texrow,
-         bool moving_arg)
+         bool moving_arg,
+         string const & everypar)
 {
-       lyxerr[Debug::LATEX] << "TeXOnePar...     " << &*pit << endl;
+       lyxerr[Debug::LATEX] << "TeXOnePar...     " << &*pit << " '" << everypar
+<< "'" << endl;
        BufferParams const & bparams = buf->params;
 
        Inset const * in = pit->inInset();
@@ -559,6 +561,7 @@ TeXOnePar(Buffer const * buf,
                break;
        }
 
+       os << everypar;
        bool need_par = pit->simpleTeXOnePar(buf, bparams,
                                             outerFont(pit, paragraphs),
                                             os, texrow, moving_arg);
@@ -682,15 +685,16 @@ TeXOnePar(Buffer const * buf,
 //
 void latexParagraphs(Buffer const * buf,
                     ParagraphList const & paragraphs,
-                    ParagraphList::iterator par,
-                    ParagraphList::iterator endpar,
-                    ostream & ofs,
+                    ostream & os,
                     TexRow & texrow,
-                    bool moving_arg)
+                    bool moving_arg,
+         string const & everypar)
 {
        bool was_title = false;
        bool already_title = false;
        LyXTextClass const & tclass = buf->params.getLyXTextClass();
+       ParagraphList::iterator par = paragraphs.begin();
+       ParagraphList::iterator endpar = paragraphs.end();
 
        // if only_body
        while (par != endpar) {
@@ -710,7 +714,7 @@ void latexParagraphs(Buffer const * buf,
                                } else if (!was_title) {
                                        was_title = true;
                                        if (tclass.titletype() == TITLE_ENVIRONMENT) {
-                                               ofs << "\\begin{"
+                                               os << "\\begin{"
                                                    << tclass.titlename()
                                                    << "}\n";
                                                texrow.newline();
@@ -718,11 +722,11 @@ void latexParagraphs(Buffer const * buf,
                                }
                        } else if (was_title && !already_title) {
                                if (tclass.titletype() == TITLE_ENVIRONMENT) {
-                                       ofs << "\\end{" << tclass.titlename()
+                                       os << "\\end{" << tclass.titlename()
                                            << "}\n";
                                }
                                else {
-                                       ofs << "\\" << tclass.titlename()
+                                       os << "\\" << tclass.titlename()
                                            << "\n";
                                }
                                texrow.newline();
@@ -730,25 +734,30 @@ void latexParagraphs(Buffer const * buf,
                                was_title = false;
                        }
 
-                       if (layout->isEnvironment() ||
+                       if (layout->is_environment) {
+                               par = TeXOnePar(buf, paragraphs, par, os, texrow,
+                                               moving_arg, everypar);
+                       } else if (layout->isEnvironment() ||
                                !par->params().leftIndent().zero())
                        {
-                               par = TeXEnvironment(buf, paragraphs, par, ofs, texrow);
+                               par = TeXEnvironment(buf, paragraphs, par, os, texrow);
                        } else {
-                               par = TeXOnePar(buf, paragraphs, par, ofs, texrow, moving_arg);
+                               par = TeXOnePar(buf, paragraphs, par, os, texrow,
+                                               moving_arg, everypar);
                        }
                } else {
-                       par = TeXOnePar(buf, paragraphs, par, ofs, texrow, moving_arg);
+                       par = TeXOnePar(buf, paragraphs, par, os, texrow,
+                                       moving_arg, everypar);
                }
        }
        // It might be that we only have a title in this document
        if (was_title && !already_title) {
                if (tclass.titletype() == TITLE_ENVIRONMENT) {
-                       ofs << "\\end{" << tclass.titlename()
+                       os << "\\end{" << tclass.titlename()
                            << "}\n";
                }
                else {
-                       ofs << "\\" << tclass.titlename()
+                       os << "\\" << tclass.titlename()
                            << "\n";
                                }
                texrow.newline();
index 3270494e658c20e832b3209872b28d550967a7d5..4c78eceb5e8c124469d45855241005a48b47e1d3 100644 (file)
@@ -63,11 +63,10 @@ int getEndLabel(ParagraphList::iterator pit,
 
 void latexParagraphs(Buffer const * buf,
                     ParagraphList const & paragraphs,
-                    ParagraphList::iterator par,
-                    ParagraphList::iterator endpar,
                     std::ostream & ofs,
                     TexRow & texrow,
-                    bool moving_arg = false);
+                    bool moving_arg,
+         string const & everypar = string());
 
 /// read a paragraph from a .lyx file. Returns number of unrecognised tokens
 int readParagraph(Buffer & buf, Paragraph & par, LyXLex & lex);
index 9dec90a8d0b46c8f2c2abd1743ba934331c66f01..92939fcae503430b8c712880bd288a5751bae442 100644 (file)
@@ -35,6 +35,7 @@
 #include "paragraph_funcs.h"
 
 #include "insets/insetbibitem.h"
+#include "insets/insetenv.h"
 #include "insets/insetfloat.h"
 #include "insets/insetwrap.h"
 
@@ -425,22 +426,41 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
 // set layout over selection and make a total rebreak of those paragraphs
 void LyXText::setLayout(string const & layout)
 {
-       LyXCursor tmpcursor = cursor;  /* store the current cursor  */
+       LyXCursor tmpcursor = cursor;  // store the current cursor 
 
        // if there is no selection just set the layout
-       // of the current paragraph  */
+       // of the current paragraph 
        if (!selection.set()) {
                selection.start = cursor;  // dummy selection
                selection.end = cursor;
        }
+
+       // special handling of new environment insets
+       BufferParams const & params = bv()->buffer()->params;
+       LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
+       if (lyxlayout->is_environment) {
+               // move everything in a new environment inset
+               lyxerr << "setting layout " << layout << endl;
+               bv()->owner()->dispatch(FuncRequest(LFUN_HOME));
+               bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
+               bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
+               Inset * inset = new InsetEnvironment(params, layout);
+               if (bv()->insertInset(inset)) {
+                       //inset->edit(bv());
+                       //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
+               }
+               else
+                       delete inset;
+               return;
+       }
+
        ParagraphList::iterator endpit = setLayout(cursor, selection.start,
                                                   selection.end, layout);
        redoParagraphs(selection.start, endpit);
 
        // we have to reset the selection, because the
        // geometry could have changed
-       setCursor(selection.start.par(),
-                 selection.start.pos(), false);
+       setCursor(selection.start.par(), selection.start.pos(), false);
        selection.cursor = cursor;
        setCursor(selection.end.par(), selection.end.pos(), false);
        updateCounters();
index d838a18b3892d70ad6d948e9425e58523b00193f..cab4f23c0e02c606333e781c8baff5eea4fff703 100644 (file)
@@ -1124,6 +1124,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                }
 
                bool change_layout = (current_layout != layout);
+
                if (!change_layout && selection.set() &&
                        selection.start.par() != selection.end.par())
                {
@@ -1137,6 +1138,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                                ++spit;
                        }
                }
+
                if (change_layout) {
                        current_layout = layout;
                        update();