}
+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
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;
}
}
- 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;
}
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);