Author: vfr
Date: Sun Nov  7 22:26:02 2010
New Revision: 36202
URL: http://www.lyx.org/trac/changeset/36202

Log:
Move the buffer related part from GuiView::renameBuffer to Buffer::saveAs.

Modified:
   lyx-devel/trunk/src/Buffer.cpp
   lyx-devel/trunk/src/Buffer.h
   lyx-devel/trunk/src/frontends/qt4/GuiView.cpp
   lyx-devel/trunk/src/frontends/qt4/GuiView.h

Modified: lyx-devel/trunk/src/Buffer.cpp
==============================================================================
--- lyx-devel/trunk/src/Buffer.cpp      Sun Nov  7 22:15:01 2010        (r36201)
+++ lyx-devel/trunk/src/Buffer.cpp      Sun Nov  7 22:26:02 2010        (r36202)
@@ -4125,6 +4125,39 @@
 }
 
 
+bool Buffer::saveAs(FileName const & fn)
+{
+       FileName const old_name = fileName();
+       FileName const old_auto = getAutosaveFileName();
+       bool const old_unnamed = isUnnamed();
+
+       setFileName(fn.absFileName());
+       markDirty();
+       setUnnamed(false);
+
+       if (save()) {
+               // bring the autosave file with us, just in case.
+               moveAutosaveFile(old_auto);
+               // validate version control data and
+               // correct buffer title
+               lyxvc().file_found_hook(fileName());
+               updateTitles();
+               // the file has now been saved to the new location.
+               // we need to check that the locations of child buffers
+               // are still valid.
+               checkChildBuffers();
+               return true;
+       } else {
+               // save failed
+               // reset the old filename and unnamed state
+               setFileName(old_name.absFileName());
+               setUnnamed(old_unnamed);
+               saveCheckSum();
+               return false;
+       }
+}
+
+
 // FIXME We could do better here, but it is complicated. What would be
 // nice is to offer either (a) to save the child buffer to an appropriate
 // location, so that it would "move with the master", or else (b) to update

Modified: lyx-devel/trunk/src/Buffer.h
==============================================================================
--- lyx-devel/trunk/src/Buffer.h        Sun Nov  7 22:15:01 2010        (r36201)
+++ lyx-devel/trunk/src/Buffer.h        Sun Nov  7 22:26:02 2010        (r36202)
@@ -177,6 +177,8 @@
            Returns \c true if the save is successful, \c false otherwise.
        */
        bool save() const;
+       /// Renames and saves the buffer
+       bool saveAs(support::FileName const & fn);
 
        /// Write document to stream. Returns \c false if unsuccesful.
        bool write(std::ostream &) const;

Modified: lyx-devel/trunk/src/frontends/qt4/GuiView.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiView.cpp       Sun Nov  7 22:15:01 
2010        (r36201)
+++ lyx-devel/trunk/src/frontends/qt4/GuiView.cpp       Sun Nov  7 22:26:02 
2010        (r36202)
@@ -2240,50 +2240,30 @@
                }
        }
 
-       FileName oldauto = b.getAutosaveFileName();
-
-       // Ok, change the name of the buffer
-       b.setFileName(fname.absFileName());
-       b.markDirty();
-       bool unnamed = b.isUnnamed();
-       b.setUnnamed(false);
-       b.saveCheckSum();
-
-       // bring the autosave file with us, just in case.
-       b.moveAutosaveFile(oldauto);
-
-       if (!saveBuffer(b)) {
-               oldauto = b.getAutosaveFileName();
-               b.setFileName(oldname.absFileName());
-               b.setUnnamed(unnamed);
-               b.saveCheckSum();
-               b.moveAutosaveFile(oldauto);
-               return false;
-       }
+       return saveBuffer(b, fname);
+}
 
-       // validate version control data and
-       // correct buffer title
-       b.lyxvc().file_found_hook(b.fileName());
-       b.updateTitles();
-
-       // the file has now been saved to the new location.
-       // we need to check that the locations of child buffers
-       // are still valid.
-       b.checkChildBuffers();
 
-       return true;
+bool GuiView::saveBuffer(Buffer & b) {
+       return saveBuffer(b, FileName());
 }
 
 
-bool GuiView::saveBuffer(Buffer & b)
+bool GuiView::saveBuffer(Buffer & b, FileName const & fn)
 {
        if (workArea(b) && workArea(b)->inDialogMode())
                return true;
 
-       if (b.isUnnamed())
-               return renameBuffer(b, docstring());
+       if (fn.empty() && b.isUnnamed())
+                       return renameBuffer(b, docstring());
 
-       if (b.save()) {
+       bool success;
+       if (fn.empty())
+               success = b.save();
+       else
+               success = b.saveAs(fn);
+       
+       if (success) {
                theSession().lastFiles().add(b.fileName());
                return true;
        }

Modified: lyx-devel/trunk/src/frontends/qt4/GuiView.h
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiView.h Sun Nov  7 22:15:01 2010        
(r36201)
+++ lyx-devel/trunk/src/frontends/qt4/GuiView.h Sun Nov  7 22:26:02 2010        
(r36202)
@@ -370,6 +370,8 @@
        bool renameBuffer(Buffer & b, docstring const & newname);
        ///
        bool saveBuffer(Buffer & b);
+       ///
+       bool saveBuffer(Buffer & b, support::FileName const & fn);
        /// closes a workarea, if close_buffer is true the buffer will
        /// also be released, otherwise the buffer will be hidden.
        bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);

Reply via email to