]> git.lyx.org Git - features.git/blobdiff - src/Buffer.cpp
move updateLables to buffer
[features.git] / src / Buffer.cpp
index f46f7b0029b45ac33d6c10efe0f5371bcd5a0f3f..d7ab7ab52e4b202b88990d524b0eb095f3df0b26 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author Stefan Schimanski
  *
  * Full author contact details are available in file CREDITS.
@@ -115,7 +115,9 @@ namespace os = support::os;
 
 namespace {
 
-int const LYX_FORMAT = 342; //uwestoehr: support for Mongolian
+// Do not remove the comment below, so we get merge conflict in
+// independent branches. Instead add your own.
+int const LYX_FORMAT = 345;  // jamatos: xml elements
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
@@ -275,6 +277,11 @@ Buffer::~Buffer()
        // GuiView already destroyed
        gui_ = 0;
 
+       if (d->unnamed && d->filename.extension() == "internal") {
+               // No need to do additional cleanups for internal buffer.
+               delete d;
+               return;
+       }
 
        // loop over children
        Impl::BufferPositionMap::iterator it = d->children_positions.begin();
@@ -367,6 +374,12 @@ string const Buffer::temppath() const
 }
 
 
+TexRow & Buffer::texrow()
+{
+       return d->texrow;
+}
+
+
 TexRow const & Buffer::texrow() const
 {
        return d->texrow;
@@ -949,7 +962,7 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
        string const encoding = runparams.encoding->iconvName();
        LYXERR(Debug::LATEX, "makeLaTeXFile encoding: " << encoding << "...");
 
-       odocfstream ofs;
+       ofdocstream ofs;
        try { ofs.reset(encoding); }
        catch (iconv_codecvt_facet_exception & e) {
                lyxerr << "Caught iconv exception: " << e.what() << endl;
@@ -1168,7 +1181,7 @@ void Buffer::makeDocBookFile(FileName const & fname,
 {
        LYXERR(Debug::LATEX, "makeDocBookFile...");
 
-       odocfstream ofs;
+       ofdocstream ofs;
        if (!openFileWrite(ofs, fname))
                return;
 
@@ -2114,10 +2127,11 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
                os << "% " << _("Preview source code") << "\n\n";
                d->texrow.newline();
                d->texrow.newline();
-               if (isLatex())
-                       writeLaTeXSource(os, filePath(), runparams, true, true);
-               else
+               if (isDocBook())
                        writeDocBookSource(os, absFileName(), runparams, false);
+               else
+                       // latex or literate
+                       writeLaTeXSource(os, string(), runparams, true, true);
        } else {
                runparams.par_begin = par_begin;
                runparams.par_end = par_end;
@@ -2135,11 +2149,11 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
                d->texrow.newline();
                d->texrow.newline();
                // output paragraphs
-               if (isLatex())
-                       latexParagraphs(*this, text(), os, d->texrow, runparams);
-               else
-                       // DocBook
+               if (isDocBook())
                        docbookParagraphs(paragraphs(), *this, os, runparams);
+               else 
+                       // latex or literate
+                       latexParagraphs(*this, text(), os, d->texrow, runparams);
        }
 }
 
@@ -2629,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