BOOST_ASSERT(lyx_view_);
FileName const filename =
makeAbsPath(argument, lyx_view_->buffer()->filePath());
- setMessage(bformat(_("Opening child document %1$s..."),
- makeDisplayPath(filename.absFilename())));
view()->saveBookmark(false);
string const parentfilename = lyx_view_->buffer()->fileName();
if (theBufferList().exists(filename.absFilename()))
lyx_view_->setBuffer(theBufferList().getBuffer(filename.absFilename()));
else
- lyx_view_->loadLyXFile(filename);
- // Set the parent name of the child document.
- // This makes insertion of citations and references in the child work,
- // when the target is in the parent or another child document.
- lyx_view_->buffer()->setParentName(parentfilename);
+ if (lyx_view_->loadLyXFile(filename)) {
+ // Set the parent name of the child document.
+ // This makes insertion of citations and references in the child work,
+ // when the target is in the parent or another child document.
+ lyx_view_->buffer()->setParentName(parentfilename);
+ setMessage(bformat(_("Opening child document %1$s..."),
+ makeDisplayPath(filename.absFilename())));
+ } else
+ setMessage(_("Document not loaded."));
break;
}
}
+bool isInputOrInclude(InsetCommandParams const & params)
+{
+ Types const t = type(params);
+ return (t == INPUT) or (t == INCLUDE);
+}
+
+
string const masterFilename(Buffer const & buffer)
{
return buffer.getMasterBuffer()->fileName();
if (!fs::exists(included_file.toFilesystemEncoding()))
return false;
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;
+ }
}
- if (buf)
- buf->setParentName(parentFilename(buffer));
- return buf != 0;
+ buf->setParentName(parentFilename(buffer));
+ return true;
}
//FIXME RECURSIVE INCLUDE
//This isn't sufficient, as the inclusion could be downstream.
//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"),
bformat(_("Attempted to include file %1$s in itself! "
"Ignoring inclusion."), from_utf8(incfile)));
// write it to a file (so far the complete file)
string const exportfile = changeExtension(incfile, ".tex");
- string const mangled = DocFileName(changeExtension(included_file.absFilename(),
- ".tex")).mangledFilename();
+ string const mangled =
+ DocFileName(changeExtension(included_file.absFilename(),".tex")).
+ mangledFilename();
FileName const writefile(makeAbsPath(mangled, m_buffer->temppath()));
if (!runparams.nice)
if (runparams.inComment || runparams.dryrun)
// Don't try to load or copy the file
- ;
- else if (loadIfNeeded(buffer, params_)) {
+ return true;
+ //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());
if (tmp->params().textclass != m_buffer->params().textclass) {