mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-20 23:07:43 +00:00
Cheap fix for #6554. When we save a Buffer to a new location, we check
the included insets and make sure that the files they reference are still where they are supposed to be. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33686 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4a07f1d0e2
commit
42a2a0f289
@ -3920,4 +3920,41 @@ bool Buffer::reload()
|
||||
}
|
||||
|
||||
|
||||
// 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
|
||||
// the InsetInclude so that it pointed to the same file. But (a) is a bit
|
||||
// complicated, because the code for this lives in GuiView.
|
||||
void Buffer::checkChildBuffers()
|
||||
{
|
||||
Impl::BufferPositionMap::iterator it = d->children_positions.begin();
|
||||
Impl::BufferPositionMap::iterator const en = d->children_positions.end();
|
||||
for (; it != en; ++it) {
|
||||
DocIterator dit = it->second;
|
||||
Buffer * cbuf = const_cast<Buffer *>(it->first);
|
||||
if (!cbuf || !theBufferList().isLoaded(cbuf))
|
||||
continue;
|
||||
Inset * inset = dit.nextInset();
|
||||
LASSERT(inset && inset->lyxCode() == INCLUDE_CODE, continue);
|
||||
InsetInclude * inset_inc = static_cast<InsetInclude *>(inset);
|
||||
docstring const & incfile = inset_inc->getParam("filename");
|
||||
string oldloc = cbuf->absFileName();
|
||||
string newloc = makeAbsPath(to_utf8(incfile),
|
||||
onlyPath(absFileName())).absFilename();
|
||||
if (oldloc == newloc)
|
||||
continue;
|
||||
// the location of the child file is incorrect.
|
||||
Alert::warning(_("Included File Invalid"),
|
||||
bformat(_("Saving this document to a new location has made the file:\n"
|
||||
" %1$s\n"
|
||||
"inaccessible. You will need to update the included filename."),
|
||||
from_utf8(oldloc)));
|
||||
cbuf->setParent(0);
|
||||
inset_inc->setChildBuffer(0);
|
||||
}
|
||||
// invalidate cache of children
|
||||
d->children_positions.clear();
|
||||
d->position_to_children.clear();
|
||||
}
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -561,6 +561,8 @@ public:
|
||||
/// \return progress if a new word was found.
|
||||
int spellCheck(DocIterator & from, DocIterator & to,
|
||||
WordLangTuple & word_lang, docstring_list & suggestions) const;
|
||||
///
|
||||
void checkChildBuffers();
|
||||
|
||||
private:
|
||||
///
|
||||
|
@ -2083,6 +2083,7 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
|
||||
fname.changeExtension(".lyx");
|
||||
}
|
||||
|
||||
// fname is now the new Buffer location.
|
||||
if (FileName(fname).exists()) {
|
||||
docstring const file = makeDisplayPath(fname.absFilename(), 30);
|
||||
docstring text = bformat(_("The document %1$s already "
|
||||
@ -2119,6 +2120,11 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user