move updateLables to buffer

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27562 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-11-16 16:43:49 +00:00
parent f54ef5c173
commit f8f5a7b28d
20 changed files with 101 additions and 103 deletions

View File

@ -2643,4 +2643,56 @@ void Buffer::bufferErrors(TeXErrors const & terr, ErrorList & errorList) const
}
// FIXME: buf should should be const because updateLabels() modifies
// the contents of the paragraphs.
void Buffer::updateLabels(bool childonly) const
{
// Use the master text class also for child documents
Buffer const * const master = masterBuffer();
DocumentClass const & textclass = master->params().documentClass();
// keep the buffers to be children in this set. If the call from the
// master comes back we can see which of them were actually seen (i.e.
// via an InsetInclude). The remaining ones in the set need still be updated.
static std::set<Buffer const *> bufToUpdate;
if (!childonly) {
// If this is a child document start with the master
if (master != this) {
bufToUpdate.insert(this);
master->updateLabels(false);
// was buf referenced from the master (i.e. not in bufToUpdate anymore)?
if (bufToUpdate.find(this) == bufToUpdate.end())
return;
}
// start over the counters in the master
textclass.counters().reset();
}
// update will be done below for this buffer
bufToUpdate.erase(this);
// update all caches
clearReferenceCache();
inset().setBuffer(const_cast<Buffer &>(*this));
updateMacros();
Buffer & cbuf = const_cast<Buffer &>(*this);
LASSERT(!text().paragraphs().empty(), /**/);
// do the real work
ParIterator parit = cbuf.par_iterator_begin();
lyx::updateLabels(*this, parit);
if (master != this)
// TocBackend update will be done later.
return;
cbuf.tocBackend().update();
if (!childonly)
cbuf.structureChanged();
}
} // namespace lyx

View File

@ -466,6 +466,10 @@ public:
void setInsetLabel(docstring const & label, InsetLabel const * il);
InsetLabel const * insetLabel(docstring const & label) const;
// FIXME: buf should should be const because updateLabels() modifies
// the contents of the paragraphs.
void updateLabels(bool childonly = false) const;
private:
/// search for macro in local (buffer) table or in children
MacroData const * getBufferMacro(docstring const & name,

View File

@ -1858,7 +1858,7 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old)
d->cursor_ = cur;
updateLabels(buffer_);
buffer_.updateLabels();
updateMetrics();
buffer_.changed();

View File

@ -658,7 +658,7 @@ void cutSelection(Cursor & cur, bool doclear, bool realcut)
// need a valid cursor. (Lgb)
cur.clearSelection();
updateLabels(cur.buffer());
cur.buffer().updateLabels();
// tell tabular that a recent copy happened
dirtyTabularStack(false);
@ -818,7 +818,7 @@ void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
boost::tie(ppp, endpit) =
pasteSelectionHelper(cur, parlist, docclass, errorList);
updateLabels(cur.buffer());
cur.buffer().updateLabels();
cur.clearSelection();
text->setCursor(cur, ppp.first, ppp.second);
}

View File

