mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
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
This commit is contained in:
parent
bda37148bf
commit
8e7d7e4295
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
// 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;
|
||||
return saveBuffer(b, fname);
|
||||
}
|
||||
|
||||
|
||||
bool GuiView::saveBuffer(Buffer & b)
|
||||
bool GuiView::saveBuffer(Buffer & b) {
|
||||
return saveBuffer(b, FileName());
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user