* src/buffer_funcs.[Ch]

- updateCounters renamed to updateLabels
 - void updateLabels(Buffer const & buf,
   ParIterator & it): new convenience function
 - void updateLabels(Buffer const & buf,
   ParIterator & from, ParIterator & to): new convenience function
 - setCounter renamed to setLabel
 - bool tryToUpdateCurrentLabel(Buffer const & buf,
   ParIterator & it): new method
 - needsUpdateCounters: deleted

* src/BufferView_pimpl.C
* src/CutAndPaste.C
* src/frontends/controllers/ControlDocument.C
* src/lyxfunc.C
* src/text.C
* src/text2.C
* src/text3.C
 - fixed the calls to updateLabels


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13689 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2006-04-16 14:19:25 +00:00
parent a90ee19486
commit f6bcac7285
9 changed files with 80 additions and 36 deletions

View File

@ -1236,7 +1236,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
lyx::toc::outline(op, buffer_, cursor_.pit());
bv_->text()->setCursor(cursor_, cursor_.pit(), 0);
buffer_->markDirty();
updateCounters(*buffer_);
updateLabels(*buffer_);
update();
}

View File

@ -516,7 +516,7 @@ void cutSelection(LCursor & cur, bool doclear, bool realcut)
// need a valid cursor. (Lgb)
cur.clearSelection();
updateCounters(cur.buffer());
updateLabels(cur.buffer());
// tell tabular that a recent copy happened
dirtyTabularStack(false);
@ -610,7 +610,7 @@ void pasteParagraphList(LCursor & cur, ParagraphList const & parlist,
parlist, textclass,
el);
bufferErrors(cur.buffer(), el);
updateCounters(cur.buffer());
updateLabels(cur.buffer());
cur.clearSelection();
text->setCursor(cur, ppp.first, ppp.second);
}

View File

@ -42,9 +42,13 @@
#include "support/fs_extras.h"
#include "support/lyxlib.h"
#include <iostream>
#include <boost/bind.hpp>
#include <boost/filesystem/operations.hpp>
using namespace std;
using lyx::pit_type;
using lyx::support::bformat;
using lyx::support::libFileSearch;
@ -346,8 +350,8 @@ bool needEnumCounterReset(ParIterator const & it)
}
// set the counter of a paragraph. This includes the labels
void setCounter(Buffer const & buf, ParIterator & it)
// set the label of a paragraph. This includes the counters.
void setLabel(Buffer const & buf, ParIterator & it)
{
Paragraph & par = *it;
BufferParams const & bufparams = buf.params();
@ -505,8 +509,12 @@ void setCounter(Buffer const & buf, ParIterator & it)
} // anon namespace
bool needsUpdateCounters(Buffer const & buf, ParIterator & it)
bool updateCurrentLabel(Buffer const & buf,
ParIterator & it)
{
if (it == par_iterator_end(buf.inset()))
return true;
switch (it->layout()->labeltype) {
case LABEL_NO_LABEL:
@ -516,24 +524,53 @@ bool needsUpdateCounters(Buffer const & buf, ParIterator & it)
case LABEL_CENTERED_TOP_ENVIRONMENT:
case LABEL_STATIC:
case LABEL_ITEMIZE:
setCounter(buf, it);
return false;
setLabel(buf, it);
return true;
case LABEL_SENSITIVE:
case LABEL_COUNTER:
// do more things with enumerate later
case LABEL_ENUMERATE:
return true;
return false;
}
// This is dead code which get rid of a warning:
return true;
}
void updateLabels(Buffer const & buf,
ParIterator & from, ParIterator & to)
{
for (ParIterator it = from; it != to; ++it) {
if (it.pit() > it.lastpit())
return;
if (!updateCurrentLabel (buf, it)) {
updateLabels(buf);
return;
}
}
}
void updateCounters(Buffer const & buf)
void updateLabels(Buffer const & buf,
ParIterator & iter)
{
// start over
if (updateCurrentLabel(buf, iter))
return;
updateLabels(buf);
}
void updateLabels(Buffer const & buf)
{
// start over the counters
buf.params().getLyXTextClass().counters().reset();
for (ParIterator it = par_iterator_begin(buf.inset()); it; ++it) {
ParIterator const end = par_iterator_end(buf.inset());
for (ParIterator it = par_iterator_begin(buf.inset()); it != end; ++it) {
// reduce depth if necessary
if (it.pit()) {
Paragraph const & prevpar = it.plist()[it.pit() - 1];
@ -543,7 +580,7 @@ void updateCounters(Buffer const & buf)
it->params().depth(0);
// set the counter for this paragraph
setCounter(buf, it);
setLabel(buf, it);
}
}

View File

@ -49,15 +49,21 @@ int countWords(DocIterator const & from, DocIterator const & to);
std::string expandLabel(Buffer const & buf, LyXLayout_ptr const & layout,
bool appendix);
/// updates current counter and/or label if possible.
/// update labels at "iter".
/**
\retval true if a full updateCounters is required.
\retval false if a full updateCounters is not required.
A full updateLabels(Buffer const &) will be called if not possible.
*/
bool needsUpdateCounters(Buffer const & buf, ParIterator & it);
void updateLabels(Buffer const & buf, ParIterator & it);
/// update labels between "from" and "to" if possible.
/**
A full updateLabels(Buffer const &) will be called if not possible.
*/
void updateLabels(Buffer const & buf,
ParIterator & from, ParIterator & to);
/// updates all counters
void updateCounters(Buffer const &);
void updateLabels(Buffer const &);
#endif // BUFFER_FUNCS_H

View File

@ -104,7 +104,7 @@ void ControlDocument::dispatchParams()
// redo the numbering if necessary
if (new_secnumdepth != old_secnumdepth)
updateCounters(kernel().buffer());
updateLabels(kernel().buffer());
// Generate the colours requested by each new branch.
BranchList & branchlist = params().branchlist();

View File

@ -1564,7 +1564,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
bufferErrors(*buffer, el);
view()->showErrorList(_("Class switch"));
updateCounters(*buffer);
updateLabels(*buffer);
update = true;
break;
}

View File

@ -1090,11 +1090,11 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
pars_[next_par].erase(0);
ParIterator current_it(cur);
ParIterator next_it(cur); next_it.pit() = next_par;
ParIterator last_it(cur);
++last_it;
++last_it;
if (needsUpdateCounters(cur.buffer(), current_it)
|| needsUpdateCounters(cur.buffer(), next_it))
updateCounters(cur.buffer());
updateLabels(cur.buffer(), current_it, last_it);
// Mark "carriage return" as inserted if change tracking:
if (cur.buffer().params().tracking_changes) {
@ -1677,8 +1677,7 @@ bool LyXText::backspacePos0(LCursor & cur)
// the counters may have changed
ParIterator par_it(cur);
if (needsUpdateCounters(cur.buffer(), par_it))
updateCounters(cur.buffer());
updateLabels(cur.buffer(), par_it);
setCursor(cur, cur.pit(), cur.pos(), false);
}

View File

@ -90,7 +90,7 @@ void LyXText::init(BufferView * bv)
pars_[pit].rows().clear();
current_font = getFont(pars_[0], 0);
updateCounters(*bv->buffer());
updateLabels(*bv->buffer());
}
@ -358,7 +358,7 @@ void LyXText::setLayout(LCursor & cur, string const & layout)
pit_type undopit = undoSpan(end - 1);
recUndo(start, undopit - 1);
setLayout(start, end, layout);
updateCounters(cur.buffer());
updateLabels(cur.buffer());
}
@ -419,7 +419,7 @@ void LyXText::changeDepth(LCursor & cur, DEPTH_CHANGE type)
}
// this handles the counter labels, and also fixes up
// depth values for follow-on (child) paragraphs
updateCounters(cur.buffer());
updateLabels(cur.buffer());
}
@ -1274,9 +1274,11 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
cur.resetAnchor();
}
}
ParIterator par_it(old);
if (needsUpdateCounters(old.buffer(), par_it))
updateCounters(old.buffer());
// There is a crash reported by Edwin Leuven (16/04/2006) because of:
//ParIterator par_it(old);
//updateLabels(old.buffer(), par_it);
// So for now we do the full update:
updateLabels(old.buffer());
return true;
}

View File

@ -342,7 +342,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
par.params().startOfAppendix(start);
// we can set the refreshing parameters now
updateCounters(cur.buffer());
updateLabels(cur.buffer());
break;
}