@ -1044,7 +1044,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
makeDisplayPath(fname.absFilename())));
Buffer * buf = lyx_view_->loadDocument(fname, false);
if (buf) {
updateLabels(*buf);
buf->updateLabels();
lyx_view_->setBuffer(buf);
buf->errors("Parse");
}
@ -1140,7 +1140,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break;
}
updateLabels(*buf);
buf->updateLabels();
lyx_view_->setBuffer(buf);
view()->setCursorFromRow(row);
if (loaded)
@ -1294,7 +1294,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// This makes insertion of citations and references in the child work,
// when the target is in the parent or another child document.
child->setParent(buffer);
updateLabels(*child->masterBuffer());
child->masterBuffer()->updateLabels();
lyx_view_->setBuffer(child);
if (parsed)
child->errors("Parse");
@ -1735,7 +1735,7 @@ void LyXFunc::reloadBuffer()
docstring const disp_fn = makeDisplayPath(filename.absFilename());
docstring str;
if (buf) {
updateLabels(*buf);
buf->updateLabels();
lyx_view_->setBuffer(buf);
buf->errors("Parse");
str = bformat(_("Document %1$s reloaded."), disp_fn);
@ -1809,7 +1809,7 @@ void LyXFunc::updateLayout(DocumentClass const * const oldlayout, Buffer * buffe
view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
buffer->errors("Class Switch");
updateLabels(*buffer);
buffer->updateLabels();
}

View File

@ -395,7 +395,7 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
break; // the character couldn't be deleted physically due to change tracking
}
updateLabels(cur.buffer());
cur.buffer().updateLabels();
// A singlePar update is not enough in this case.
cur.updateFlags(Update::Force);
@ -869,7 +869,7 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
cur.clearSelection();
setCursorIntern(cur, begPit, begPos);
cur.updateFlags(Update::Force);
updateLabels(cur.buffer());
cur.buffer().updateLabels();
}
@ -1018,7 +1018,7 @@ bool Text::handleBibitems(Cursor & cur)
cur.recordUndo(ATOMIC_UNDO, prevcur.pit());
mergeParagraph(bufparams, cur.text()->paragraphs(),
prevcur.pit());
updateLabels(cur.buffer());
cur.buffer().updateLabels();
setCursorIntern(cur, prevcur.pit(), prevcur.pos());
cur.updateFlags(Update::Force);
return true;
@ -1046,7 +1046,7 @@ bool Text::erase(Cursor & cur)
cur.top().forwardPos();
if (was_inset)
updateLabels(cur.buffer());
cur.buffer().updateLabels();
else
cur.checkBufferStructure();
needsUpdate = true;
@ -1122,7 +1122,7 @@ bool Text::backspacePos0(Cursor & cur)
}
if (needsUpdate) {
updateLabels(cur.buffer());
cur.buffer().updateLabels();
setCursorIntern(cur, prevcur.pit(), prevcur.pos());
}
@ -1162,7 +1162,7 @@ bool Text::backspace(Cursor & cur)
bool const was_inset = cur.paragraph().isInset(cur.pos());
cur.paragraph().eraseChar(cur.pos(), cur.buffer().params().trackChanges);
if (was_inset)
updateLabels(cur.buffer());
cur.buffer().updateLabels();
else
cur.checkBufferStructure();
}

View File

@ -235,7 +235,7 @@ void Text::setLayout(Cursor & cur, docstring const & layout)
pit_type undopit = undoSpan(end - 1);
recUndo(cur, start, undopit - 1);
setLayout(cur.buffer(), start, end, layout);
updateLabels(cur.buffer());
cur.buffer().updateLabels();
}
@ -294,7 +294,7 @@ void Text::changeDepth(Cursor & cur, DEPTH_CHANGE type)
}
// this handles the counter labels, and also fixes up
// depth values for follow-on (child) paragraphs
updateLabels(cur.buffer());
cur.buffer().updateLabels();
}

View File

