]> git.lyx.org Git - features.git/commitdiff
Move the buffer related part from GuiView::renameBuffer to Buffer::saveAs.
authorVincent van Ravesteijn <vfr@lyx.org>
Sun, 7 Nov 2010 21:26:02 +0000 (21:26 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Sun, 7 Nov 2010 21:26:02 +0000 (21:26 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36202 a592a061-630c-0410-9148-cb99ea01b6c8

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

index 1eb7abba0a3e81b97ea74c2103a49b6aa8867195..e2aa7266647b7e175ff0f2e3f39bb490541db421 100644 (file)
@@ -4125,6 +4125,39 @@ Buffer::ReadStatus Buffer::reload()
 }
 
 
+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
index d809068171b151f0a64e84e96aa11f921a8864b4..35d1da1b42eec1df852b50685d7d7dc1e322d3e1 100644 (file)
@@ -177,6 +177,8 @@ public:
            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;
index 5b5ccf6e2c803ccbdff54d0dbc1e4d1a2ce33cfe..eaec019d9519efe029b5e5f21a03519d486f4458 100644 (file)
@@ -2240,50 +2240,30 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
                }
        }
 
-       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;
-       }
-
-       // validate version control data and
-       // correct buffer title
-       b.lyxvc().file_found_hook(b.fileName());
-       b.updateTitles();
+       return saveBuffer(b, fname);
+}
 
-       // 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;
        }
index d8fdb3bb25acc96103f3d642ca38602e6876b9cb..e0ac1ed2f9e3b9bcd17671e20a65f3db5d1aac57 100644 (file)
@@ -370,6 +370,8 @@ private:
        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);