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));
}
break;
case LFUN_MOUSE_RELEASE:
- InsetIncludeMailer(*this).showDialog(&cur.bv());
+ if (!cur.selection())
+ InsetIncludeMailer(*this).showDialog(&cur.bv());
break;
default:
}
+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 += ": ";
if (!isLyXFilename(included_file))
return 0;
- return theBufferList().getBuffer(included_file);
+ Buffer * childBuffer = theBufferList().getBuffer(included_file);
+
+ //FIXME RECURSIVE INCLUDES
+ if (childBuffer == & buffer)
+ return 0;
+ 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;
}
return 0;
FileName const included_file(includedFilename(buffer, params_));
+
+ //Check we're not trying to include ourselves.
+ //FIXME RECURSIVE INCLUDE
+ //This isn't sufficient, as the inclusion could be downstream.
+ //But it'll have to do for now.
+ 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)));
+ return 0;
+ }
+
Buffer const * const m_buffer = buffer.getMasterBuffer();
// if incfile is relative, make it relative to the master
// 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,
string const included_file = includedFilename(buffer, params_).absFilename();
+ //Check we're not trying to include ourselves.
+ //FIXME RECURSIVE INCLUDE
+ //This isn't sufficient, as the inclusion could be downstream.
+ //But it'll have to do for now.
+ if (buffer.fileName() == included_file) {
+ Alert::error(_("Recursive input"),
+ bformat(_("Attempted to include file %1$s in itself! "
+ "Ignoring inclusion."), from_utf8(incfile)));
+ return 0;
+ }
+
// write it to a file (so far the complete file)
string const exportfile = changeExtension(incfile, ".sgml");
DocFileName writefile(changeExtension(included_file, ".sgml"));
if (loadIfNeeded(buffer, params_)) {
// a file got loaded
Buffer * const tmp = theBufferList().getBuffer(included_file);
- if (tmp) {
+ // make sure the buffer isn't us
+ // FIXME RECURSIVE INCLUDES
+ // This is not sufficient, as recursive includes could be
+ // more than a file away. But it will do for now.
+ if (tmp && tmp != & buffer) {
// We must temporarily change features.buffer,
// otherwise it would always be the master buffer,
// and nested includes would not work.
}
+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)