#include "OutputParams.h"
#include "TocBackend.h"
-#include "frontends/Alert.h"
+#include "frontends/alert.h"
#include "frontends/Painter.h"
#include "graphics/PreviewImage.h"
#include "graphics/PreviewLoader.h"
#include "insets/RenderPreview.h"
+#include "insets/InsetListingsParams.h"
#include "support/filetools.h"
#include "support/lstrings.h" // contains
using support::DocFileName;
using support::FileName;
using support::getFileContents;
+using support::getVectorFromString;
using support::isFileReadable;
using support::isLyXFilename;
using support::latex_path;
using support::makeRelPath;
using support::onlyFilename;
using support::onlyPath;
+using support::prefixIs;
using support::subst;
using support::sum;
using std::istringstream;
using std::ostream;
using std::ostringstream;
+using std::vector;
namespace Alert = frontend::Alert;
namespace fs = boost::filesystem;
return "file" + convert<docstring>(++seed);
}
+
+bool isListings(InsetCommandParams const & params)
+{
+ return params.getCmdName() == "lstinputlisting";
+}
+
} // namespace anon
InsetInclude::InsetInclude(InsetInclude const & other)
- : InsetOld(other),
+ : Inset(other),
params_(other.params_),
include_label(other.include_label),
preview_(new RenderMonitoredPreview(this)),
InsetCommandParams p("include");
InsetIncludeMailer::string2params(to_utf8(cmd.argument()), p);
if (!p.getCmdName().empty()) {
+ if (isListings(p)){
+ InsetListingsParams par_old(params().getOptions());
+ InsetListingsParams par_new(p.getOptions());
+ if (par_old.getParamValue("label") !=
+ par_new.getParamValue("label")
+ && !par_new.getParamValue("label").empty())
+ cur.bv().buffer()->changeRefsIfUnique(
+ from_utf8(par_old.getParamValue("label")),
+ from_utf8(par_new.getParamValue("label")),
+ Inset::REF_CODE);
+ }
set(p, cur.buffer());
cur.buffer().updateBibfilesCache();
} else
break;
case LFUN_MOUSE_RELEASE:
- InsetIncludeMailer(*this).showDialog(&cur.bv());
+ if (!cur.selection())
+ InsetIncludeMailer(*this).showDialog(&cur.bv());
break;
default:
- InsetBase::doDispatch(cur, cmd);
+ Inset::doDispatch(cur, cmd);
break;
}
}
return true;
default:
- return InsetBase::getStatus(cur, cmd, flag);
+ return Inset::getStatus(cur, cmd, flag);
}
}
INCLUDE = 0,
VERB = 1,
INPUT = 2,
- VERBAST = 3
+ VERBAST = 3,
+ LISTINGS = 4,
};
return VERB;
if (command_name == "verbatiminput*")
return VERBAST;
+ if (command_name == "lstinputlisting")
+ return LISTINGS;
return INCLUDE;
}
}
-auto_ptr<InsetBase> InsetInclude::doClone() const
+auto_ptr<Inset> InsetInclude::doClone() const
{
- return auto_ptr<InsetBase>(new InsetInclude(*this));
+ return auto_ptr<Inset>(new InsetInclude(*this));
}
}
-docstring const InsetInclude::getScreenLabel(Buffer const &) const
+docstring const InsetInclude::getScreenLabel(Buffer const & buf) const
{
docstring temp;
switch (type(params_)) {
case INPUT:
- temp += _("Input");
+ temp += buf.B_("Input");
break;
case VERB:
- temp += _("Verbatim Input");
+ temp += buf.B_("Verbatim Input");
break;
case VERBAST:
- temp += _("Verbatim Input*");
+ temp += buf.B_("Verbatim Input*");
break;
case INCLUDE:
- temp += _("Include");
+ temp += buf.B_("Include");
+ break;
+ case LISTINGS:
+ temp += buf.B_("Program Listing");
break;
}
/// return the child buffer if the file is a LyX doc and is loaded
Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params)
{
- if (isVerbatim(params))
+ if (isVerbatim(params) || isListings(params))
return 0;
string const included_file = includedFilename(buffer, params).absFilename();
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;
}
/// return true if the file is or got loaded.
bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
{
- if (isVerbatim(params))
+ if (isVerbatim(params) || isListings(params))
return false;
FileName const included_file = includedFilename(buffer, params);
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 (!isListings(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
"has textclass `%2$s'\n"
"while parent file has textclass `%3$s'."),
makeDisplayPath(included_file.absFilename()),
- from_utf8(tmp->params().getLyXTextClass().name()),
- from_utf8(m_buffer->params().getLyXTextClass().name()));
+ from_utf8(tmp->params().getTextClass().name()),
+ from_utf8(m_buffer->params().getTextClass().name()));
Alert::warning(_("Different textclasses"), text);
//return 0;
}
os << '\\' << from_ascii(params_.getCmdName())
<< '{' << from_utf8(incfile) << '}';
}
+ } else if (type(params_) == LISTINGS) {
+ os << '\\' << from_ascii(params_.getCmdName());
+ string opt = params_.getOptions();
+ // 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(incfile) << '}';
} else {
runparams.exportdata->addExternalFile(tex_format, writefile,
exportfile);
int InsetInclude::plaintext(Buffer const & buffer, odocstream & os,
OutputParams const &) const
{
- if (isVerbatim(params_)) {
+ if (isVerbatim(params_) || isListings(params_)) {
os << '[' << getScreenLabel(buffer) << '\n';
// FIXME: We don't know the encoding of the file
docstring const str =
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"));
runparams.exportdata->addExternalFile("docbook-xml", writefile,
exportfile);
- if (isVerbatim(params_)) {
+ if (isVerbatim(params_) || isListings(params_)) {
os << "<inlinegraphic fileref=\""
<< '&' << include_label << ';'
<< "\" format=\"linespecific\">";
else
writefile = included_file;
- if (!features.runparams().nice && !isVerbatim(params_)) {
+ if (!features.runparams().nice && !isVerbatim(params_) && !isListings(params_)) {
incfile = DocFileName(writefile).mangledFilename();
writefile = makeAbsPath(incfile,
buffer.getMasterBuffer()->temppath()).absFilename();
if (isVerbatim(params_))
features.require("verbatim");
+ else if (isListings(params_))
+ features.require("listings");
// Here we must do the fun stuff...
// Load the file in the include if it needs
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::getLabelList(Buffer const & buffer,
std::vector<docstring> & list) const
{
- if (loadIfNeeded(buffer, params_)) {
+ if (isListings(params_)) {
+ InsetListingsParams params(params_.getOptions());
+ string label = params.getParamValue("label");
+ if (!label.empty())
+ list.push_back(from_utf8(label));
+ }
+ else if (loadIfNeeded(buffer, params_)) {
string const included_file = includedFilename(buffer, params_).absFilename();
Buffer * tmp = theBufferList().getBuffer(included_file);
tmp->setParentName("");
button_.draw(pi, x, y);
}
-bool InsetInclude::display() const
+
+Inset::DisplayType InsetInclude::display() const
{
- return type(params_) != INPUT;
+ return type(params_) == INPUT ? Inline : AlignCenter;
}
return print_mailer_error("InsetIncludeMailer", in, 1, name_);
// This is part of the inset proper that is usually swallowed
- // by LyXText::readInset
+ // by Text::readInset
string id;
lex >> id;
if (!lex || id != "Include")