Martin's Per-buffer counters patch.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4948 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2002-08-12 20:24:10 +00:00
parent 9681e21dae
commit 6894fa6008
10 changed files with 81 additions and 57 deletions

View File

@ -1,3 +1,19 @@
2002-08-12 Martin Vermeer <martin.vermeer@hut.fi>
* buffer.C:
* buffer.h:
* lyxtext.h:
* paragraph.C:
* paragraph_pimpl.h:
* text.C:
* text2.C:
* undo_funcs.C: replaced per-paragraph counter logic by per-buffer, as
suggested by Angus.
Made updateCounter always count from start of buffer, and removed
second argument (par).
Reverted floats number display to '#'. Perhaps I'll try again when the
code base is sanitized a bit.
2002-08-12 Angus Leeming <leeming@lyx.org>
* buffer.[Ch] (getLabelList): constify.

View File

@ -20,6 +20,7 @@
#include "buffer.h"
#include "bufferlist.h"
#include "counters.h"
#include "LyXAction.h"
#include "lyxrc.h"
#include "lyxlex.h"
@ -148,7 +149,7 @@ const int LYX_FORMAT = 220;
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)
filename_(file), users(0), ctrs(new Counters)
{
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
// filename = file;
@ -3860,6 +3861,12 @@ bool Buffer::isMultiLingual()
}
Counters & Buffer::counters() const
{
return *ctrs.get();
}
Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
: par(paragraph)
{

View File

@ -27,9 +27,11 @@
#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;
@ -317,6 +319,9 @@ public:
/// Used when typesetting to place errorboxes.
TexRow texrow;
/// Buffer-wide counter array
Counters & counters() const;
private:
/// is save needed
mutable bool lyx_clean;
@ -350,6 +355,9 @@ private:
*/
BufferView * users;
/// The pointer is const although its contents may not be
boost::scoped_ptr<Counters> const ctrs;
public:
///
class inset_iterator {

View File

@ -222,6 +222,7 @@ void Counters::reset(string const & match)
}
}
void Counters::copy(Counters & from, Counters & to, string const & match)
{
CounterList::iterator it = counterList.begin();
@ -245,6 +246,7 @@ char loweralphaCounter(int n)
return 'a' + n - 1;
}
inline
char alphaCounter(int n)
{
@ -254,6 +256,7 @@ char alphaCounter(int n)
return 'A' + n - 1;
}
inline
char hebrewCounter(int n)
{
@ -268,6 +271,7 @@ char hebrewCounter(int n)
return hebrew[n-1];
}
inline
string const romanCounter(int n)
{
@ -285,10 +289,11 @@ string const romanCounter(int n)
} // namespace anon
string Counters::labelItem(string const & ctr,
string const & numbertype,
string const & langtype,
bool first)
string const & numbertype,
string const & langtype,
bool first)
{
ostringstream s, o;
CounterList::iterator it = counterList.find(ctr);
@ -314,10 +319,11 @@ string Counters::labelItem(string const & ctr,
return s.str();
}
string Counters::numberLabel(string const & ctr,
string const & numbertype,
string const & langtype,
int head)
string const & numbertype,
string const & langtype,
int head)
{
ostringstream s, o;
if (numbertype == "sectioning" || numbertype == "appendix") {

View File

@ -618,7 +618,7 @@ private:
public:
/** Updates all counters starting BEHIND the row. Changed paragraphs
* with a dynamic left margin will be rebroken. */
void updateCounters(BufferView *, Row * row) const;
void updateCounters(BufferView *) const;
private:
///
void setCounter(Buffer const *, Paragraph * par) const;

View File

@ -2057,7 +2057,3 @@ bool Paragraph::isFreeSpacing() const
}
Counters & Paragraph::counters()
{
return pimpl_->ctrs;
}

View File

@ -145,8 +145,7 @@ struct Paragraph::Pimpl {
static unsigned int paragraph_id;
///
ParagraphParameters params;
///
Counters ctrs;
private:
/// match a string against a particular point in the paragraph
bool isTextAt(string const & str, lyx::pos_type pos) const;

View File

@ -1805,7 +1805,7 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
insertParagraph(bview, cursor.par()->next(), cursor.row());
updateCounters(bview, cursor.row()->previous());
updateCounters(bview);
// This check is necessary. Otherwise the new empty paragraph will
// be deleted automatically. And it is more friendly for the user!
@ -2818,7 +2818,7 @@ void LyXText::backspace(BufferView * bview)
// This rebuilds the rows.
appendParagraph(bview, cursor.row());
updateCounters(bview, cursor.row());
updateCounters(bview);
// the row may have changed, block, hfills etc.
setCursor(bview, cursor.par(), cursor.pos(), false);

View File

@ -542,7 +542,7 @@ void LyXText::setLayout(BufferView * bview, string const & layout)
selection.start.pos(), false);
selection.cursor = cursor;
setCursor(bview, selection.end.par(), selection.end.pos(), false);
updateCounters(bview, cursor.row());
updateCounters(bview);
clearSelection();
setSelection(bview);
setCursor(bview, tmpcursor.par(), tmpcursor.pos(), true);
@ -619,7 +619,7 @@ void LyXText::incDepth(BufferView * bview)
setCursor(bview, selection.start.par(), selection.start.pos());
selection.cursor = cursor;
setCursor(bview, selection.end.par(), selection.end.pos());
updateCounters(bview, cursor.row());
updateCounters(bview);
clearSelection();
setSelection(bview);
setCursor(bview, tmpcursor.par(), tmpcursor.pos());
@ -676,7 +676,7 @@ void LyXText::decDepth(BufferView * bview)
selection.start.pos());
selection.cursor = cursor;
setCursor(bview, selection.end.par(), selection.end.pos());
updateCounters(bview, cursor.row());
updateCounters(bview);
clearSelection();
setSelection(bview);
setCursor(bview, tmpcursor.par(), tmpcursor.pos());
@ -883,6 +883,7 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
if (tmprow && tmprow->next())
setHeightOfRow(bview, tmprow->next());
updateCounters(bview);
}
@ -1218,21 +1219,16 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
LyXTextClass const & textclass = buf->params.getLyXTextClass();
LyXLayout_ptr const & layout = par->layout();
// copy the prev-counters to this one,
// unless this is the first paragraph
if (par->previous()) {
par->counters().copy(par->previous()->counters(), par->counters(), "");
par->params().appendix(par->previous()->params().appendix());
if (!par->params().appendix() && par->params().startOfAppendix()) {
par->params().appendix(true);
par->counters().reset();
buf->counters().reset();
}
par->enumdepth = par->previous()->enumdepth;
par->itemdepth = par->previous()->itemdepth;
} else {
par->counters().reset();
par->params().appendix(par->params().startOfAppendix());
par->enumdepth = 0;
par->itemdepth = 0;
@ -1258,8 +1254,6 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
&& par->previous()->getDepth() > par->getDepth()
&& layout->labeltype != LABEL_BIBLIO) {
par->enumdepth = par->depthHook(par->getDepth())->enumdepth;
par->counters().set(par->counters().enums[par->enumdepth],
par->depthHook(par->getDepth())->counters().value(par->counters().enums[par->enumdepth]));
}
if (!par->params().labelString().empty()) {
@ -1283,7 +1277,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
if (i >= 0 && i<= buf->params.secnumdepth) {
par->counters().step(par->counters().sects[i]);
buf->counters().step(buf->counters().sects[i]);
// Is there a label? Useful for Chapter layout
if (!par->params().appendix()) {
@ -1310,28 +1304,28 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
langtype = "latin";
}
s << par->counters().numberLabel(par->counters().sects[i],
s << buf->counters().numberLabel(buf->counters().sects[i],
numbertype, langtype, head);
par->params().labelString(par->params().labelString() +s.str().c_str());
par->params().labelString(par->params().labelString() + s.str().c_str());
// We really want to remove the c_str as soon as
// possible...
// reset enum counters
par->counters().reset("enum");
buf->counters().reset("enum");
} else if (layout->labeltype < LABEL_COUNTER_ENUMI) {
par->counters().reset("enum");
buf->counters().reset("enum");
} else if (layout->labeltype == LABEL_COUNTER_ENUMI) {
par->counters().step(par->counters().enums[par->enumdepth]);
buf->counters().step(buf->counters().enums[par->enumdepth]);
s << par->counters().numberLabel(par->counters().enums[par->enumdepth],
s << buf->counters().numberLabel(buf->counters().enums[par->enumdepth],
"enumeration", langtype);
par->params().labelString(s.str().c_str());
}
} else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
par->counters().step("bibitem");
int number = par->counters().value("bibitem");
buf->counters().step("bibitem");
int number = buf->counters().value("bibitem");
if (!par->bibkey) {
InsetCommandParams p("bibitem" );
par->bibkey = new InsetBibKey(p);
@ -1353,11 +1347,12 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
Floating const & fl
= floatList.getType(tmp->type());
// Why doesn't it work? -- MV
par->counters().step(fl.name());
// We should get the correct number here too.
buf->counters().step(fl.name());
// Doesn't work... yet.
ostringstream o;
o << fl.name() << " " << par->counters().value(fl.name()) << ":";
//o << fl.name() << " " << buf->counters().value(fl.name()) << ":";
o << fl.name() << " #:";
s = o.str();
} else {
/* par->SetLayout(0);
@ -1371,7 +1366,7 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
/* reset the enumeration counter. They are always resetted
* when there is any other layout between */
for (int i = par->enumdepth + 1; i < 4; i++) {
par->counters().set(par->counters().enums[i], 0);
buf->counters().set(buf->counters().enums[i], 0);
}
}
}
@ -1379,21 +1374,18 @@ void LyXText::setCounter(Buffer const * buf, Paragraph * par) const
// Updates all counters BEHIND the row. Changed paragraphs
// with a dynamic left margin will be rebroken.
void LyXText::updateCounters(BufferView * bview, Row * row) const
void LyXText::updateCounters(BufferView * bview) const
{
Paragraph * par;
Row * row = firstrow;
par = row->par();
if (!row) {
row = firstrow;
par = row->par();
} else {
par = row->par()->next();
}
bview->buffer()->counters().reset();
while (par) {
while (row->par() != par)
row = row->next();
setCounter(bview->buffer(), par);
// now check for the headline layouts. remember that they
@ -1520,7 +1512,7 @@ void LyXText::cutSelection(BufferView * bview, bool doclear, bool realcut)
setCursor(bview, cursor.par(), cursor.pos());
selection.cursor = cursor;
updateCounters(bview, cursor.row());
updateCounters(bview);
}
@ -1573,7 +1565,7 @@ void LyXText::pasteSelection(BufferView * bview)
selection.cursor = cursor;
setCursor(bview, actpar, pos);
setSelection(bview);
updateCounters(bview, cursor.row());
updateCounters(bview);
}
@ -2319,7 +2311,7 @@ bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
* there is another layout before */
if (refresh_row->next()) {
breakAgain(bview, refresh_row->next());
updateCounters(bview, refresh_row);
updateCounters(bview);
}
setHeightOfRow(bview, refresh_row);
} else {
@ -2352,7 +2344,7 @@ bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
there is another layout before */
if (refresh_row) {
breakAgain(bview, refresh_row);
updateCounters(bview, refresh_row->previous());
updateCounters(bview);
}
}
@ -2395,7 +2387,7 @@ void LyXText::toggleAppendix(BufferView * bview)
status(bview, LyXText::NEED_MORE_REFRESH);
refresh_y = 0;
refresh_row = 0; // not needed for full update
updateCounters(bview, 0);
updateCounters(bview);
setCursor(bview, cursor.par(), cursor.pos());
}

View File

@ -216,7 +216,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
// for an evt. new selection.
t->clearSelection();
t->selection.cursor = t->cursor;
t->updateCounters(bv, t->cursor.row());
t->updateCounters(bv);
bv->fitCursor();
}
bv->updateInset(it, false);
@ -238,7 +238,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo)
// for an evt. new selection.
t->clearSelection();
t->selection.cursor = t->cursor;
t->updateCounters(bv, t->cursor.row());
t->updateCounters(bv);
}
}