From: Vincent van Ravesteijn Date: Sun, 7 Nov 2010 21:26:02 +0000 (+0000) Subject: Move the buffer related part from GuiView::renameBuffer to Buffer::saveAs. X-Git-Tag: 2.0.0~1922 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8e7d7e42952f0119db1c192386a63d1d9ede3b7f;p=features.git Move the buffer related part from GuiView::renameBuffer to Buffer::saveAs. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36202 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 1eb7abba0a..e2aa726664 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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 diff --git a/src/Buffer.h b/src/Buffer.h index d809068171..35d1da1b42 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -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; diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 5b5ccf6e2c..eaec019d95 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -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; } diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index d8fdb3bb25..e0ac1ed2f9 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -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);