@ -1,5 +1,5 @@
/**
* \file text3.cpp
* \file Text3.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
@ -473,7 +473,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
recUndo(cur, pit, pit + 1);
cur.finishUndo();
swap(pars_[pit], pars_[pit + 1]);
updateLabels(cur.buffer());
cur.buffer().updateLabels();
needsUpdate = true;
++cur.pit();
break;
@ -484,7 +484,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
recUndo(cur, pit - 1, pit);
cur.finishUndo();
swap(pars_[pit], pars_[pit - 1]);
updateLabels(cur.buffer());
cur.buffer().updateLabels();
--cur.pit();
needsUpdate = true;
break;
@ -510,14 +510,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
par.params().startOfAppendix(start);
// we can set the refreshing parameters now
updateLabels(cur.buffer());
cur.buffer().updateLabels();
break;
}
case LFUN_WORD_DELETE_FORWARD:
if (cur.selection()) {
if (cur.selection())
cutSelection(cur, true, false);
} else
else
deleteWordForward(cur);
finishChange(cur, false);
break;
@ -1417,7 +1417,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cur.posForward();
// Some insets are numbered, others are shown in the outline pane so
// let's update the labels and the toc backend.
updateLabels(bv->buffer());
bv->buffer().updateLabels();
break;
case LFUN_TABULAR_INSERT:
@ -1471,7 +1471,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
// date metrics.
FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
doInsertInset(cur, cur.text(), cmd_caption, true, false);
updateLabels(bv->buffer());
bv->buffer().updateLabels();
cur.updateFlags(Update::Force);
// FIXME: When leaving the Float (or Wrap) inset we should
// delete any empty paragraph left above or below the
@ -1832,26 +1832,26 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_OUTLINE_UP:
outline(OutlineUp, cur);
setCursor(cur, cur.pit(), 0);
updateLabels(cur.buffer());
cur.buffer().updateLabels();
needsUpdate = true;
break;
case LFUN_OUTLINE_DOWN:
outline(OutlineDown, cur);
setCursor(cur, cur.pit(), 0);
updateLabels(cur.buffer());
cur.buffer().updateLabels();
needsUpdate = true;
break;
case LFUN_OUTLINE_IN:
outline(OutlineIn, cur);
updateLabels(cur.buffer());
cur.buffer().updateLabels();
needsUpdate = true;
break;
case LFUN_OUTLINE_OUT:
outline(OutlineOut, cur);
updateLabels(cur.buffer());
cur.buffer().updateLabels();
needsUpdate = true;
break;

View File

@ -390,7 +390,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
LYXERR(Debug::INFO, "MacroContext not initialised!"
<< " Going through the buffer again and hope"
<< " the context is better then.");
updateLabels(bv_->buffer());
bv_->buffer().updateLabels();
parPos = text_->macrocontextPosition();
LASSERT(!parPos.empty(), /**/);
parPos.pit() = pit;

View File

@ -427,7 +427,7 @@ bool Undo::Private::textUndoOrRedo(DocIterator & cur, bool isUndoOperation)
doTextUndoOrRedo(cur, stack, otherstack);
// Addapt the new material to current buffer.
updateLabels(buffer_);
buffer_.updateLabels();
return true;
}

View File

@ -471,58 +471,4 @@ void updateLabels(Buffer const & buf, ParIterator & parit)
}
}
// FIXME: buf should should be const because updateLabels() modifies
// the contents of the paragraphs.
void updateLabels(Buffer const & buf, bool childonly)
{
// Use the master text class also for child documents
Buffer const * const master = buf.masterBuffer();
DocumentClass const & textclass = master->params().documentClass();
// keep the buffers to be children in this set. If the call from the
// master comes back we can see which of them were actually seen (i.e.
// via an InsetInclude). The remaining ones in the set need still be updated.
static std::set<Buffer const *> bufToUpdate;
if (!childonly) {
// If this is a child document start with the master
if (master != &buf) {
bufToUpdate.insert(&buf);
updateLabels(*master);
// was buf referenced from the master (i.e. not in bufToUpdate anymore)?
if (bufToUpdate.find(&buf) == bufToUpdate.end())
return;
}
// start over the counters in the master
textclass.counters().reset();
}
// update will be done below for buf
bufToUpdate.erase(&buf);
// update all caches
buf.clearReferenceCache();
buf.inset().setBuffer(const_cast<Buffer &>(buf));
buf.updateMacros();
Buffer & cbuf = const_cast<Buffer &>(buf);
BOOST_ASSERT(!buf.text().paragraphs().empty());
// do the real work
ParIterator parit = par_iterator_begin(buf.inset());
updateLabels(buf, parit);
if (master != &buf)
// TocBackend update will be done later.
return;
cbuf.tocBackend().update();
if (!childonly)
cbuf.structureChanged();
}
} // namespace lyx

View File

