diff --git a/src/Buffer.cpp b/src/Buffer.cpp index dec742f334..5be6679dca 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -588,7 +588,7 @@ bool Buffer::readDocument(Lexer & lex) FileName const master_file = makeAbsPath(params().master, onlyPath(absFileName())); if (isLyXFilename(master_file.absFilename())) { - Buffer * master = checkAndLoadLyXFile(master_file); + Buffer * master = checkAndLoadLyXFile(master_file, true); d->parent_buffer = master; } } diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 861413dcd9..f82535bae7 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -57,12 +57,15 @@ namespace lyx { namespace Alert = frontend::Alert; -Buffer * checkAndLoadLyXFile(FileName const & filename) +Buffer * checkAndLoadLyXFile(FileName const & filename, bool const acceptDirty) { // File already open? Buffer * checkBuffer = theBufferList().getBuffer(filename); if (checkBuffer) { - if (checkBuffer->isClean()) + // sometimes (when setting the master buffer from a child) + // we accept a dirty buffer right away (otherwise we'd get + // an infinite loop (bug 5514) + if (checkBuffer->isClean() || acceptDirty) return checkBuffer; docstring const file = makeDisplayPath(filename.absFilename(), 20); docstring text = bformat(_( diff --git a/src/buffer_funcs.h b/src/buffer_funcs.h index d34a7406c3..8e67a3fdc6 100644 --- a/src/buffer_funcs.h +++ b/src/buffer_funcs.h @@ -27,7 +27,8 @@ class ParIterator; * \retval the newly created \c Buffer pointer if successful or 0. * \retval 0 if the \c Buffer could not be created. */ -Buffer * checkAndLoadLyXFile(support::FileName const & filename); +Buffer * checkAndLoadLyXFile(support::FileName const & filename, + bool acceptDirty = false); /** Make a new file (buffer) with name \c filename based on a template * named \c templatename