]> git.lyx.org Git - features.git/commitdiff
Generalize Buffer::autoSave() for both the threaded as the forked process call. Also...
authorVincent van Ravesteijn <vfr@lyx.org>
Wed, 17 Nov 2010 02:18:12 +0000 (02:18 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Wed, 17 Nov 2010 02:18:12 +0000 (02:18 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36325 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/frontends/qt4/GuiView.cpp

index e2aa7266647b7e175ff0f2e3f39bb490541db421..c9d0b63800772a2f7d2f796f6163873421b38e33 100644 (file)
@@ -2025,6 +2025,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
 
        case LFUN_BUFFER_AUTO_SAVE:
                autoSave();
+               resetAutosaveTimers();
                break;
 
        case LFUN_BRANCH_ADD: {
@@ -3270,23 +3271,36 @@ void Buffer::moveAutosaveFile(support::FileName const & oldauto) const
 }
 
 
-// Perfect target for a thread...
-void Buffer::autoSave() const
+bool Buffer::autoSave() const 
 {
-       if (d->bak_clean || isReadonly()) {
-               // We don't save now, but we'll try again later
-               resetAutosaveTimers();
-               return;
-       }
+       Buffer const * buf = d->cloned_buffer_ ? d->cloned_buffer_ : this;
+       if (buf->d->bak_clean || isReadonly())
+               return true;
 
-       // emit message signal.
        message(_("Autosaving current document..."));
-       AutoSaveBuffer autosave(*this, getAutosaveFileName());
-       autosave.start();
-
-       d->bak_clean = true;
-
-       resetAutosaveTimers();
+       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;
+       }
 }
 
 
index 35d1da1b42eec1df852b50685d7d7dc1e322d3e1..68f8b883171bc36a9051fe365d013cfffee81271 100644 (file)
@@ -235,8 +235,8 @@ private:
 public:
        /// \name Functions involved in autosave and emergency files.
        //@{
-       ///
-       void autoSave() const;
+       /// Save an autosave file to #filename.lyx#
+       bool autoSave() const;  
        /// save emergency file
        /// \return a status message towards the user.
        docstring emergencyWrite();
index 249968cdfb40cebb01cf681cb70558633f12073d..f8a15cdcccdb2266f856f9dc2abc38588356d631 100644 (file)
@@ -1530,6 +1530,7 @@ void GuiView::autoSave()
        d.autosave_watcher_.setFuture(f);
 #else
        buffer->autoSave();
+       resetAutosaveTimers();
 #endif
 }