@ -47,9 +47,6 @@ int countWords(DocIterator const & from, DocIterator const & to);
/// Count the number of chars in the text between these two iterators
int countChars(DocIterator const & from, DocIterator const & to, bool with_blanks);
/// updates all counters
void updateLabels(Buffer const &, bool childonly = false);
///
void updateLabels(Buffer const &, ParIterator &);

View File

@ -99,7 +99,7 @@ void GuiInfo::applyView()
dispatch(FuncRequest(LFUN_INSET_MODIFY, argument));
// FIXME: update the inset contents
updateLabels(bufferview()->buffer());
bufferview()->buffer().updateLabels(false);
BufferView * bv = const_cast<BufferView *>(bufferview());
bv->updateMetrics();
bv->buffer().changed();

View File

@ -1066,7 +1066,7 @@ void GuiView::setBuffer(Buffer * newBuffer)
GuiWorkArea * wa = workArea(*newBuffer);
if (wa == 0) {
updateLabels(*newBuffer->masterBuffer());
newBuffer->masterBuffer()->updateLabels();
wa = addWorkArea(*newBuffer);
} else {
//Disconnect the old buffer...there's no new one.
@ -1438,8 +1438,7 @@ void GuiView::openDocument(string const & fname)
docstring str2;
Buffer * buf = loadDocument(fullname);
if (buf) {
updateLabels(*buf);
buf->updateLabels();
setBuffer(buf);
buf->errors("Parse");
str2 = bformat(_("Document %1$s opened."), disp_fn);
@ -1488,7 +1487,7 @@ static bool import(GuiView * lv, FileName const & filename,
Buffer * buf = lv->loadDocument(lyxfile);
if (!buf)
return false;
updateLabels(*buf);
buf->updateLabels();
lv->setBuffer(buf);
buf->errors("Parse");
} else {

View File

@ -163,7 +163,7 @@ docstring Inset::name() const
void Inset::initView()
{
if (isLabeled())
lyx::updateLabels(buffer());
buffer().updateLabels();
}

View File

@ -90,7 +90,7 @@ void InsetBibitem::updateCommand(docstring const & new_key, bool)
}
setParam("key", key);
lyx::updateLabels(buffer());
buffer().updateLabels();
}

View File

@ -911,7 +911,7 @@ void InsetInclude::updateLabels(ParIterator const & it)
{
Buffer const * const childbuffer = getChildBuffer(buffer(), params());
if (childbuffer) {
lyx::updateLabels(*childbuffer, true);
childbuffer->updateLabels(true);
return;
}
if (!isListings(params()))

View File

@ -81,17 +81,16 @@ void InsetLabel::updateCommand(docstring const & new_label, bool updaterefs)
buffer().undo().endUndoGroup();
// We need an update of the Buffer reference cache. This is achieved by
// updateLabel().
lyx::updateLabels(buffer());
// updateLabels().
buffer().updateLabels();
}
ParamInfo const & InsetLabel::findInfo(string const & /* cmdName */)
{
static ParamInfo param_info_;
if (param_info_.empty()) {
if (param_info_.empty())
param_info_.add("name", ParamInfo::LATEX_REQUIRED);
}
return param_info_;
}

View File

@ -182,7 +182,7 @@ int replaceAll(BufferView * bv,
++num;
}
updateLabels(buf);
buf.updateLabels();
bv->putSelectionAt(doc_iterator_begin(buf.inset()), 0, false);
if (num)
buf.markDirty();

View File

@ -511,9 +511,10 @@ void InsetMathHull::label(row_type row, docstring const & label)
label_[row] = dummy_pointer;
// We need an update of the Buffer reference cache.
// This is achieved by updateLabels().
lyx::updateLabels(buffer());
} else
buffer().updateLabels();
} else {
label_[row]->updateCommand(label);
}
return;
}
InsetCommandParams p(LABEL_CODE);
@ -532,7 +533,7 @@ void InsetMathHull::numbered(row_type row, bool num)
label_[row] = 0;
// We need an update of the Buffer reference cache.
// This is achieved by updateLabels().
lyx::updateLabels(buffer());
buffer().updateLabels();
}
}