]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Add a member to TocItem that tells us whether the item in question
[lyx.git] / src / Buffer.cpp
index ebc5d3ae30c112f1bb729102d6dacaa1a759b60f..b646cf6619982519c34ed52c32bc455f61b34445 100644 (file)
@@ -99,7 +99,7 @@
 #include "support/lyxalgo.h"
 #include "support/os.h"
 #include "support/Package.h"
-#include "support/Path.h"
+#include "support/PathChanger.h"
 #include "support/Systemcall.h"
 #include "support/textutils.h"
 #include "support/types.h"
@@ -282,7 +282,8 @@ public:
 
        /// This is here to force the test to be done whenever parent_buffer
        /// is accessed.
-       Buffer const * parent() const {
+       Buffer const * parent() const
+       {
                // ignore_parent temporarily "orphans" a buffer
                // (e.g. if a child is compiled standalone)
                if (ignore_parent)
@@ -299,7 +300,8 @@ public:
        }
 
        ///
-       void setParent(Buffer const * pb) {
+       void setParent(Buffer const * pb)
+       {
                if (parent_buffer == pb)
                        // nothing to do
                        return;
@@ -324,10 +326,14 @@ public:
        /// \p from initial position
        /// \p to points to the end position
        void updateStatistics(DocIterator & from, DocIterator & to,
-                                                 bool skipNoOutput = true);
+                             bool skipNoOutput = true);
        /// statistics accessor functions
-       int wordCount() const { return word_count_; }
-       int charCount(bool with_blanks) const {
+       int wordCount() const
+       {
+               return word_count_;
+       }
+       int charCount(bool with_blanks) const
+       {
                return char_count_
                + (with_blanks ? blank_count_ : 0);
        }
@@ -493,7 +499,7 @@ Buffer::~Buffer()
 Buffer * Buffer::cloneFromMaster() const
 {
        BufferMap bufmap;
-       cloned_buffers.push_back(new CloneList());
+       cloned_buffers.push_back(new CloneList);
        CloneList * clones = cloned_buffers.back();
 
        masterBuffer()->cloneWithChildren(bufmap, clones);
@@ -549,7 +555,7 @@ void Buffer::cloneWithChildren(BufferMap & bufmap, CloneList * clones) const
 
 
 Buffer * Buffer::cloneBufferOnly() const {
-       cloned_buffers.push_back(new CloneList());
+       cloned_buffers.push_back(new CloneList);
        CloneList * clones = cloned_buffers.back();
        Buffer * buffer_clone = new Buffer(fileName().absFileName(), false, this);
        clones->insert(buffer_clone);
@@ -755,7 +761,10 @@ void Buffer::setReadonly(bool const flag)
 
 void Buffer::setFileName(FileName const & fname)
 {
+       bool const changed = fname != d->filename;
        d->filename = fname;
+       if (changed)
+               lyxvc().file_found_hook(fname);
        setReadonly(d->filename.isReadOnly());
        saveCheckSum();
        updateTitles();
@@ -2112,6 +2121,13 @@ void Buffer::addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const
 }
 
 
+void Buffer::makeCitationLabels() const
+{
+       Buffer const * const master = masterBuffer();
+       return d->bibinfo_.makeCitationLabels(*master);
+}
+
+
 bool Buffer::citeLabelsValid() const
 {
        return masterBuffer()->d->cite_labels_valid_;
@@ -2244,8 +2260,11 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
 
        switch (func.action()) {
        case LFUN_BUFFER_TOGGLE_READ_ONLY:
-               if (lyxvc().inUse())
-                       lyxvc().toggleReadOnly();
+               if (lyxvc().inUse()) {
+                       string log = lyxvc().toggleReadOnly();
+                       if (!log.empty())
+                               dr.setMessage(log);
+               }
                else
                        setReadonly(!isReadonly());
                break;
@@ -3619,26 +3638,19 @@ bool Buffer::autoSave() const
        buf->d->bak_clean = true;
 
        FileName const fname = getAutosaveFileName();
-       if (d->cloned_buffer_) {
-               // If this buffer is cloned, we assume that
-               // we are running in a separate thread already.
-               FileName const tmp_ret = FileName::tempName("lyxauto");
-               if (!tmp_ret.empty()) {
-                       writeFile(tmp_ret);
-                       // assume successful write of tmp_ret
-                       if (tmp_ret.moveTo(fname))
-                               return true;
-               }
-               // failed to write/rename tmp_ret so try writing direct
-               return writeFile(fname);
-       } else {
-               /// This function is deprecated as the frontend needs to take care
-               /// of cloning the buffer and autosaving it in another thread. It
-               /// is still here to allow (QT_VERSION < 0x040400).
-               AutoSaveBuffer autosave(*this, fname);
-               autosave.start();
-               return true;
+       LASSERT(d->cloned_buffer_, return false);
+
+       // If this buffer is cloned, we assume that
+       // we are running in a separate thread already.
+       FileName const tmp_ret = FileName::tempName("lyxauto");
+       if (!tmp_ret.empty()) {
+               writeFile(tmp_ret);
+               // assume successful write of tmp_ret
+               if (tmp_ret.moveTo(fname))
+                       return true;
        }
+       // failed to write/rename tmp_ret so try writing direct
+       return writeFile(fname);
 }
 
 
@@ -4022,6 +4034,7 @@ Buffer::ReadStatus Buffer::loadEmergency()
                                        "file."), from_utf8(d->filename.absFileName())));
                        }
                        markDirty();
+                       lyxvc().file_found_hook(d->filename);
                        str = _("Document was successfully recovered.");
                } else
                        str = _("Document was NOT successfully recovered.");
@@ -4085,6 +4098,7 @@ Buffer::ReadStatus Buffer::loadAutosave()
                                        from_utf8(d->filename.absFileName())));
                        }
                        markDirty();
