Allow LyX format to be shown in View>Source.

Cherry-picked from b7ac2d69e7.
This commit is contained in:
Richard Heck 2012-07-11 11:20:15 -04:00
parent 1e8f537481
commit 4eab9d49a4
6 changed files with 48 additions and 19 deletions

View File

@ -3215,14 +3215,14 @@ void Buffer::getSourceCode(odocstream & os, string const format,
convert<docstring>(par_end - 1)) convert<docstring>(par_end - 1))
<< "\n\n"; << "\n\n";
} }
TexRow texrow;
texrow.reset();
texrow.newline();
texrow.newline();
// output paragraphs // output paragraphs
if (params().isDocBook()) if (runparams.flavor == OutputParams::LYX) {
docbookParagraphs(text(), *this, os, runparams); Paragraph const & par = text().paragraphs()[par_begin];
else if (runparams.flavor == OutputParams::HTML) { ostringstream ods;
depth_type dt = par.getDepth();
par.write(ods, params(), dt);
os << from_utf8(ods.str());
} else if (runparams.flavor == OutputParams::HTML) {
XHTMLStream xs(os); XHTMLStream xs(os);
setMathFlavor(runparams); setMathFlavor(runparams);
xhtmlParagraphs(text(), *this, xs, runparams); xhtmlParagraphs(text(), *this, xs, runparams);
@ -3232,6 +3232,8 @@ void Buffer::getSourceCode(odocstream & os, string const format,
// Probably should have some routine with a signature like them. // Probably should have some routine with a signature like them.
writePlaintextParagraph(*this, writePlaintextParagraph(*this,
text().paragraphs()[par_begin], os, runparams, dummy); text().paragraphs()[par_begin], os, runparams, dummy);
} else if (params().isDocBook()) {
docbookParagraphs(text(), *this, os, runparams);
} else { } else {
// We need to validate the Buffer params' features here // We need to validate the Buffer params' features here
// in order to know if we should output polyglossia // in order to know if we should output polyglossia
@ -3239,28 +3241,46 @@ void Buffer::getSourceCode(odocstream & os, string const format,
LaTeXFeatures features(*this, params(), runparams); LaTeXFeatures features(*this, params(), runparams);
params().validate(features); params().validate(features);
runparams.use_polyglossia = features.usePolyglossia(); runparams.use_polyglossia = features.usePolyglossia();
TexRow texrow;
texrow.reset();
texrow.newline();
texrow.newline();
// latex or literate // latex or literate
otexstream ots(os, texrow); otexstream ots(os, texrow);
latexParagraphs(*this, text(), ots, runparams); latexParagraphs(*this, text(), ots, runparams);
} }
} else { } else {
os << "% "; os << "% ";
if (output == FullSource) if (output == FullSource)
os << _("Preview source code"); os << _("Preview source code");
else if (output == OnlyPreamble) else if (output == OnlyPreamble)
os << _("Preview preamble"); os << _("Preview preamble");
else if (output == OnlyBody) else if (output == OnlyBody)
os << _("Preview body"); os << _("Preview body");
os << "\n\n"; os << "\n\n";
d->texrow.reset(); if (runparams.flavor == OutputParams::LYX) {
d->texrow.newline(); ostringstream ods;
d->texrow.newline(); if (output == FullSource)
if (params().isDocBook()) write(ods);
writeDocBookSource(os, absFileName(), runparams, output); else if (output == OnlyPreamble)
else if (runparams.flavor == OutputParams::HTML) params().writeFile(ods);
else if (output == OnlyBody)
text().write(ods);
os << from_utf8(ods.str());
} else if (runparams.flavor == OutputParams::HTML) {
writeLyXHTMLSource(os, runparams, output); writeLyXHTMLSource(os, runparams, output);
else { } else if (runparams.flavor == OutputParams::TEXT) {
if (output == OnlyPreamble) {
os << _("% Plaintext does not have a preamble.");
} else
writePlaintextFile(*this, os, runparams);
} else if (params().isDocBook()) {
writeDocBookSource(os, absFileName(), runparams, output);
} else {
// latex or literate // latex or literate
d->texrow.reset();
d->texrow.newline();
d->texrow.newline();
otexstream ots(os, d->texrow); otexstream ots(os, d->texrow);
writeLaTeXSource(ots, string(), runparams, output); writeLaTeXSource(ots, string(), runparams, output);
} }

View File

@ -2181,6 +2181,8 @@ OutputParams::FLAVOR BufferParams::getOutputFlavor(string const format) const
result = OutputParams::LUATEX; result = OutputParams::LUATEX;
else if (dformat == "dviluatex") else if (dformat == "dviluatex")
result = OutputParams::DVILUATEX; result = OutputParams::DVILUATEX;
else if (dformat == "lyx")
result = OutputParams::LYX;
else { else {
// Try to determine flavor of default output format // Try to determine flavor of default output format
vector<string> backs = backends(); vector<string> backs = backends();

View File

@ -35,7 +35,8 @@ public:
XETEX, XETEX,
XML, XML,
HTML, HTML,
TEXT TEXT,
LYX
}; };
enum MathFlavor { enum MathFlavor {

View File

@ -203,11 +203,10 @@ void ViewSourceWidget::updateDefaultFormat()
for (; it != en; ++it) { for (; it != en; ++it) {
string const format = *it; string const format = *it;
Format const * fmt = formats.getFormat(format); Format const * fmt = formats.getFormat(format);
if (!fmt) if (!fmt) {
LYXERR0("Can't find format for backend " << format << "!"); LYXERR0("Can't find format for backend " << format << "!");
else if (fmt->name() == "lyx")
// we can't presently display the LyX format itself
continue; continue;
}
QString const pretty = QString const pretty =
fmt ? qt_(fmt->prettyname()) : toqstr(format); fmt ? qt_(fmt->prettyname()) : toqstr(format);

View File

@ -746,6 +746,9 @@ void InsetExternal::validate(LaTeXFeatures & features) const
case OutputParams::TEXT: case OutputParams::TEXT:
format = "text"; format = "text";
break; break;
case OutputParams::LYX:
format = "lyx";
break;
} }
external::Template::Formats::const_iterator cit = external::Template::Formats::const_iterator cit =
et.formats.find(format); et.formats.find(format);

View File

@ -43,6 +43,8 @@ What's new
- Show backends, not formats, in View>Source (bug #7652). - Show backends, not formats, in View>Source (bug #7652).
- Allow native LyX format to be shown in View>Source.
* DOCUMENTATION AND LOCALIZATION * DOCUMENTATION AND LOCALIZATION
@ -90,6 +92,8 @@ What's new
- Fix enumitem module translation (bug #8201). - Fix enumitem module translation (bug #8201).
- Set math display format when showing XHTML in View>Source.
* DOCUMENTATION AND LOCALIZATION * DOCUMENTATION AND LOCALIZATION