]> git.lyx.org Git - features.git/commitdiff
move updateLables to buffer
authorAndré Pönitz <poenitz@gmx.net>
Sun, 16 Nov 2008 16:43:49 +0000 (16:43 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sun, 16 Nov 2008 16:43:49 +0000 (16:43 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27562 a592a061-630c-0410-9148-cb99ea01b6c8

20 files changed:
src/Buffer.cpp
src/Buffer.h
src/BufferView.cpp
src/CutAndPaste.cpp
src/LyXFunc.cpp
src/Text.cpp
src/Text2.cpp
src/Text3.cpp
src/TextMetrics.cpp
src/Undo.cpp
src/buffer_funcs.cpp
src/buffer_funcs.h
src/frontends/qt4/GuiInfo.cpp
src/frontends/qt4/GuiView.cpp
src/insets/Inset.cpp
src/insets/InsetBibitem.cpp
src/insets/InsetInclude.cpp
src/insets/InsetLabel.cpp
src/lyxfind.cpp
src/mathed/InsetMathHull.cpp

index d63160b6b6286bfb20809f37e8a4c77b35dab28a..d7ab7ab52e4b202b88990d524b0eb095f3df0b26 100644 (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
index 23ac227a8e3f5814242d80987c3c184ca3a52b58..db5f9737e2af97b8b5dc188ae85fc9d44c8b6aa5 100644 (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,
index 57c74a34da092496d26520b914453d4085ea125c..b463778ef31567e31ec08a0b7a50da8be749f9be 100644 (file)
@@ -1858,7 +1858,7 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old)
 
        d->cursor_ = cur;
 
-       updateLabels(buffer_);
+       buffer_.updateLabels();
 
        updateMetrics();
        buffer_.changed();
index dd436eee455b54b76e7dbffc6be75e7062c0ca75..f367dde1bddc742fbb5ae1272a8d970e7b260a99 100644 (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);
        }
index 1bea019eb917054221b099fd430bb33aea7b68a9..b8600360cddd06caa15793e8358632e361b70d36 100644 (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();
 }
 
 
index 51c6a26a69491497f05fcb09bf0dc5ec81126c7a..cb6a0d10c9dbbee3a87c8481b52e9185080effdb 100644 (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();
        }
index 71cbfefc069b1478290b9ab0e576484d43fb05d6..a224dc75eb260b97b26b9f730e43c9b40e13747b 100644 (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();
 }
 
 
index 595c0343a5d443b62ff95c97b9494aa76f3ccb69..517fcd28cf968859a3ba672897d91d55f1f9ec84 100644 (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;
 
index ce942ce3f2907def24e5020198f4ee53f0b867ec..37b779312562d260a5401e43321e166115af2a97 100644 (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;
index a0e84e43ec7ccdfd4a2bc209bab2d97e90ec82c5..2acc1a36ba191419d80ad3a1bd236a934f78bdfd 100644 (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;
 }
 
index f37a74194515506aa57e1920afe40b1855543f42..9e0350a9ef43d06a65a03c59b24c11f91f44e9dc 100644 (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
index 23049161d608efa63816a2653437a235652b453c..55780ec63bfe0eccdbf768819c09ace86fbaaa4e 100644 (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 &);
 
index 929360efaf7b54d73152431681819b2a4e430ae7..fc71f85d87a42d6a472ece86ac150c03fae7b481 100644 (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();
index d45b939466d13423f016a57126e83ea31b171bf9..be58dc71c066165eefb330cb48ca741d3f2de46a 100644 (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 {
index a3ab48708740773cafb0070b3254499466157fec..2321ce6809899c3fc6975967c557712bd5a97068 100644 (file)
@@ -163,7 +163,7 @@ docstring Inset::name() const
 void Inset::initView()
 {
        if (isLabeled())
-               lyx::updateLabels(buffer());
+               buffer().updateLabels();
 }
 
 
index b9194833023b5e1d9ae77a599e6584bc37f64631..0eb0d3dbd1867706a8f50b2a9e0234beab5a40d8 100644 (file)
@@ -90,7 +90,7 @@ void InsetBibitem::updateCommand(docstring const & new_key, bool)
        }
        setParam("key", key);
 
-       lyx::updateLabels(buffer());
+       buffer().updateLabels();
 }
 
 
index 8723257d6f77891e486e9e2219dcc97349d31345..9267d02de4fa8cc680ad40f09b7ded09350e487a 100644 (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()))
index 823a22fefc297c4899a5bf20b587274e7ee5d29c..0b671b2c0fd6478ac7eb0967443ae14454587932 100644 (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_;
 }
 
index 685f1f91eaf0a94894cfdb56f8a099baafce8234..d7c0fee879972b0b10a45c025f71ed15ba2095bd 100644 (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();
index 5e0402b21df45622effdf829dfc165f5129b1913..f65f7db3df1c01475c330b85c2b1b91971b641f8 100644 (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();
        }
 }