From ff98dcea08c23fe70daf8877fb05593e3262057d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 19 May 2003 07:12:09 +0000 Subject: [PATCH] on the way to a usable insetenv git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6975 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 17 ++++++++++++++ src/buffer.C | 2 +- src/insets/ChangeLog | 33 +++++++++++++++------------ src/insets/insetenv.C | 31 ++++++++++++------------- src/insets/insetenv.h | 9 ++++---- src/insets/insettext.C | 7 ++---- src/lyxlayout.C | 16 +++++++++---- src/lyxlayout.h | 4 ++++ src/lyxtextclass.C | 51 ++++++------------------------------------ src/lyxtextclass.h | 7 ------ src/paragraph.C | 4 ++++ src/paragraph_funcs.C | 45 ++++++++++++++++++++++--------------- src/paragraph_funcs.h | 5 ++--- src/text2.C | 28 +++++++++++++++++++---- src/text3.C | 2 ++ 15 files changed, 142 insertions(+), 119 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index a364b855c4..54f18be7b9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,24 @@ + +2003-05-19 André Pönitz + + * buffer.C: + * lyxlayout.[Ch]: + * lyxtextclass.[Ch]: + * paragraph.C: + * paragraph_funcs.[Ch]: + * text2.C: + * text3.C: more insetenv work + 2003-05-16 Alfredo Braunstein * ParagraphParameters.C (params2string): small bug fixed +2003-05-16 André Pönitz + + * 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 * BufferView.C: diff --git a/src/buffer.C b/src/buffer.C index 07b9ccbf2c..8783c6a876 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -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; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 053abfaff9..80b522f599 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,11 +1,16 @@ -2003-05-16 André Pönitz +2003-05-19 André Pönitz + + * insetenv.[Ch]: + * insettext.C: more insetenv + +2003-05-16 André Pönitz * insetcommand.C: * insetminimpage.[Ch]: * insetcollapsable.[Ch]: fix #832 -2003-05-16 André Pönitz +2003-05-16 André Pönitz * inset.[Ch]: * insetbibitem.[Ch]: @@ -31,7 +36,7 @@ * inseturl.[Ch]: * updatableinset.[Ch]: edit() -> LFUN_INSET_EDIT -2003-05-13 André Pönitz +2003-05-13 André Pönitz * insetbibitem.C: * insetcollapsable.C: @@ -53,7 +58,7 @@ * insetwrap.C: STRCONV -2003-05-12 André Pönitz +2003-05-12 André Pönitz * 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 +2003-05-05 André Pönitz * insettext.h: add missing #include @@ -92,7 +97,7 @@ * insetfloat.h: * insetfloat.C: remove unneeded type() function -2003-05-05 André Pönitz +2003-05-05 André Pönitz * inset.h: * insettext.[Ch]: @@ -113,7 +118,7 @@ hideInsetCursor(), toggleInsetCursor(), isCursorVisible(). Add getCursor(). Remove explicit cursor hides. -2003-05-02 André Pönitz +2003-05-02 André Pönitz * insettext.C: remove unneeded &* @@ -129,11 +134,11 @@ (setFont): ditto (tabularFeatures): ditto -2003-04-29 André Pönitz +2003-04-29 André Pönitz * inset.h: introduce "haveParagraph" from Lars' parlist-14-b. -2003-04-28 André Pönitz +2003-04-28 André Pönitz * insettext.[Ch]: part of Lars' Paragraph * -> ParagraphList::iterator Changes @@ -155,7 +160,7 @@ * insettabular.C (string2params): ditto * insetwrap.C (string2params): ditto -2003-04-24 André Pönitz +2003-04-24 André Pönitz * insetref.C: support for eqref @@ -409,7 +414,7 @@ * insettext.C (edit): replace Dialogs::updateParagraph with BufferView::dispatch(LFUN_PARAGRAPH_UPDATE). -2003-03-13 André Pönitz +2003-03-13 André Pönitz * Makefile.am: insert insetenv @@ -439,7 +444,7 @@ * insettext.C: name change to readToken() -2003-03-11 André Pönitz +2003-03-11 André Pönitz * Makefile.am: insert insethfill @@ -754,7 +759,7 @@ * insetinclude.C (loadIfNeeded): ensure loading also works when child document is under version control. -2003-02-17 André Pönitz +2003-02-17 André Pönitz * insetbib.[Ch]: Adjust access to bibkeys @@ -955,7 +960,7 @@ * insetcite.C (getNatbibLabel): correct logic of when and when not to reload the BibTeX keys. -2002-10-11 André Pönitz +2002-10-11 André Pönitz * insettext.h: handle LFUN_PRIOR/NEXT diff --git a/src/insets/insetenv.C b/src/insets/insetenv.C index 52e478f35a..e8ba7fde58 100644 --- a/src/insets/insetenv.C +++ b/src/insets/insetenv.C @@ -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_; } diff --git a/src/insets/insetenv.h b/src/insets/insetenv.h index 2f67c2f0a7..a42b903d67 100644 --- a/src/insets/insetenv.h +++ b/src/insets/insetenv.h @@ -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 diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 51eac4683a..85845d18f8 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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(); } diff --git a/src/lyxlayout.C b/src/lyxlayout.C index 9aa7684798..6f20fc49e8 100644 --- a/src/lyxlayout.C +++ b/src/lyxlayout.C @@ -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; diff --git a/src/lyxlayout.h b/src/lyxlayout.h index 079b79a853..1700811cf8 100644 --- a/src/lyxlayout.h +++ b/src/lyxlayout.h @@ -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. */ diff --git a/src/lyxtextclass.C b/src/lyxtextclass.C index 462e9ed74c..f406915a85 100644 --- a/src/lyxtextclass.C +++ b/src/lyxtextclass.C @@ -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(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(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) { diff --git a/src/lyxtextclass.h b/src/lyxtextclass.h index bc93f8d6fe..70817d1ad8 100644 --- a/src/lyxtextclass.h +++ b/src/lyxtextclass.h @@ -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_; diff --git a/src/paragraph.C b/src/paragraph.C index 321c50bd22..d4f19258b3 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -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(inset)->layout(); return layout_; } diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index ca99e26a53..9ee4573abe 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -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(); diff --git a/src/paragraph_funcs.h b/src/paragraph_funcs.h index 3270494e65..4c78eceb5e 100644 --- a/src/paragraph_funcs.h +++ b/src/paragraph_funcs.h @@ -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); diff --git a/src/text2.C b/src/text2.C index 9dec90a8d0..92939fcae5 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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(); diff --git a/src/text3.C b/src/text3.C index d838a18b38..cab4f23c0e 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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();