]> git.lyx.org Git - lyx.git/commitdiff
move counters to the layout files
authorLars Gullik Bjønnes <larsbj@gullik.org>
Fri, 6 Sep 2002 14:48:01 +0000 (14:48 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Fri, 6 Sep 2002 14:48:01 +0000 (14:48 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5218 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
lib/ChangeLog
lib/layouts/stdclass.inc
lib/layouts/stdcounters.inc [new file with mode: 0644]
src/ChangeLog
src/buffer.C
src/buffer.h
src/counters.C
src/counters.h
src/lyxtextclass.C
src/lyxtextclass.h
src/lyxtextclasslist.C
src/text2.C

index 1e0c1fb3a0b08827a8d40dcdcb77414ebfbd609c..199ee8b856202a8b3e602699080a40e3c44feaae 100644 (file)
@@ -1,3 +1,9 @@
+2002-09-06  Lars Gullik Bjønnes  <larsbj@gullik.net>
+
+       * layouts/stdcounters.inc: new file
+
+       * layouts/stdclass.inc: include standard counters
+
 2002-09-05  Angus Leeming  <leeming@lyx.org>
 
        * scripts/lyxpreview2bitmap.sh: augment the preliminary blurb, as
index bb1700e72d16a58c724f562fda98e55f9c6f4347..1a8709ad91e8bbed9f56a15e60510e632deed6ba 100644 (file)
@@ -43,4 +43,5 @@ Input stdstruct.inc
 Input lyxmacros.inc
 Input stdlayouts.inc
 Input stdfloats.inc
+Input stdcounters.inc
 Input obsolete.inc
diff --git a/lib/layouts/stdcounters.inc b/lib/layouts/stdcounters.inc
new file mode 100644 (file)
index 0000000..f5d96f6
--- /dev/null
@@ -0,0 +1,73 @@
+# Author : Lars Gullik Bjønnes <larsbj@lyx.org>
+
+# 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 cd01d69670def8c3a97386e0baaa4b0aedbf21b0..e40821b44826f92e7e21e9ef50880f43b5ddb211 100644 (file)
@@ -1,23 +1,50 @@
+2002-09-06  Lars Gullik Bjønnes  <larsbj@gullik.net>
+
+       * text2.C (init): update counters after init
+       (insertParagraph): no need to set counter on idividual paragraphs.
+       (setCounter): access the counters object in the textclass object
+       on in the buffer object.
+       (updateCounters): ditto
+
+       * lyxtextclass.C: include counters.h, add variable ctrs_ as
+       shared_ptr<Counters> to avoid loading counters.h in all
+       compilation units.
+       (LyXTextClass): initialize ctrs_
+       (TextClassTags): add TC_COUNTER, and ...
+       (Read): use it here.
+       (CounterTags): new tags
+       (readCounter): new function
+       (counters): new funtion
+       (defaultLayoutName): return a const reference
+
+       * counters.C (Counters): remove contructor
+       (newCounter): remove a couple of unneeded statements.
+       (newCounter): simplify a bit.
+       (numberLabel): some small formatting changes.
+
+       * buffer.[Ch]: remove all traces of counters, move the Counters
+       object to the LyXTextClass.
+
 2002-09-06  Alain Castera  <castera@in2p3.fr>
 
-        * tabular.C: uses \tabularnewline; uses >{...} construct from array
+       * tabular.C: uses \tabularnewline; uses >{...} construct from array
        package to set the horizontal alignment on fixed width columns.
 
-        * lyx_sty.C: 
+       * lyx_sty.C:
        * lyx_sty.h: added tabularnewline macro def.
 
-        * LaTeXFeatures.C: added NeedTabularnewline macro feature
+       * LaTeXFeatures.C: added NeedTabularnewline macro feature
 
 2002-09-06  John Levon  <levon@movementarian.org>
 
        * LyXAction.C: tooltips for sub/superscript
 
        * MenuBackend.C: a bit more verbose
+
        * lyxfunc.C: tiny clean
 
-       * undo_funcs.C: document undo_frozen 
+       * undo_funcs.C: document undo_frozen
+
 2002-09-05  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * counters.C (Counters): add missing algorithm counter.
@@ -37,7 +64,7 @@
 
 2002-09-04  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
-       * lyxtextclass.C (TextClassTags): add TC_FLOAT 
+       * lyxtextclass.C (TextClassTags): add TC_FLOAT
        (Read): add float->TC_FLOAT to textclassTags
        (Read): and handle it in the switch
        (readFloat): new function
index 78011ecda77cd1aedea841bc7f5ca20de81b1333..086129577082ae50e2e40ad54fe8b6fe19ef0774 100644 (file)
@@ -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, Paragraph * par)
                                                     "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 Buffer::getBibkeyList() const
 
        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) {
@@ -3340,12 +3339,6 @@ bool Buffer::isMultiLingual()
 }
 
 