+                       lyxvc().file_found_hook(d->filename);
                        return ReadSuccess;
                }
                return ReadAutosaveFailure;
@@ -4242,7 +4256,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
 
        d->bibinfo_cache_valid_ = true;
        d->cite_labels_valid_ = true;
-       cbuf.tocBackend().update();
+       cbuf.tocBackend().update(true);
        if (scope == UpdateMaster)
                cbuf.structureChanged();
 }
@@ -4350,17 +4364,6 @@ void Buffer::Impl::setLabel(ParIterator & it, UpdateType utype) const
        }
 
        switch(layout.labeltype) {
-       case LABEL_COUNTER:
-               if (layout.toclevel <= bp.secnumdepth
-                     && (layout.latextype != LATEX_ENVIRONMENT
-                         || it.text()->isFirstInSequence(it.pit()))) {
-                       if (counters.hasCounter(layout.counter))
-                               counters.step(layout.counter, utype);
-                       par.params().labelString(par.expandLabel(layout, bp));
-               } else
-                       par.params().labelString(docstring());
-               break;
-
        case LABEL_ITEMIZE: {
                // At some point of time we should do something more
                // clever here, like:
@@ -4440,13 +4443,27 @@ void Buffer::Impl::setLabel(ParIterator & it, UpdateType utype) const
                par.params().labelString(docstring());
                break;
 
+       case LABEL_ABOVE:
+       case LABEL_CENTERED:
+       case LABEL_STATIC: {
+               docstring const & lcounter = layout.counter;
+               if (!lcounter.empty()) {
+                       if (layout.toclevel <= bp.secnumdepth
+                                               && (layout.latextype != LATEX_ENVIRONMENT
+                                       || it.text()->isFirstInSequence(it.pit()))) {
+                               if (counters.hasCounter(lcounter))
+                                       counters.step(lcounter, utype);
+                               par.params().labelString(par.expandLabel(layout, bp));
+                       } else
+                               par.params().labelString(docstring());
+               } else
+                       par.params().labelString(par.expandLabel(layout, bp));
+               break;
+       }
+
        case LABEL_MANUAL:
-       case LABEL_TOP_ENVIRONMENT:
-       case LABEL_CENTERED_TOP_ENVIRONMENT:
-       case LABEL_STATIC:
        case LABEL_BIBLIO:
                par.params().labelString(par.expandLabel(layout, bp));
-               break;
        }
 }