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 } // namespace lyx

View File

@ -466,6 +466,10 @@ public:
void setInsetLabel(docstring const & label, InsetLabel const * il); void setInsetLabel(docstring const & label, InsetLabel const * il);
InsetLabel const * insetLabel(docstring const & label) const; 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: private:
/// search for macro in local (buffer) table or in children /// search for macro in local (buffer) table or in children
MacroData const * getBufferMacro(docstring const & name, MacroData const * getBufferMacro(docstring const & name,

View File

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

View File

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

View File

@ -1044,7 +1044,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
makeDisplayPath(fname.absFilename()))); makeDisplayPath(fname.absFilename())));
Buffer * buf = lyx_view_->loadDocument(fname, false); Buffer * buf = lyx_view_->loadDocument(fname, false);
if (buf) { if (buf) {
updateLabels(*buf); buf->updateLabels();
lyx_view_->setBuffer(buf); lyx_view_->setBuffer(buf);
buf->errors("Parse"); buf->errors("Parse");
} }
@ -1140,7 +1140,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break; break;
} }
updateLabels(*buf); buf->updateLabels();
lyx_view_->setBuffer(buf); lyx_view_->setBuffer(buf);
view()->setCursorFromRow(row); view()->setCursorFromRow(row);
if (loaded) if (loaded)
@ -1294,7 +1294,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// This makes insertion of citations and references in the child work, // This makes insertion of citations and references in the child work,
// when the target is in the parent or another child document. // when the target is in the parent or another child document.
child->setParent(buffer); child->setParent(buffer);
updateLabels(*child->masterBuffer()); child->masterBuffer()->updateLabels();
lyx_view_->setBuffer(child); lyx_view_->setBuffer(child);
if (parsed) if (parsed)
child->errors("Parse"); child->errors("Parse");
@ -1735,7 +1735,7 @@ void LyXFunc::reloadBuffer()
docstring const disp_fn = makeDisplayPath(filename.absFilename()); docstring const disp_fn = makeDisplayPath(filename.absFilename());
docstring str; docstring str;
if (buf) { if (buf) {
updateLabels(*buf); buf->updateLabels();
lyx_view_->setBuffer(buf); lyx_view_->setBuffer(buf);
buf->errors("Parse"); buf->errors("Parse");
str = bformat(_("Document %1$s reloaded."), disp_fn); 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()))); view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
buffer->errors("Class Switch"); 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 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. // A singlePar update is not enough in this case.
cur.updateFlags(Update::Force); cur.updateFlags(Update::Force);
@ -869,7 +869,7 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
cur.clearSelection(); cur.clearSelection();
setCursorIntern(cur, begPit, begPos); setCursorIntern(cur, begPit, begPos);
cur.updateFlags(Update::Force); 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()); cur.recordUndo(ATOMIC_UNDO, prevcur.pit());
mergeParagraph(bufparams, cur.text()->paragraphs(), mergeParagraph(bufparams, cur.text()->paragraphs(),
prevcur.pit()); prevcur.pit());
updateLabels(cur.buffer()); cur.buffer().updateLabels();
setCursorIntern(cur, prevcur.pit(), prevcur.pos()); setCursorIntern(cur, prevcur.pit(), prevcur.pos());
cur.updateFlags(Update::Force); cur.updateFlags(Update::Force);
return true; return true;
@ -1046,7 +1046,7 @@ bool Text::erase(Cursor & cur)
cur.top().forwardPos(); cur.top().forwardPos();
if (was_inset) if (was_inset)
updateLabels(cur.buffer()); cur.buffer().updateLabels();
else else
cur.checkBufferStructure(); cur.checkBufferStructure();
needsUpdate = true; needsUpdate = true;
@ -1122,7 +1122,7 @@ bool Text::backspacePos0(Cursor & cur)
} }
if (needsUpdate) { if (needsUpdate) {
updateLabels(cur.buffer()); cur.buffer().updateLabels();
setCursorIntern(cur, prevcur.pit(), prevcur.pos()); setCursorIntern(cur, prevcur.pit(), prevcur.pos());
} }
@ -1162,7 +1162,7 @@ bool Text::backspace(Cursor & cur)
bool const was_inset = cur.paragraph().isInset(cur.pos()); bool const was_inset = cur.paragraph().isInset(cur.pos());
cur.paragraph().eraseChar(cur.pos(), cur.buffer().params().trackChanges); cur.paragraph().eraseChar(cur.pos(), cur.buffer().params().trackChanges);
if (was_inset) if (was_inset)
updateLabels(cur.buffer()); cur.buffer().updateLabels();
else else
cur.checkBufferStructure(); cur.checkBufferStructure();
} }

View File

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

View File

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

View File

@ -427,7 +427,7 @@ bool Undo::Private::textUndoOrRedo(DocIterator & cur, bool isUndoOperation)
doTextUndoOrRedo(cur, stack, otherstack); doTextUndoOrRedo(cur, stack, otherstack);
// Addapt the new material to current buffer. // Addapt the new material to current buffer.
updateLabels(buffer_); buffer_.updateLabels();
return true; 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 } // 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 /// Count the number of chars in the text between these two iterators
int countChars(DocIterator const & from, DocIterator const & to, bool with_blanks); 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 &); void updateLabels(Buffer const &, ParIterator &);

View File

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

View File

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

View File

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

View File

@ -90,7 +90,7 @@ void InsetBibitem::updateCommand(docstring const & new_key, bool)
} }
setParam("key", key); 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()); Buffer const * const childbuffer = getChildBuffer(buffer(), params());
if (childbuffer) { if (childbuffer) {
lyx::updateLabels(*childbuffer, true); childbuffer->updateLabels(true);
return; return;
} }
if (!isListings(params())) if (!isListings(params()))

View File

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

View File

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

View File

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