mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-07 12:32:26 +00:00
Fix for bugs 2199 and 3667. Most of the changes were to the logic. Buffers
that were opened for possible included LyX files need to be closed if those files cannot be loaded, for example. A bit more work was needed to allow a LyX file to include itself as a verbatim or listings without trying to load itself and without relying upon loadIfNeeded() to report the problem. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18494 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d396035606
commit
d2fb80eec7
@ -1413,18 +1413,20 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
BOOST_ASSERT(lyx_view_);
|
BOOST_ASSERT(lyx_view_);
|
||||||
FileName const filename =
|
FileName const filename =
|
||||||
makeAbsPath(argument, lyx_view_->buffer()->filePath());
|
makeAbsPath(argument, lyx_view_->buffer()->filePath());
|
||||||
setMessage(bformat(_("Opening child document %1$s..."),
|
|
||||||
makeDisplayPath(filename.absFilename())));
|
|
||||||
view()->saveBookmark(false);
|
view()->saveBookmark(false);
|
||||||
string const parentfilename = lyx_view_->buffer()->fileName();
|
string const parentfilename = lyx_view_->buffer()->fileName();
|
||||||
if (theBufferList().exists(filename.absFilename()))
|
if (theBufferList().exists(filename.absFilename()))
|
||||||
lyx_view_->setBuffer(theBufferList().getBuffer(filename.absFilename()));
|
lyx_view_->setBuffer(theBufferList().getBuffer(filename.absFilename()));
|
||||||
else
|
else
|
||||||
lyx_view_->loadLyXFile(filename);
|
if (lyx_view_->loadLyXFile(filename)) {
|
||||||
// Set the parent name of the child document.
|
// Set the parent name of the child document.
|
||||||
// This makes insertion of citations and references in the child work,
|
// This makes insertion of citations and references in the child work,
|
||||||
// when the target is in the parent or another child document.
|
// when the target is in the parent or another child document.
|
||||||
lyx_view_->buffer()->setParentName(parentfilename);
|
lyx_view_->buffer()->setParentName(parentfilename);
|
||||||
|
setMessage(bformat(_("Opening child document %1$s..."),
|
||||||
|
makeDisplayPath(filename.absFilename())));
|
||||||
|
} else
|
||||||
|
setMessage(_("Document not loaded."));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,6 +230,13 @@ bool isVerbatim(InsetCommandParams const & params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool isInputOrInclude(InsetCommandParams const & params)
|
||||||
|
{
|
||||||
|
Types const t = type(params);
|
||||||
|
return (t == INPUT) or (t == INCLUDE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
string const masterFilename(Buffer const & buffer)
|
string const masterFilename(Buffer const & buffer)
|
||||||
{
|
{
|
||||||
return buffer.getMasterBuffer()->fileName();
|
return buffer.getMasterBuffer()->fileName();
|
||||||
@ -393,12 +400,14 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
|
|||||||
if (!fs::exists(included_file.toFilesystemEncoding()))
|
if (!fs::exists(included_file.toFilesystemEncoding()))
|
||||||
return false;
|
return false;
|
||||||
buf = theBufferList().newBuffer(included_file.absFilename());
|
buf = theBufferList().newBuffer(included_file.absFilename());
|
||||||
if (!loadLyXFile(buf, included_file))
|
if (!loadLyXFile(buf, included_file)) {
|
||||||
|
//close the buffer we just opened
|
||||||
|
theBufferList().close(buf, false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (buf)
|
}
|
||||||
buf->setParentName(parentFilename(buffer));
|
buf->setParentName(parentFilename(buffer));
|
||||||
return buf != 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -420,7 +429,9 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
|
|||||||
//FIXME RECURSIVE INCLUDE
|
//FIXME RECURSIVE INCLUDE
|
||||||
//This isn't sufficient, as the inclusion could be downstream.
|
//This isn't sufficient, as the inclusion could be downstream.
|
||||||
//But it'll have to do for now.
|
//But it'll have to do for now.
|
||||||
if (!isListings(params_) && buffer.fileName() == included_file.toFilesystemEncoding()) {
|
if (isInputOrInclude(params_) &&
|
||||||
|
buffer.fileName() == included_file.toFilesystemEncoding())
|
||||||
|
{
|
||||||
Alert::error(_("Recursive input"),
|
Alert::error(_("Recursive input"),
|
||||||
bformat(_("Attempted to include file %1$s in itself! "
|
bformat(_("Attempted to include file %1$s in itself! "
|
||||||
"Ignoring inclusion."), from_utf8(incfile)));
|
"Ignoring inclusion."), from_utf8(incfile)));
|
||||||
@ -439,8 +450,9 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
|
|||||||
|
|
||||||
// write it to a file (so far the complete file)
|
// write it to a file (so far the complete file)
|
||||||
string const exportfile = changeExtension(incfile, ".tex");
|
string const exportfile = changeExtension(incfile, ".tex");
|
||||||
string const mangled = DocFileName(changeExtension(included_file.absFilename(),
|
string const mangled =
|
||||||
".tex")).mangledFilename();
|
DocFileName(changeExtension(included_file.absFilename(),".tex")).
|
||||||
|
mangledFilename();
|
||||||
FileName const writefile(makeAbsPath(mangled, m_buffer->temppath()));
|
FileName const writefile(makeAbsPath(mangled, m_buffer->temppath()));
|
||||||
|
|
||||||
if (!runparams.nice)
|
if (!runparams.nice)
|
||||||
@ -451,8 +463,14 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
|
|||||||
|
|
||||||
if (runparams.inComment || runparams.dryrun)
|
if (runparams.inComment || runparams.dryrun)
|
||||||
// Don't try to load or copy the file
|
// Don't try to load or copy the file
|
||||||
;
|
return true;
|
||||||
else if (loadIfNeeded(buffer, params_)) {
|
//if it's a LyX file and we're including or inputting it...
|
||||||
|
else if (isInputOrInclude(params_) &&
|
||||||
|
isLyXFilename(included_file.absFilename())) {
|
||||||
|
//try to load it so we can write the associated latex
|
||||||
|
if (!loadIfNeeded(buffer, params_))
|
||||||
|
return false;
|
||||||
|
|
||||||
Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
|
Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
|
||||||
|
|
||||||
if (tmp->params().textclass != m_buffer->params().textclass) {
|
if (tmp->params().textclass != m_buffer->params().textclass) {
|
||||||
|
Loading…
Reference in New Issue
Block a user