Martin Vermeer <[EMAIL PROTECTED]> writes: | Try this: | | 1) Load a document, any document, as long as it contains chapter headers. | 2) Close the doc. Do NOT exit LyX. | 3) Open the same doc again.
Ok, the following update seems to fix that problem. If you have time, please look at it again. | :-) | | Also an enumerated list with a tabular in a std depth 1 par is | rendered at load like this: | | | 1. first item | | | | | +---------+ | | | tabular | | | +---------+ | | | | 1. second item | | ...but then fiddling with the depth (1->0->1) changes the 1 to a 2. Strange... but I cannot reproduce it with the attached patch.
Index: lib/layouts/stdclass.inc =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/stdclass.inc,v retrieving revision 1.4 diff -u -p -r1.4 stdclass.inc --- lib/layouts/stdclass.inc 4 Sep 2002 06:52:25 -0000 1.4 +++ lib/layouts/stdclass.inc 6 Sep 2002 12:03:12 -0000 @@ -43,4 +43,5 @@ Input stdstruct.inc Input lyxmacros.inc Input stdlayouts.inc Input stdfloats.inc +Input stdcounters.inc Input obsolete.inc Index: lib/layouts/stdcounters.inc =================================================================== RCS file: lib/layouts/stdcounters.inc diff -N lib/layouts/stdcounters.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/layouts/stdcounters.inc 6 Sep 2002 12:03:12 -0000 @@ -0,0 +1,73 @@ +# Author : Lars Gullik Bjønnes <[EMAIL PROTECTED]> + +# This include file contains all the counters that are defined as standard +# in most LyX layouts. + + +Counter + Name part +End + +Counter + Name chapter +End + +Counter + Name section + Within chapter +End + +Counter + Name subsection + Within section +End + +Counter + Name subsubsection + Within subsection +End + +Counter + Name paragraph + Within subsubsection +End + +Counter + Name subparagraph + Within paragraph +End + +Counter + Name enumi +End + +Counter + Name enumii + Within enumi +End + +Counter + Name enumiii + Within enumii +End + +Counter + Name enumiv + Within enumiii +End + +Counter + Name bibitem +End + +Counter + Name figure +End + +Counter + Name table +End + +Counter + Name algorithm +End Index: src/buffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v retrieving revision 1.383 diff -u -p -r1.383 buffer.C --- src/buffer.C 3 Sep 2002 16:13:35 -0000 1.383 +++ src/buffer.C 6 Sep 2002 12:03:14 -0000 @@ -20,7 +20,6 @@ #include "buffer.h" #include "bufferlist.h" -#include "counters.h" #include "LyXAction.h" #include "lyxrc.h" #include "lyxlex.h" @@ -154,7 +153,7 @@ const int LYX_FORMAT = 221; Buffer::Buffer(string const & file, bool ronly) : niceFile(true), lyx_clean(true), bak_clean(true), unnamed(false), dep_clean(0), read_only(ronly), - filename_(file), users(0), ctrs(new Counters) + filename_(file), users(0) { lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl; filepath_ = OnlyPath(file); @@ -1171,7 +1170,7 @@ bool Buffer::readFile(LyXLex & lex, Para "Use LyX 0.10.x to read this!")); return false; } else { - string command = + string command = LibFileSearch("lyx2lyx", "lyx2lyx"); if (command.empty()) { Alert::alert(_("ERROR!"), @@ -3221,7 +3220,7 @@ vector<pair<string, string> > const Buff if (!keys.empty()) return keys; - + // Might be either using bibtex or a child has bibliography for (inset_iterator it = inset_const_iterator_begin(); it != inset_const_iterator_end(); ++it) { @@ -3337,12 +3336,6 @@ bool Buffer::isMultiLingual() return true; return false; -} - - -Counters & Buffer::counters() const -{ - return *ctrs.get(); } Index: src/buffer.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v retrieving revision 1.112 diff -u -p -r1.112 buffer.h --- src/buffer.h 21 Aug 2002 07:30:56 -0000 1.112 +++ src/buffer.h 6 Sep 2002 12:03:14 -0000 @@ -27,11 +27,9 @@ #include "ParagraphList.h" #include "paragraph.h" -#include <boost/scoped_ptr.hpp> #include <boost/shared_ptr.hpp> class BufferView; -class Counters; class LyXRC; class TeXErrors; class LaTeXFeatures; @@ -311,9 +309,6 @@ public: /// Used when typesetting to place errorboxes. TexRow texrow; - /// Buffer-wide counter array - Counters & counters() const; - private: /// is save needed mutable bool lyx_clean; @@ -346,10 +341,6 @@ private: of the buffers in the list of users to do a #updateLayoutChoice#. */ BufferView * users; - - /// The pointer is const although its contents may not be - boost::scoped_ptr<Counters> const ctrs; - public: /// class inset_iterator { Index: src/counters.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/counters.C,v retrieving revision 1.14 diff -u -p -r1.14 counters.C --- src/counters.C 5 Sep 2002 13:19:33 -0000 1.14 +++ src/counters.C 6 Sep 2002 12:03:14 -0000 @@ -17,6 +17,7 @@ #include "counters.h" #include "debug.h" + #include "support/lstrings.h" #include "support/LAssert.h" @@ -59,45 +60,19 @@ void Counter::reset() value_ = 0; } + string Counter::master() const { return master_; } + void Counter::setMaster(string const & m) { master_ = m; } -Counters::Counters() -{ - // Ehh, should this take a textclass arg? - - // Sectioning counters: - newCounter("part"); - newCounter("chapter"); - newCounter("section", "chapter"); - newCounter("subsection", "section"); - newCounter("subsubsection", "subsection"); - newCounter("paragraph", "subsubsection"); - newCounter("subparagraph", "paragraph"); - - // Enumeration counters: - newCounter("enumi"); - newCounter("enumii", "enumi"); - newCounter("enumiii", "enumii"); - newCounter("enumiv", "enumiii"); - - // Biblio: - newCounter("bibitem"); - - // Float counters: - newCounter("figure"); - newCounter("table"); - newCounter("algorithm"); -} - void Counters::newCounter(string const & newc) { @@ -109,8 +84,6 @@ void Counters::newCounter(string const & return; } counterList[newc]; - cit = counterList.find(newc); - cit->second.setMaster(""); } @@ -131,9 +104,7 @@ void Counters::newCounter(string const & return; } - counterList[newc]; - cit = counterList.find(newc); - cit->second.setMaster(masterc); + counterList[newc].setMaster(masterc); } @@ -343,9 +314,11 @@ string Counters::numberLabel(string cons } } else if (numbertype == "enumeration") { - ostringstream ei, eii, eiii, eiv; - //string ei, eiii, eiv; - //char eii; + ostringstream ei; + ostringstream eii; + ostringstream eiii; + ostringstream eiv; + if (langtype == "hebrew") { ei << '.' << value("enumi"); eii << '(' << hebrewCounter(value("enumii")) << ')'; Index: src/counters.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/counters.h,v retrieving revision 1.11 diff -u -p -r1.11 counters.h --- src/counters.h 5 Sep 2002 12:58:09 -0000 1.11 +++ src/counters.h 6 Sep 2002 12:03:14 -0000 @@ -55,10 +55,6 @@ private: /// Every instantiation is an array of counters of type Counter. class Counters { public: - /// - Counters(); - /// - //~Counters(); /// Add a new counter to array. void newCounter(string const & newc); /// Add new counter having oldc as its master. Index: src/lyxtextclass.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtextclass.C,v retrieving revision 1.18 diff -u -p -r1.18 lyxtextclass.C --- src/lyxtextclass.C 4 Sep 2002 06:52:26 -0000 1.18 +++ src/lyxtextclass.C 6 Sep 2002 12:03:14 -0000 @@ -18,6 +18,7 @@ #include "lyxtextclass.h" #include "debug.h" #include "lyxlex.h" +#include "counters.h" #include "support/lstrings.h" #include "support/LAssert.h" @@ -48,7 +49,7 @@ struct compare_name { LyXTextClass::LyXTextClass(string const & fn, string const & cln, string const & desc) - : name_(fn), latexname_(cln), description_(desc) + : name_(fn), latexname_(cln), description_(desc), ctrs_(new Counters) { outputType_ = LATEX; columns_ = 1; @@ -108,7 +109,8 @@ enum TextClassTags { TC_PROVIDESURL, TC_LEFTMARGIN, TC_RIGHTMARGIN, - TC_FLOAT + TC_FLOAT, + TC_COUNTER }; @@ -118,6 +120,7 @@ bool LyXTextClass::Read(string const & f keyword_item textClassTags[] = { { "classoptions", TC_CLASSOPTIONS }, { "columns", TC_COLUMNS }, + { "counter", TC_COUNTER }, { "defaultfont", TC_DEFAULTFONT }, { "defaultstyle", TC_DEFAULTSTYLE }, { "float", TC_FLOAT }, @@ -148,7 +151,7 @@ bool LyXTextClass::Read(string const & f << MakeDisplayPath(filename) << endl; - LyXLex lexrc(textClassTags, TC_FLOAT); + LyXLex lexrc(textClassTags, TC_COUNTER); bool error = false; lexrc.setFile(filename); @@ -327,6 +330,9 @@ bool LyXTextClass::Read(string const & f case TC_FLOAT: readFloat(lexrc); break; + case TC_COUNTER: + readCounter(lexrc); + break; } } @@ -600,6 +606,64 @@ void LyXTextClass::readFloat(LyXLex & le } +enum CounterTags { + CT_NAME = 1, + CT_WITHIN, + CT_END +}; + +void LyXTextClass::readCounter(LyXLex & lexrc) +{ + keyword_item counterTags[] = { + { "end", CT_END }, + { "name", CT_NAME }, + { "within", CT_WITHIN } + }; + + lexrc.pushTable(counterTags, CT_END); + + string name; + string within; + + bool getout = false; + while (!getout && lexrc.isOK()) { + int le = lexrc.lex(); + switch (le) { + case LyXLex::LEX_UNDEF: + lexrc.printError("Unknown ClassOption tag `$$Token'"); + continue; + default: break; + } + switch (static_cast<CounterTags>(le)) { + case CT_NAME: + lexrc.next(); + name = lexrc.getString(); + break; + case CT_WITHIN: + lexrc.next(); + within = lexrc.getString(); + if (within == "none") + within.erase(); + break; + case CT_END: + getout = true; + break; + } + } + + // Here if have a full float if getout == true + if (getout) { + if (within.empty()) { + ctrs_->newCounter(name); + } else { + ctrs_->newCounter(name, within); + } + } + + lexrc.popTable(); +} + + LyXFont const & LyXTextClass::defaultfont() const { return defaultfont_; @@ -714,7 +778,13 @@ FloatList const & LyXTextClass::floats() } -string const LyXTextClass::defaultLayoutName() const +Counters & LyXTextClass::counters() const +{ + return *ctrs_.get(); +} + + +string const & LyXTextClass::defaultLayoutName() const { // This really should come from the actual layout... (Lgb) return defaultlayout_; Index: src/lyxtextclass.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtextclass.h,v retrieving revision 1.8 diff -u -p -r1.8 lyxtextclass.h --- src/lyxtextclass.h 4 Sep 2002 06:52:26 -0000 1.8 +++ src/lyxtextclass.h 6 Sep 2002 12:03:15 -0000 @@ -23,9 +23,12 @@ #include "support/types.h" +#include <boost/shared_ptr.hpp> + #include <vector> class LyXLex; +class Counters; /// class LyXTextClass { @@ -36,9 +39,9 @@ public: typedef LayoutList::const_iterator const_iterator; /// explicit - LyXTextClass (string const & = string(), - string const & = string(), - string const & = string()); + LyXTextClass(string const & = string(), + string const & = string(), + string const & = string()); /// const_iterator begin() const { return layoutlist_.begin(); } @@ -56,6 +59,8 @@ public: /// void readFloat(LyXLex &); /// + void readCounter(LyXLex &); + /// bool hasLayout(string const & name) const; /// @@ -68,9 +73,10 @@ public: FloatList & floats(); /// the list of floats defined in the class FloatList const & floats() const; - + /// The Counters present in this textclass. + Counters & counters() const; /// - string const defaultLayoutName() const; + string const & defaultLayoutName() const; /// LyXLayout_ptr const & defaultLayout() const; /// @@ -191,6 +197,9 @@ private: /// FloatList floatlist_; + + /// + boost::shared_ptr<Counters> ctrs_; /// Has this layout file been loaded yet? mutable bool loaded; Index: src/lyxtextclasslist.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtextclasslist.C,v retrieving revision 1.7 diff -u -p -r1.7 lyxtextclasslist.C --- src/lyxtextclasslist.C 21 Jul 2002 21:20:56 -0000 1.7 +++ src/lyxtextclasslist.C 6 Sep 2002 12:03:15 -0000 @@ -20,7 +20,6 @@ #include "debug.h" #include "lyxlex.h" #include "gettext.h" - #include "frontends/Alert.h" #include "support/lyxfunctional.h" Index: src/text2.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v retrieving revision 1.259 diff -u -p -r1.259 text2.C --- src/text2.C 5 Sep 2002 12:58:09 -0000 1.259 +++ src/text2.C 6 Sep 2002 12:03:16 -0000 @@ -98,6 +98,8 @@ void LyXText::init(BufferView * bview, b } setCursorIntern(bview, firstrow->par(), 0); selection.cursor = cursor; + + updateCounters(bview); } @@ -383,9 +385,6 @@ void LyXText::insertParagraph(BufferView // insert a new row, starting at position 0 insertRow(row, par, 0); - // set the counters - setCounter(bview->buffer(), par); - // and now append the whole paragraph behind the new row if (!row) { firstrow->height(0); @@ -1218,7 +1217,7 @@ void LyXText::setCounter(Buffer const * par->params().appendix(par->previous()->params().appendix()); if (!par->params().appendix() && par->params().startOfAppendix()) { par->params().appendix(true); - buf->counters().reset(); + textclass.counters().reset(); } par->enumdepth = par->previous()->enumdepth; par->itemdepth = par->previous()->itemdepth; @@ -1272,7 +1271,7 @@ void LyXText::setCounter(Buffer const * if (i >= 0 && i <= buf->params.secnumdepth) { - buf->counters().step(layout->latexname()); + textclass.counters().step(layout->latexname()); // Is there a label? Useful for Chapter layout if (!par->params().appendix()) { @@ -1299,7 +1298,7 @@ void LyXText::setCounter(Buffer const * langtype = "latin"; } - s << buf->counters() + s << textclass.counters() .numberLabel(layout->latexname(), numbertype, langtype, head); @@ -1308,9 +1307,9 @@ void LyXText::setCounter(Buffer const * // possible... // reset enum counters - buf->counters().reset("enum"); + textclass.counters().reset("enum"); } else if (layout->labeltype < LABEL_COUNTER_ENUMI) { - buf->counters().reset("enum"); + textclass.counters().reset("enum"); } else if (layout->labeltype == LABEL_COUNTER_ENUMI) { // FIXME // Yes I know this is a really, really! bad solution @@ -1333,16 +1332,16 @@ void LyXText::setCounter(Buffer const * break; } - buf->counters().step(enumcounter); + textclass.counters().step(enumcounter); - s << buf->counters() + s << textclass.counters() .numberLabel(enumcounter, "enumeration", langtype); par->params().labelString(s.str().c_str()); } } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302 - buf->counters().step("bibitem"); - int number = buf->counters().value("bibitem"); + textclass.counters().step("bibitem"); + int number = textclass.counters().value("bibitem"); if (!par->bibkey) { InsetCommandParams p("bibitem"); par->bibkey = new InsetBibKey(p); @@ -1374,7 +1373,7 @@ void LyXText::setCounter(Buffer const * Floating const & fl = textclass.floats().getType(static_cast<InsetFloat*>(in)->type()); - buf->counters().step(fl.type()); + textclass.counters().step(fl.type()); // Doesn't work... yet. ostringstream o; @@ -1394,13 +1393,13 @@ void LyXText::setCounter(Buffer const * // when there is any other layout between switch (par->enumdepth) { case 0: - buf->counters().reset("enumi"); + textclass.counters().reset("enumi"); case 1: - buf->counters().reset("enumii"); + textclass.counters().reset("enumii"); case 2: - buf->counters().reset("enumiii"); + textclass.counters().reset("enumiii"); case 3: - buf->counters().reset("enumiv"); + textclass.counters().reset("enumiv"); } } } @@ -1415,7 +1414,9 @@ void LyXText::updateCounters(BufferView Row * row = firstrow; par = row->par(); - bview->buffer()->counters().reset(); + // CHECK if this is really needed. (Lgb) + bview->buffer()->params.getLyXTextClass().counters().reset(); + while (par) { while (row->par() != par) row = row->next();
-- Lgb