]> git.lyx.org Git - lyx.git/commitdiff
Fix another prompt for externally-modified bug with writeAs()
authorBo Peng <bpeng@lyx.org>
Thu, 6 Sep 2007 15:54:17 +0000 (15:54 +0000)
committerBo Peng <bpeng@lyx.org>
Thu, 6 Sep 2007 15:54:17 +0000 (15:54 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20107 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/callback.cpp

index 3eeb7d0d1b4dd1f8e8d2efe87c5ca1f75b009d7f..dc2d85f9d24bc488c5db79ed2da738c0048af753 100644 (file)
@@ -756,8 +756,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                string diskfile = filename.toFilesystemEncoding();
                if (suffixIs(diskfile, ".emergency"))
                        diskfile = diskfile.substr(0, diskfile.size() - 10);
-               pimpl_->timestamp_ = fs::last_write_time(diskfile);
-               pimpl_->checksum_ = sum(FileName(diskfile));
+               saveCheckSum(diskfile);
        }
 
        if (file_format != LYX_FORMAT) {
@@ -874,8 +873,7 @@ bool Buffer::save() const
        if (writeFile(pimpl_->filename)) {
                markClean();
                removeAutosaveFile(fileName());
-               pimpl_->timestamp_ = fs::last_write_time(pimpl_->filename.toFilesystemEncoding());
-               pimpl_->checksum_ = sum(pimpl_->filename);
+               saveCheckSum(pimpl_->filename.toFilesystemEncoding());
                return true;
        } else {
                // Saving failed, so backup is not backup
@@ -1634,6 +1632,19 @@ bool Buffer::isExternallyModified(CheckMethod method) const
 }
 
 
+void Buffer::saveCheckSum(string const & file) const
+{
+       if (fs::exists(file)) {
+               pimpl_->timestamp_ = fs::last_write_time(file);
+               pimpl_->checksum_ = sum(FileName(file));
+       } else {
+               // in the case of save to a new file.
+               pimpl_->timestamp_ = 0;
+               pimpl_->checksum_ = 0;
+       }
+}
+
+
 void Buffer::markClean() const
 {
        if (!pimpl_->lyx_clean) {
index 6e5ba14546cc6c98b0394826ae4fc825c023ef90..7d18ab65e2870904b943a0f0750c0fbb137c75d9 100644 (file)
@@ -229,6 +229,9 @@ public:
        /// whether or not disk file has been externally modified
        bool isExternallyModified(CheckMethod method) const;
 
+       /// save timestamp and checksum of the given file.
+       void saveCheckSum(std::string const & file) const;
+
        /// mark the main lyx file as not needing saving
        void markClean() const;
 
index 87da777504f519179e7e3c60a1a64034485a1762..2a41494be6f48791f17427a676d0799f278fc0ef 100644 (file)
@@ -195,10 +195,12 @@ bool writeAs(Buffer * buffer, string const & newname)
        buffer->markDirty();
        bool unnamed = buffer->isUnnamed();
        buffer->setUnnamed(false);
+       buffer->saveCheckSum(fname);
 
        if (!menuWrite(buffer)) {
                buffer->setFileName(oldname);
                buffer->setUnnamed(unnamed);
+               buffer->saveCheckSum(oldname);
                return false;
        }