]> git.lyx.org Git - features.git/commitdiff
display of counters in various situations (in particular bug 465)
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 3 Aug 2005 20:21:11 +0000 (20:21 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 3 Aug 2005 20:21:11 +0000 (20:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10387 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/buffer_funcs.C
src/dociterator.h
src/text3.C

index b17f349d5069435efb1c9a0ec3adcf0f93aebf58..47f2ebfe498d8416bf9f843c2b401611fb9eb4d4 100644 (file)
@@ -1,3 +1,23 @@
+2005-07-31  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       bug 465.
+
+       * dociterator.h (clear, push_back, pop_back): change from
+       protected to public.
+
+       * buffer_funcs.C (getItemDepth): renamed from incrementItemDepth
+       and changed to just return the value of the item depth; take a
+       ParIterator as argument; take the itemdepth at outer nesting level
+       in account if necessary; cleanup and comment the code.
+       (resetEnumCounterNeeded): renamed from resetEnumCounterIfNeeded
+       and changed to just return true if reset is needed; take a
+       ParIterator as argument; cleanup and comment the code.
+       (setCounter): adapt to above changes.
+
+2005-07-30  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * text3.C (dispatch): make debug message optional
+
 2005-08-02  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * lyxfunc.C (dispatch): use InsetIncludeMailer for the include
index 2aee55c78e46fdcff8ebad41570bd9eaecec3f8f..1df2d55bd64b0637e2e5aeb70c916be3f6fb1c90 100644 (file)
@@ -13,7 +13,6 @@
 #include <config.h>
 
 #include "buffer_funcs.h"
-
 #include "buffer.h"
 #include "bufferlist.h"
 #include "bufferparams.h"
@@ -272,75 +271,75 @@ int countWords(DocIterator const & from, DocIterator const & to)
 
 namespace {
 
-void incrementItemDepth(ParagraphList & pars, pit_type pit, pit_type first_pit)
+lyx::depth_type getDepth(DocIterator const & it)
 {
-       int const cur_labeltype = pars[pit].layout()->labeltype;
+       lyx::depth_type depth = 0;
+       for (size_t i = 0 ; i < it.depth() ; ++i) 
+               if (!it[i].inset().inMathed())
+                       depth += it[i].paragraph().getDepth() + 1;
+       // remove 1 since the outer inset does not count
+       return depth - 1;
+}
 
-       if (cur_labeltype != LABEL_ENUMERATE && cur_labeltype != LABEL_ITEMIZE)
-               return;
+lyx::depth_type getItemDepth(ParIterator const & it)
+{      
+       Paragraph const & par = *it;
+       LYX_LABEL_TYPES const labeltype = par.layout()->labeltype;
 
-       int const cur_depth = pars[pit].getDepth();
+       if (labeltype != LABEL_ENUMERATE && labeltype != LABEL_ITEMIZE)
+               return 0;
 
-       pit_type prev_pit = pit - 1;
+       // this will hold the lowest depth encountered up to now.
+       lyx::depth_type min_depth = getDepth(it);
+       ParIterator prev_it = it;
        while (true) {
-               int const prev_depth = pars[prev_pit].getDepth();
-               int const prev_labeltype = pars[prev_pit].layout()->labeltype;
-               if (prev_depth == 0 && cur_depth > 0) {
-                       if (prev_labeltype == cur_labeltype) {
-                               pars[pit].itemdepth = pars[prev_pit].itemdepth + 1;
+               if (prev_it.pit())
+                       --prev_it.top().pit();
+               else {
+                       // start of nested inset: go to outer par
+                       prev_it.pop_back();
+                       if (prev_it.empty()) {
+                               // start of document: nothing to do
+                               return 0;
                        }
-                       break;
-               } else if (prev_depth < cur_depth) {
-                       if (prev_labeltype == cur_labeltype) {
-                               pars[pit].itemdepth = pars[prev_pit].itemdepth + 1;
-                               break;
+               }
+               
+               // We search for the first paragraph with same label
+               // that is not more deeply nested.
+               Paragraph & prev_par = *prev_it;
+               lyx::depth_type const prev_depth = getDepth(prev_it);
+               if (labeltype == prev_par.layout()->labeltype) {
+                       if (prev_depth < min_depth) {
+                               return prev_par.itemdepth + 1;
                        }
-               } else if (prev_depth == cur_depth) {
-                       if (prev_labeltype == cur_labeltype) {
-                               pars[pit].itemdepth = pars[prev_pit].itemdepth;
-                               break;
+                       else if (prev_depth == min_depth) {
+                               return prev_par.itemdepth;
                        }
                }
-               if (prev_pit == first_pit)
-                       break;
-
-               --prev_pit;
+               min_depth = std::min(min_depth, prev_depth);
+               // small optimization: if we are at depth 0, we won't
+               // find anything else
+               if (prev_depth == 0) {
+                       return 0;
+               }
        }
 }
 
 
-void resetEnumCounterIfNeeded(ParagraphList & pars, pit_type pit,
-       pit_type firstpit, Counters & counters)
+bool needEnumCounterReset(ParIterator const & it)
 {
-       if (pit == firstpit)
-               return;
-
-       int const cur_depth = pars[pit].getDepth();
-       pit_type prev_pit = pit - 1;
-       while (true) {
-               int const prev_depth = pars[prev_pit].getDepth();
-               int const prev_labeltype = pars[prev_pit].layout()->labeltype;
-               if (prev_depth <= cur_depth) {
-                       if (prev_labeltype != LABEL_ENUMERATE) {
-                               switch (pars[pit].itemdepth) {
-                               case 0:
-                                       counters.reset("enumi");
-                               case 1:
-                                       counters.reset("enumii");
-                               case 2:
-                                       counters.reset("enumiii");
-                               case 3:
-                                       counters.reset("enumiv");
-                               }
-                       }
-                       break;
-               }
-
-               if (prev_pit == firstpit)
-                       break;
-
-               --prev_pit;
+       Paragraph const & par = *it;
+       BOOST_ASSERT(par.layout()->labeltype == LABEL_ENUMERATE);
+       lyx::depth_type const cur_depth = par.getDepth();
+       ParIterator prev_it = it;
+       while (prev_it.pit()) {
+               --prev_it.top().pit();
+               Paragraph const & prev_par = *prev_it;
+               if (prev_par.getDepth() <= cur_depth)
+                       return  prev_par.layout()->labeltype != LABEL_ENUMERATE;
        }
+       // start of nested inset: reset
+       return true;
 }
 
 
@@ -353,9 +352,6 @@ void setCounter(Buffer const & buf, ParIterator & it)
        LyXLayout_ptr const & layout = par.layout();
        Counters & counters = textclass.counters();
 
-       // Always reset
-       par.itemdepth = 0;
-
        if (it.pit() == 0) {
                par.params().appendix(par.params().startOfAppendix());
        } else {
@@ -365,11 +361,11 @@ void setCounter(Buffer const & buf, ParIterator & it)
                        par.params().appendix(true);
                        textclass.counters().reset();
                }
-
-               // Maybe we have to increment the item depth.
-               incrementItemDepth(it.plist(), it.pit(), 0);
        }
 
+       // Compute the item depth of the paragraph
+       par.itemdepth = getItemDepth(it);
+
        // erase what was there before
        par.params().labelString(string());
 
@@ -414,9 +410,6 @@ void setCounter(Buffer const & buf, ParIterator & it)
 
                par.params().labelString(itemlabel);
        } else if (layout->labeltype == LABEL_ENUMERATE) {
-               // Maybe we have to reset the enumeration counter.
-               resetEnumCounterIfNeeded(it.plist(), it.pit(), 0, counters);
-
                // FIXME
                // Yes I know this is a really, really! bad solution
                // (Lgb)
@@ -438,6 +431,10 @@ void setCounter(Buffer const & buf, ParIterator & it)
                        break;
                }
 
+               // Maybe we have to reset the enumeration counter.
+               if (needEnumCounterReset(it))
+                       counters.reset(enumcounter);
+
                counters.step(enumcounter);
 
                par.params().labelString(counters.enumLabel(enumcounter));
index 5b410ae9a7c10f0596111a2c5435ddd566bf5370..3cfcef96f3293ccf2cfad51629924d16cc91ad59 100644 (file)
@@ -207,7 +207,7 @@ public:
        friend bool operator==(DocIterator const &, DocIterator const &);
        ///
        friend class StableDocIterator;
-protected:
+//protected:
        ///
        void clear() { slices_.clear(); }
        ///
index 0db15288d93512d72b5d470c2a7b7593d040a968..051bf8630d8eb2dc7a5f37b70ed20e15da4300b2 100644 (file)
@@ -1519,8 +1519,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        default:
-               lyxerr << BOOST_CURRENT_FUNCTION
-                                        << ": Command " << cmd << " not DISPATCHED by LyXText" << endl;
+               lyxerr[Debug::ACTION] 
+                       << BOOST_CURRENT_FUNCTION
+                       << ": Command " << cmd 
+                       << " not DISPATCHED by LyXText" << endl;
                cur.undispatched();
                break;
        }