From: André Pönitz Date: Sun, 16 Nov 2008 16:43:49 +0000 (+0000) Subject: move updateLables to buffer X-Git-Tag: 2.0.0~7710 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f8f5a7b28d4c6fb432055911b81d01505696e66b;p=features.git move updateLables to buffer git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27562 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index d63160b6b6..d7ab7ab52e 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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 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(*this)); + updateMacros(); + + Buffer & cbuf = const_cast(*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 diff --git a/src/Buffer.h b/src/Buffer.h index 23ac227a8e..db5f9737e2 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -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, diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 57c74a34da..b463778ef3 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1858,7 +1858,7 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old) d->cursor_ = cur; - updateLabels(buffer_); + buffer_.updateLabels(); updateMetrics(); buffer_.changed(); diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index dd436eee45..f367dde1bd 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -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); } diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 1bea019eb9..b8600360cd 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -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(); } diff --git a/src/Text.cpp b/src/Text.cpp index 51c6a26a69..cb6a0d10c9 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -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(); } diff --git a/src/Text2.cpp b/src/Text2.cpp index 71cbfefc06..a224dc75eb 100644 --- a/src/Text2.cpp +++ b/src/Text2.cpp @@ -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(); } diff --git a/src/Text3.cpp b/src/Text3.cpp index 595c0343a5..517fcd28cf 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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; diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index ce942ce3f2..37b7793125 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -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; diff --git a/src/Undo.cpp b/src/Undo.cpp index a0e84e43ec..2acc1a36ba 100644 --- a/src/Undo.cpp +++ b/src/Undo.cpp @@ -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; } diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index f37a741945..9e0350a9ef 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -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 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(buf)); - buf.updateMacros(); - - Buffer & cbuf = const_cast(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 diff --git a/src/buffer_funcs.h b/src/buffer_funcs.h index 23049161d6..55780ec63b 100644 --- a/src/buffer_funcs.h +++ b/src/buffer_funcs.h @@ -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 &); diff --git a/src/frontends/qt4/GuiInfo.cpp b/src/frontends/qt4/GuiInfo.cpp index 929360efaf..fc71f85d87 100644 --- a/src/frontends/qt4/GuiInfo.cpp +++ b/src/frontends/qt4/GuiInfo.cpp @@ -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()); bv->updateMetrics(); bv->buffer().changed(); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index d45b939466..be58dc71c0 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -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 { diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index a3ab487087..2321ce6809 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -163,7 +163,7 @@ docstring Inset::name() const void Inset::initView() { if (isLabeled()) - lyx::updateLabels(buffer()); + buffer().updateLabels(); } diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp index b919483302..0eb0d3dbd1 100644 --- a/src/insets/InsetBibitem.cpp +++ b/src/insets/InsetBibitem.cpp @@ -90,7 +90,7 @@ void InsetBibitem::updateCommand(docstring const & new_key, bool) } setParam("key", key); - lyx::updateLabels(buffer()); + buffer().updateLabels(); } diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 8723257d6f..9267d02de4 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -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())) diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index 823a22fefc..0b671b2c0f 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -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_; } diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 685f1f91ea..d7c0fee879 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -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(); diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 5e0402b21d..f65f7db3df 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -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(); } }