void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
{
- LASSERT(cur.buffer() == &buffer(), return);
switch (cmd.action) {
case LFUN_INSET_EDIT: {
bool InsetInclude::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
- LYXERR0(cmd.action);
switch (cmd.action) {
case LFUN_INSET_EDIT:
- case LFUN_INSET_MODIFY:
flag.setEnabled(true);
return true;
+ case LFUN_INSET_MODIFY:
+ if (cmd.getArg(0) == "changetype")
+ return InsetCommand::getStatus(cur, cmd, flag);
+ else
+ flag.setEnabled(true);
+ return true;
+
default:
return InsetCommand::getStatus(cur, cmd, flag);
}
Buffer * InsetInclude::loadIfNeeded() const
{
// Don't try to load it again if we failed before.
- if (failedtoload_)
+ if (failedtoload_ || isVerbatim(params()) || isListings(params()))
return 0;
// Use cached Buffer if possible.
child_buffer_ = 0;
}
- InsetCommandParams const & p = params();
- if (isVerbatim(p) || isListings(p))
- return 0;
-
string const parent_filename = buffer().absFileName();
FileName const included_file =
- makeAbsPath(to_utf8(p["filename"]), onlyPath(parent_filename));
+ makeAbsPath(to_utf8(params()["filename"]), onlyPath(parent_filename));
if (!isLyXFilename(included_file.absFilename()))
return 0;
// if incfile is relative, make it relative to the master
// buffer directory.
- if (!FileName(incfile).isAbsolute()) {
+ if (!FileName::isAbsolute(incfile)) {
// FIXME UNICODE
incfile = to_utf8(makeRelPath(from_utf8(included_file.absFilename()),
from_utf8(masterBuffer->filePath())));
}
// Make sure modules used in child are all included in master
- //FIXME It might be worth loading the children's modules into the master
- //over in BufferParams rather than doing this check.
+ // FIXME It might be worth loading the children's modules into the master
+ // over in BufferParams rather than doing this check.
LayoutModuleList const masterModules = masterBuffer->params().getModules();
LayoutModuleList const childModules = tmp->params().getModules();
LayoutModuleList::const_iterator it = childModules.begin();
tmp->markDepClean(masterBuffer->temppath());
-// FIXME: handle non existing files
-// FIXME: Second argument is irrelevant!
-// since only_body is true, makeLaTeXFile will not look at second
-// argument. Should we set it to string(), or should makeLaTeXFile
-// make use of it somehow? (JMarc 20031002)
+ // FIXME: handle non existing files
+ // FIXME: Second argument is irrelevant!
+ // since only_body is true, makeLaTeXFile will not look at second
+ // argument. Should we set it to string(), or should makeLaTeXFile
+ // make use of it somehow? (JMarc 20031002)
// The included file might be written in a different encoding
Encoding const * const oldEnc = runparams.encoding;
runparams.encoding = &tmp->params().encoding();
string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
"latex" : "pdflatex";
- if (isVerbatim(params())) {
+ switch (type(params())) {
+ case VERB:
+ case VERBAST: {
incfile = latex_path(incfile);
// FIXME UNICODE
os << '\\' << from_ascii(params().getCmdName()) << '{'
<< from_utf8(incfile) << '}';
- } else if (type(params()) == INPUT) {
+ break;
+ }
+ case INPUT: {
runparams.exportdata->addExternalFile(tex_format, writefile,
exportfile);
os << '\\' << from_ascii(params().getCmdName())
<< '{' << from_utf8(incfile) << '}';
}
- } else if (type(params()) == LISTINGS) {
+ break;
+ }
+ case LISTINGS: {
os << '\\' << from_ascii(params().getCmdName());
string const opt = to_utf8(params()["lstparams"]);
// opt is set in QInclude dialog and should have passed validation.
if (!params.params().empty())
os << "[" << from_utf8(params.params()) << "]";
os << '{' << from_utf8(incfile) << '}';
- } else {
+ break;
+ }
+ case INCLUDE: {
runparams.exportdata->addExternalFile(tex_format, writefile,
exportfile);
// FIXME UNICODE
os << '\\' << from_ascii(params().getCmdName()) << '{'
<< from_utf8(incfile) << '}';
+ break;
+ }
+ case NONE:
+ break;
}
return 0;
}
+docstring InsetInclude::xhtml(odocstream & os, OutputParams const &rp) const
+{
+ if (rp.inComment)
+ return docstring();
+
+ // For verbatim and listings, we just include the contents of the file as-is.
+ // In the case of listings, we wrap it in <pre>.
+ bool const listing = isListings(params());
+ if (listing || isVerbatim(params())) {
+ if (listing)
+ os << "<pre>\n";
+ // FIXME: We don't know the encoding of the file, default to UTF-8.
+ os << includedFilename(buffer(), params()).fileContents("UTF-8");
+ if (listing)
+ os << "</pre>\n";
+ return docstring();
+ }
+
+ // We don't (yet) know how to Input or Include non-LyX files.
+ // (If we wanted to get really arcane, we could run some tex2html
+ // converter on the included file. But that's just masochistic.)
+ string const parent_filename = buffer().absFileName();
+ FileName const included_file =
+ makeAbsPath(to_utf8(params()["filename"]), onlyPath(parent_filename));
+ if (!isLyXFilename(included_file.absFilename())) {
+ frontend::Alert::warning(_("Unsupported Inclusion"),
+ _("LyX does not know how to include non-LyX files when "
+ "generating HTML output. Offending file: ") +
+ params()["filename"]);
+ return docstring();
+ }
+
+ // In the other cases, we will generate the HTML and include it.
+
+ // Check we're not trying to include ourselves.
+ // FIXME RECURSIVE INCLUDE
+ if (buffer().absFileName() == included_file.absFilename()) {
+ Alert::error(_("Recursive input"),
+ bformat(_("Attempted to include file %1$s in itself! "
+ "Ignoring inclusion."), params()["filename"]));
+ return docstring();
+ }
+
+ Buffer const * const ibuf = loadIfNeeded();
+ if (!ibuf)
+ return docstring();
+ ibuf->writeLyXHTMLSource(os, rp, true);
+ return docstring();
+}
+
+
int InsetInclude::plaintext(odocstream & os, OutputParams const &) const
{
if (isVerbatim(params()) || isListings(params())) {