-Counters & Buffer::counters() const
-{
-       return *ctrs.get();
-}
-
-
 void Buffer::inset_iterator::setParagraph()
 {
        while (pit != pend) {
index 3e7b72c81d3b250760e06e0ac9958ab70d291723..b571466dc892fd501ed4dceb79dfcb4751a84cd6 100644 (file)
 #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 8415c45081c5aa0483227dbbd1e282cc593168ad..8203a98ceaec6583467fdeae9b4404d1c6af576a 100644 (file)
@@ -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 & newc)
                return;
        }
        counterList[newc];
-       cit = counterList.find(newc);
-       cit->second.setMaster("");
 }
 
 
@@ -131,9 +104,7 @@ void Counters::newCounter(string const & newc, string const & masterc)
                return;
        }
 
-       counterList[newc];
-       cit = counterList.find(newc);
-       cit->second.setMaster(masterc);
+       counterList[newc].setMaster(masterc);
 }
 
 
@@ -343,9 +314,11 @@ string Counters::numberLabel(string const & ctr,
                }
 
        } 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 d1c0ef59af0ad94246d9e6fee1ab76e508953f2f..d0b296b4183427b8876cc10e7e9eb53498b742e0 100644 (file)
@@ -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 5d87ca71aaed38558355166449488e3bb0b71b7c..f1ee3e12c01df1b5743500898ec45f2f593917ec 100644 (file)
@@ -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 & filename, bool merge)
        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 & filename, bool merge)
                                     << 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 & filename, bool merge)
                case TC_FLOAT:
                        readFloat(lexrc);
                        break;
+               case TC_COUNTER:
+                       readCounter(lexrc);
+                       break;
                }
        }
 
@@ -600,6 +606,64 @@ void LyXTextClass::readFloat(LyXLex & lexrc)
 }
 
 
+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() const
 }
 
 
-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 33cc930851348ec282eae9c8ba14d208ff1892b6..5063a13b0f2adb61840a9ae134df087740697bd0 100644 (file)
 
 #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;
        ///
@@ -192,6 +198,9 @@ private:
        ///
        FloatList floatlist_;
 
+       ///
+       boost::shared_ptr<Counters> ctrs_;
+
        /// Has this layout file been loaded yet?
        mutable bool loaded;
 };
index 59b0a4d5957b7dcbf9dd7d53a0f2e7e8a789d1b6..389e7ddfbcf00f612c7e5a5ac0fc636909a0cf37 100644 (file)
@@ -20,7 +20,6 @@
 #include "debug.h"
 #include "lyxlex.h"
 #include "gettext.h"
-
 #include "frontends/Alert.h"
 
 #include "support/lyxfunctional.h"
index dbb946bb37e656d052fc2e85172d6ffa13bffe3c..fcd43d880e64b3667c3c87da0c9d487f0a4a3d71 100644 (file)
@@ -98,6 +98,8 @@ void LyXText::init(BufferView * bview, bool reinit)
        }
        setCursorIntern(bview, firstrow->par(), 0);
        selection.cursor = cursor;
+
+       updateCounters(bview);
 }
 
 
@@ -383,9 +385,6 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
        // 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 * buf, Paragraph * par) 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 * buf, Paragraph * par) 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 * buf, Paragraph * par) const
                                        langtype = "latin";
                        }
 
-                       s << buf->counters()
+                       s << textclass.counters()
                                .numberLabel(layout->latexname(),
                                             numbertype, langtype, head);
 
@@ -1308,9 +1307,9 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) 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 * buf, Paragraph * par) 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 * buf, Paragraph * par) 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;
@@ -1390,17 +1389,19 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
                }
                par->params().labelString(s);
 
-               // reset the enumeration counter. They are always resetted
+               // reset the enumeration counter. They are always reset
                // when there is any other layout between
+               // Just fall-through between the cases so that all
+               // enum counters deeper than enumdepth is also reset.
                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 +1416,9 @@ void LyXText::updateCounters(BufferView * bview) const
        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();