InsetInclude::InsetInclude(InsetCommandParams const & p)
: params_(p), include_label(uniqueID()),
preview_(new RenderMonitoredPreview(this)),
- set_label_(false)
+ set_label_(false), counter_(0)
{
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
}
params_(other.params_),
include_label(other.include_label),
preview_(new RenderMonitoredPreview(this)),
- set_label_(false)
+ set_label_(false), counter_(0)
{
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
}
}
+bool isInputOrInclude(InsetCommandParams const & params)
+{
+ Types const t = type(params);
+ return (t == INPUT) || (t == INCLUDE);
+}
+
+
string const masterFilename(Buffer const & buffer)
{
return buffer.getMasterBuffer()->fileName();
case INCLUDE:
temp += buf.B_("Include");
break;
- case LISTINGS:
- temp += buf.B_("Program Listing");
+ case LISTINGS: {
+ if (counter_ > 0)
+ temp += buf.B_("Program Listing ") + convert<docstring>(counter_);
+ else
+ temp += buf.B_("Program Listing");
break;
+ }
}
temp += ": ";
//FIXME RECURSIVE INCLUDES
if (childBuffer == & buffer)
return 0;
- else return childBuffer;
+ else
+ return childBuffer;
}
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)
LYXERR(Debug::LATEX) << "exportfile:" << exportfile << endl;
LYXERR(Debug::LATEX) << "writefile:" << writefile << endl;
- if (runparams.inComment || runparams.dryrun)
- // Don't try to load or copy the file
- ;
- else if (loadIfNeeded(buffer, params_)) {
+ if (runparams.inComment || runparams.dryrun) {
+ //Don't try to load or copy the file if we're
+ //in a comment or doing a dryrun
+ } else if (isInputOrInclude(params_) &&
+ isLyXFilename(included_file.absFilename())) {
+ //if it's a LyX file and we're inputting or including,
+ //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) {
runparams, false);
runparams.encoding = oldEnc;
} else {
- // Copy the file to the temp dir, so that .aux files etc.
- // are not created in the original dir. Files included by
- // this file will be found via input@path, see ../Buffer.cpp.
+ // In this case, it's not a LyX file, so we copy the file
+ // to the temp dir, so that .aux files etc. are not created
+ // in the original dir. Files included by this file will be
+ // found via input@path, see ../Buffer.cpp.
unsigned long const checksum_in = sum(included_file);
unsigned long const checksum_out = sum(writefile);
// opt is set in QInclude dialog and should have passed validation.
InsetListingsParams params(opt);
if (!params.params().empty())
- os << "[" << from_utf8(params.encodedString()) << "]";
+ os << "[" << from_utf8(params.params()) << "]";
os << '{' << from_utf8(incfile) << '}';
} else {
runparams.exportdata->addExternalFile(tex_format, writefile,
}
+void InsetInclude::updateCounter(Counters & counters)
+{
+ if (!isListings(params_))
+ return;
+
+ InsetListingsParams const par = params_.getOptions();
+ if (par.getParamValue("caption").empty())
+ counter_ = 0;
+ else {
+ counters.step(from_ascii("listing"));
+ counter_ = counters.value(from_ascii("listing"));
+ }
+}
+
+
string const InsetIncludeMailer::name_("include");
InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset)