display of counters in various situations (in particular bug 465)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10387 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2005-08-03 20:21:11 +00:00
parent 7454536793
commit 0424e3b04a
4 changed files with 88 additions and 69 deletions

View 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> 2005-08-02 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* lyxfunc.C (dispatch): use InsetIncludeMailer for the include * lyxfunc.C (dispatch): use InsetIncludeMailer for the include

View File

@ -13,7 +13,6 @@
#include <config.h> #include <config.h>
#include "buffer_funcs.h" #include "buffer_funcs.h"
#include "buffer.h" #include "buffer.h"
#include "bufferlist.h" #include "bufferlist.h"
#include "bufferparams.h" #include "bufferparams.h"
@ -272,75 +271,75 @@ int countWords(DocIterator const & from, DocIterator const & to)
namespace { 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) lyx::depth_type getItemDepth(ParIterator const & it)
return; {
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) { while (true) {
int const prev_depth = pars[prev_pit].getDepth(); if (prev_it.pit())
int const prev_labeltype = pars[prev_pit].layout()->labeltype; --prev_it.top().pit();
if (prev_depth == 0 && cur_depth > 0) { else {
if (prev_labeltype == cur_labeltype) { // start of nested inset: go to outer par
pars[pit].itemdepth = pars[prev_pit].itemdepth + 1; prev_it.pop_back();
} if (prev_it.empty()) {
break; // start of document: nothing to do
} else if (prev_depth < cur_depth) { return 0;
if (prev_labeltype == cur_labeltype) {
pars[pit].itemdepth = pars[prev_pit].itemdepth + 1;
break;
}
} else if (prev_depth == cur_depth) {
if (prev_labeltype == cur_labeltype) {
pars[pit].itemdepth = pars[prev_pit].itemdepth;
break;
} }
} }
if (prev_pit == first_pit)
break;
--prev_pit; // 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 == min_depth) {
return prev_par.itemdepth;
}
}
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, bool needEnumCounterReset(ParIterator const & it)
pit_type firstpit, Counters & counters)
{ {
if (pit == firstpit) Paragraph const & par = *it;
return; BOOST_ASSERT(par.layout()->labeltype == LABEL_ENUMERATE);
lyx::depth_type const cur_depth = par.getDepth();
int const cur_depth = pars[pit].getDepth(); ParIterator prev_it = it;
pit_type prev_pit = pit - 1; while (prev_it.pit()) {
while (true) { --prev_it.top().pit();
int const prev_depth = pars[prev_pit].getDepth(); Paragraph const & prev_par = *prev_it;
int const prev_labeltype = pars[prev_pit].layout()->labeltype; if (prev_par.getDepth() <= cur_depth)
if (prev_depth <= cur_depth) { return prev_par.layout()->labeltype != LABEL_ENUMERATE;
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;
} }
// start of nested inset: reset
return true;
} }
@ -353,9 +352,6 @@ void setCounter(Buffer const & buf, ParIterator & it)
LyXLayout_ptr const & layout = par.layout(); LyXLayout_ptr const & layout = par.layout();
Counters & counters = textclass.counters(); Counters & counters = textclass.counters();
// Always reset
par.itemdepth = 0;
if (it.pit() == 0) { if (it.pit() == 0) {
par.params().appendix(par.params().startOfAppendix()); par.params().appendix(par.params().startOfAppendix());
} else { } else {
@ -365,11 +361,11 @@ void setCounter(Buffer const & buf, ParIterator & it)
par.params().appendix(true); par.params().appendix(true);
textclass.counters().reset(); 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 // erase what was there before
par.params().labelString(string()); par.params().labelString(string());
@ -414,9 +410,6 @@ void setCounter(Buffer const & buf, ParIterator & it)
par.params().labelString(itemlabel); par.params().labelString(itemlabel);
} else if (layout->labeltype == LABEL_ENUMERATE) { } else if (layout->labeltype == LABEL_ENUMERATE) {
// Maybe we have to reset the enumeration counter.
resetEnumCounterIfNeeded(it.plist(), it.pit(), 0, counters);
// FIXME // FIXME
// Yes I know this is a really, really! bad solution // Yes I know this is a really, really! bad solution
// (Lgb) // (Lgb)
@ -438,6 +431,10 @@ void setCounter(Buffer const & buf, ParIterator & it)
break; break;
} }
// Maybe we have to reset the enumeration counter.
if (needEnumCounterReset(it))
counters.reset(enumcounter);
counters.step(enumcounter); counters.step(enumcounter);
par.params().labelString(counters.enumLabel(enumcounter)); par.params().labelString(counters.enumLabel(enumcounter));

View File

@ -207,7 +207,7 @@ public:
friend bool operator==(DocIterator const &, DocIterator const &); friend bool operator==(DocIterator const &, DocIterator const &);
/// ///
friend class StableDocIterator; friend class StableDocIterator;
protected: //protected:
/// ///
void clear() { slices_.clear(); } void clear() { slices_.clear(); }
/// ///

View File

@ -1519,8 +1519,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
break; break;
default: default:
lyxerr << BOOST_CURRENT_FUNCTION lyxerr[Debug::ACTION]
<< ": Command " << cmd << " not DISPATCHED by LyXText" << endl; << BOOST_CURRENT_FUNCTION
<< ": Command " << cmd
<< " not DISPATCHED by LyXText" << endl;
cur.undispatched(); cur.undispatched();
break; break;
} }