]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Improve how add_to_preamble and insert_to_preamble work, and audit the
[lyx.git] / src / Buffer.cpp
index 1c53b8a53b87168dea5360674a0dcc3cfd3e3824..feaf141f4af13e35f92f1dd4cd1cb427c274d497 100644 (file)
@@ -414,9 +414,8 @@ Buffer::~Buffer()
                        from_utf8(d->temppath.absFileName())));
        }
 
-       // Remove any previewed LaTeX snippets associated with this buffer.
        if (!isClone())
-               thePreviews().removeLoader(*this);
+               removePreviews();
 
        delete d;
 }
@@ -876,6 +875,9 @@ Buffer::ReadStatus Buffer::readFile(FileName const & fn)
                return readFile(tmpFile);
        }
 
+       // InsetInfo needs to know if file is under VCS
+       lyxvc().file_found_hook(fn);
+
        if (readDocument(lex)) {
                Alert::error(_("Document format failure"),
                        bformat(_("%1$s ended unexpectedly, which means"
@@ -885,8 +887,6 @@ Buffer::ReadStatus Buffer::readFile(FileName const & fn)
        }
 
        d->file_fully_loaded = true;
-       // InsetInfo needs to know if file is under VCS
-       lyxvc().file_found_hook(fn);
        d->read_only = !fname.isWritable();
        params().compressed = fname.isZippedFile();
        saveCheckSum();
@@ -906,6 +906,19 @@ void Buffer::setFullyLoaded(bool value)
 }
 
 
+void Buffer::updatePreviews() const
+{
+       if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
+               thePreviews().generateBufferPreviews(*this);
+}
+
+
+void Buffer::removePreviews() const
+{
+       thePreviews().removeLoader(*this);
+}
+
+
 Buffer::ReadStatus Buffer::parseLyXFormat(Lexer & lex,
        FileName const & fn, int & file_format) const
 {
@@ -3638,6 +3651,7 @@ Buffer::ReadStatus Buffer::loadEmergency(FileName const & fn)
                bool const success = (ret_llf == ReadSuccess);
                if (success) {
                        markDirty();
+                       lyxvc().file_found_hook(fn);
                        str = _("Document was successfully recovered.");
                } else
                        str = _("Document was NOT successfully recovered.");
@@ -3693,6 +3707,7 @@ Buffer::ReadStatus Buffer::loadAutosave(FileName const & fn)
                // the file is not saved if we load the autosave file.
                if (ret_llf == ReadSuccess) {
                        markDirty();
+                       lyxvc().file_found_hook(fn);
                        return ReadSuccess;
                }
                return ReadAutosaveFailure;
@@ -4111,15 +4126,13 @@ Buffer::ReadStatus Buffer::reload()
                changed(true);
                updateTitles();
                markClean();
-               saveCheckSum();
                message(bformat(_("Document %1$s reloaded."), disp_fn));
        } else {
                message(bformat(_("Could not reload document %1$s."), disp_fn));
        }       
        setBusy(false);
-       thePreviews().removeLoader(*this);
-       if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
-               thePreviews().generateBufferPreviews(*this);
+       removePreviews();
+       updatePreviews();
        errors("Parse");
        return status;
 }