bool Buffer::makeLaTeXFile(FileName const & fname,
string const & original_path,
OutputParams const & runparams_in,
- bool output_preamble, bool output_body) const
+ OutputWhat output) const
{
OutputParams runparams = runparams_in;
otexstream os(ofs, d->texrow);
try {
os.texrow().reset();
- writeLaTeXSource(os, original_path,
- runparams, output_preamble, output_body);
+ writeLaTeXSource(os, original_path, runparams, output);
}
catch (EncodingException & e) {
odocstringstream ods;
void Buffer::writeLaTeXSource(otexstream & os,
string const & original_path,
OutputParams const & runparams_in,
- bool const output_preamble, bool const output_body) const
+ OutputWhat output) const
{
// The child documents, if any, shall be already loaded at this point.
validate(features);
LYXERR(Debug::LATEX, " Buffer validation done.");
+ bool const output_preamble =
+ output == FullSource || output == OnlyPreamble;
+ bool const output_body =
+ output == FullSource || output == OnlyBody;
+
// The starting paragraph of the coming rows is the
// first paragraph of the document. (Asger)
if (output_preamble && runparams.nice) {
void Buffer::makeDocBookFile(FileName const & fname,
OutputParams const & runparams,
- bool const body_only) const
+ OutputWhat output) const
{
LYXERR(Debug::LATEX, "makeDocBookFile...");
if (!openFileWrite(ofs, fname))
return;
- writeDocBookSource(ofs, fname.absFileName(), runparams, body_only);
+ writeDocBookSource(ofs, fname.absFileName(), runparams, output);
ofs.close();
if (ofs.fail())
void Buffer::writeDocBookSource(odocstream & os, string const & fname,
OutputParams const & runparams,
- bool const only_body) const
+ OutputWhat output) const
{
LaTeXFeatures features(*this, params(), runparams);
validate(features);
DocumentClass const & tclass = params().documentClass();
string const top_element = tclass.latexname();
- if (!only_body) {
+ bool const output_preamble =
+ output == FullSource || output == OnlyPreamble;
+ bool const output_body =
+ output == FullSource || output == OnlyBody;
+
+ if (output_preamble) {
if (runparams.flavor == OutputParams::XML)
os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
os << ">\n\n";
}
- string top = top_element;
- top += " lang=\"";
- if (runparams.flavor == OutputParams::XML)
- top += params().language->code();
- else
- top += params().language->code().substr(0, 2);
- top += '"';
-
- if (!params().options.empty()) {
- top += ' ';
- top += params().options;
- }
-
- os << "<!-- " << ((runparams.flavor == OutputParams::XML)? "XML" : "SGML")
- << " file was created by LyX " << lyx_version
- << "\n See http://www.lyx.org/ for more information -->\n";
-
- params().documentClass().counters().reset();
-
- updateMacros();
+ if (output_body) {
+ string top = top_element;
+ top += " lang=\"";
+ if (runparams.flavor == OutputParams::XML)
+ top += params().language->code();
+ else
+ top += params().language->code().substr(0, 2);
+ top += '"';
+
+ if (!params().options.empty()) {
+ top += ' ';
+ top += params().options;
+ }
+
+ os << "<!-- " << ((runparams.flavor == OutputParams::XML)? "XML" : "SGML")
+ << " file was created by LyX " << lyx_version
+ << "\n See http://www.lyx.org/ for more information -->\n";
+
+ params().documentClass().counters().reset();
+
+ updateMacros();
- sgml::openTag(os, top);
- os << '\n';
- docbookParagraphs(text(), *this, os, runparams);
- sgml::closeTag(os, top_element);
+ sgml::openTag(os, top);
+ os << '\n';
+ docbookParagraphs(text(), *this, os, runparams);
+ sgml::closeTag(os, top_element);
+ }
}
if (!openFileWrite(ofs, fname))
return;
- writeLyXHTMLSource(ofs, runparams, body_only);
+ writeLyXHTMLSource(ofs, runparams, FullSource);
ofs.close();
if (ofs.fail())
void Buffer::writeLyXHTMLSource(odocstream & os,
OutputParams const & runparams,
- bool const only_body) const
+ OutputWhat output) const
{
LaTeXFeatures features(*this, params(), runparams);
validate(features);
updateMacros();
updateMacroInstances(OutputUpdate);
- if (!only_body) {
+ bool const output_preamble =
+ output == FullSource || output == OnlyPreamble;
+ bool const output_body =
+ output == FullSource || output == OnlyBody;
+
+ if (output_preamble) {
os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
<< "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN\" \"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd\">\n"
// FIXME Language should be set properly.
<< ";\n";
os << "}\n</style>\n";
}
- os << "</head>\n<body>\n";
+ os << "</head>\n";
+ }
+
+ if (output_body) {
+ os << "<body>\n";
+ XHTMLStream xs(os);
+ params().documentClass().counters().reset();
+ xhtmlParagraphs(text(), *this, xs, runparams);
+ os << "</body>\n";
}
- XHTMLStream xs(os);
- params().documentClass().counters().reset();
- xhtmlParagraphs(text(), *this, xs, runparams);
- if (!only_body)
- os << "</body>\n</html>\n";
+ if (output_preamble)
+ os << "</html>\n";
}
void Buffer::getSourceCode(odocstream & os, string const format,
pit_type par_begin, pit_type par_end,
- bool full_source) const
+ OutputWhat output) const
{
OutputParams runparams(¶ms().encoding());
runparams.nice = true;
// No side effect of file copying and image conversion
runparams.dryrun = true;
- if (full_source) {
- os << "% " << _("Preview source code") << "\n\n";
- d->texrow.reset();
- d->texrow.newline();
- d->texrow.newline();
- if (params().isDocBook())
- writeDocBookSource(os, absFileName(), runparams, false);
- else if (runparams.flavor == OutputParams::HTML)
- writeLyXHTMLSource(os, runparams, false);
- else {
- // latex or literate
- otexstream ots(os, d->texrow);
- writeLaTeXSource(ots, string(), runparams, true, true);
- }
- } else {
+ if (output == CurrentParagraph) {
runparams.par_begin = par_begin;
runparams.par_end = par_end;
if (par_begin + 1 == par_end) {
otexstream ots(os, texrow);
latexParagraphs(*this, text(), ots, runparams);
}
+ } else {
+ os << "% ";
+ if (output == FullSource)
+ os << _("Preview source code");
+ else if (output == OnlyPreamble)
+ os << _("Preview preamble");
+ else if (output == OnlyBody)
+ os << _("Preview body");
+ os << "\n\n";
+ d->texrow.reset();
+ d->texrow.newline();
+ d->texrow.newline();
+ if (params().isDocBook())
+ writeDocBookSource(os, absFileName(), runparams, output);
+ else if (runparams.flavor == OutputParams::HTML)
+ writeLyXHTMLSource(os, runparams, output);
+ else {
+ // latex or literate
+ otexstream ots(os, d->texrow);
+ writeLaTeXSource(ots, string(), runparams, output);
+ }
}
}
/// Fill in the ErrorList with the TeXErrors
void bufferErrors(TeXErrors const &, ErrorList &) const;
+ enum OutputWhat {
+ FullSource,
+ OnlyBody,
+ OnlyPreamble,
+ CurrentParagraph
+ };
+
/// Just a wrapper for writeLaTeXSource, first creating the ofstream.
bool makeLaTeXFile(support::FileName const & filename,
std::string const & original_path,
OutputParams const &,
- bool output_preamble = true,
- bool output_body = true) const;
+ OutputWhat output = FullSource) const;
/** Export the buffer to LaTeX.
If \p os is a file stream, and params().inputenc is "auto" or
"default", and the buffer contains text in different languages
void writeLaTeXSource(otexstream & os,
std::string const & original_path,
OutputParams const &,
- bool output_preamble = true,
- bool output_body = true) const;
+ OutputWhat output = FullSource) const;
///
void makeDocBookFile(support::FileName const & filename,
OutputParams const & runparams_in,
- bool only_body = false) const;
+ OutputWhat output = FullSource) const;
///
void writeDocBookSource(odocstream & os, std::string const & filename,
OutputParams const & runparams_in,
- bool only_body = false) const;
+ OutputWhat output = FullSource) const;
///
void makeLyXHTMLFile(support::FileName const & filename,
OutputParams const & runparams_in,
///
void writeLyXHTMLSource(odocstream & os,
OutputParams const & runparams_in,
- bool only_body = false) const;
+ OutputWhat output = FullSource) const;
/// returns the main language for the buffer (document)
Language const * language() const;
/// get l10n translated to the buffers language
/// get source code (latex/docbook) for some paragraphs, or all paragraphs
/// including preamble
void getSourceCode(odocstream & os, std::string const format,
- pit_type par_begin, pit_type par_end, bool full_source) const;
+ pit_type par_begin, pit_type par_end, OutputWhat output) const;
/// Access to error list.
/// This method is used only for GUI visualisation of Buffer related
if (!(*it)->isDepClean(masterTmpDir)) {
string writefile = addName(masterTmpDir, (*it)->latexName());
(*it)->makeLaTeXFile(FileName(writefile), masterTmpDir,
- runparams, false);
+ runparams, Buffer::OnlyBody);
(*it)->markDepClean(masterTmpDir);
}
}
{
setupUi(this);
- connect(viewFullSourceCB, SIGNAL(clicked()),
- this, SLOT(fullSourceChanged()));
+ connect(contentsCO, SIGNAL(activated(int)),
+ this, SLOT(contentsChanged()));
connect(autoUpdateCB, SIGNAL(toggled(bool)),
updatePB, SLOT(setDisabled(bool)));
connect(autoUpdateCB, SIGNAL(toggled(bool)),
\param fullSource get full source code
\return true if the content has changed since last call.
*/
-static bool getContent(BufferView const * view, bool fullSource,
+static bool getContent(BufferView const * view, Buffer::OutputWhat output,
QString & qstr, string const format, bool force_getcontent)
{
// get the *top* level paragraphs that contain the cursor,
if (par_begin > par_end)
swap(par_begin, par_end);
odocstringstream ostr;
- view->buffer().getSourceCode(ostr, format, par_begin, par_end + 1, fullSource);
+ view->buffer().getSourceCode(ostr, format, par_begin, par_end + 1, output);
docstring s = ostr.str();
static size_t crc = 0;
size_t newcrc = crcCheck(s);
}
-void ViewSourceWidget::fullSourceChanged()
+void ViewSourceWidget::contentsChanged()
{
if (autoUpdateCB->isChecked())
updateView();
outputFormatCO->currentIndex()).toString());
QString content;
- if (getContent(bv_, viewFullSourceCB->isChecked(), content,
- format, force_getcontent_))
+ Buffer::OutputWhat output = Buffer::CurrentParagraph;
+ if (contentsCO->currentIndex() == 1)
+ output = Buffer::FullSource;
+ else if (contentsCO->currentIndex() == 2)
+ output = Buffer::OnlyPreamble;
+ else if (contentsCO->currentIndex() == 3)
+ output = Buffer::OnlyBody;
+
+ if (getContent(bv_, output, content, format, force_getcontent_))
document_->setPlainText(content);
CursorSlice beg = bv_->cursor().selectionBegin().bottom();
{
Dialog::saveSession();
QSettings settings;
- settings.setValue(
- sessionKey() + "/fullsource", widget_->viewFullSourceCB->isChecked());
+ // see below
+ // settings.setValue(
+ // sessionKey() + "/output", widget_->contentsCO->currentIndex());
settings.setValue(
sessionKey() + "/autoupdate", widget_->autoUpdateCB->isChecked());
}
{
DockView::restoreSession();
// FIXME: Full source updating is too slow to be done at startup.
- //widget_->viewFullSourceCB->setChecked(
- // settings.value(sessionKey() + "/fullsource", false).toBool());
- widget_->viewFullSourceCB->setChecked(false);
+ //widget_->outputCO-setCurrentIndex(
+ // settings.value(sessionKey() + "/output", false).toInt());
+ widget_->contentsCO->setCurrentIndex(0);
QSettings settings;
widget_->autoUpdateCB->setChecked(
settings.value(sessionKey() + "/autoupdate", true).toBool());
///
void updateDefaultFormat();
///
- void fullSourceChanged();
+ void contentsChanged();
private:
///
+<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ViewSourceUi</class>
<widget class="QWidget" name="ViewSourceUi">
<rect>
<x>0</x>
<y>0</y>
- <width>452</width>
- <height>120</height>
+ <width>528</width>
+ <height>205</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
- <layout class="QGridLayout" name="gridLayout_2">
- <item row="0" column="0">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" rowspan="5">
<widget class="QTextEdit" name="viewSourceTV">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Ignored">
</widget>
</item>
<item row="0" column="1">
- <layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="outputFormatLA">
- <property name="text">
- <string>&Output Format:</string>
- </property>
- <property name="buddy">
- <cstring>outputFormatCO</cstring>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QComboBox" name="outputFormatCO">
- <property name="toolTip">
- <string>Select the output format</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0" colspan="2">
- <widget class="QCheckBox" name="viewFullSourceCB">
- <property name="cursor">
- <cursorShape>ArrowCursor</cursorShape>
- </property>
- <property name="text">
- <string>Complete source</string>
- </property>
- </widget>
+ <widget class="QLabel" name="outputFormatLA">
+ <property name="text">
+ <string>F&ormat:</string>
+ </property>
+ <property name="buddy">
+ <cstring>outputFormatCO</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QComboBox" name="outputFormatCO">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="toolTip">
+ <string>Select the output format</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" colspan="2">
+ <widget class="QComboBox" name="contentsCO">
+ <item>
+ <property name="text">
+ <string>Current Paragraph</string>
+ </property>
</item>
- <item row="2" column="0" colspan="2">
- <widget class="QCheckBox" name="autoUpdateCB">
- <property name="text">
- <string>Automatic update</string>
- </property>
- <property name="checked">
- <bool>true</bool>
- </property>
- </widget>
+ <item>
+ <property name="text">
+ <string>Complete Source</string>
+ </property>
</item>
- <item row="3" column="0" colspan="2">
- <widget class="QPushButton" name="updatePB">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>&Update</string>
- </property>
- </widget>
+ <item>
+ <property name="text">
+ <string>Preamble Only</string>
+ </property>
</item>
- <item row="4" column="0">
- <spacer>
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>17</height>
- </size>
- </property>
- </spacer>
+ <item>
+ <property name="text">
+ <string>Body Only</string>
+ </property>
</item>
- </layout>
+ </widget>
+ </item>
+ <item row="2" column="1" colspan="2">
+ <widget class="QCheckBox" name="autoUpdateCB">
+ <property name="text">
+ <string>Automatic update</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" colspan="2">
+ <widget class="QPushButton" name="updatePB">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>&Update</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1" colspan="2">
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>85</height>
+ </size>
+ </property>
+ </spacer>
</item>
</layout>
</widget>
<tabstops>
<tabstop>viewSourceTV</tabstop>
- <tabstop>viewFullSourceCB</tabstop>
<tabstop>autoUpdateCB</tabstop>
<tabstop>updatePB</tabstop>
</tabstops>
runparams.nice = true;
runparams.moving_arg = true;
runparams.free_spacing = true;
- buffer_.writeLaTeXSource(os, buffer_.filePath(), runparams, true, false);
+ buffer_.writeLaTeXSource(os, buffer_.filePath(), runparams, Buffer::OnlyPreamble);
// FIXME! This is a HACK! The proper fix is to control the 'true'
// passed to WriteStream below:
runparams.par_begin = 0;
runparams.par_end = tmp->paragraphs().size();
if (!tmp->makeLaTeXFile(tmpwritefile, masterFileName(buffer()).
- onlyPath().absFileName(), runparams, false)) {
+ onlyPath().absFileName(), runparams, Buffer::OnlyBody)) {
docstring msg = bformat(_("Included file `%1$s' "
"was not exported correctly.\nWarning: "
"LaTeX export is probably incomplete."),
if (all_pars) {
op.par_begin = 0;
op.par_end = 0;
- ibuf->writeLyXHTMLSource(xs.os(), op, true);
+ ibuf->writeLyXHTMLSource(xs.os(), op, Buffer::OnlyBody);
} else
xs << XHTMLStream::ESCAPE_NONE
<< "<!-- Included file: "
LYXERR(Debug::LATEX, "exportfile:" << exportfile);
LYXERR(Debug::LATEX, "writefile:" << writefile);
- tmp->makeDocBookFile(writefile, runparams, true);
+ tmp->makeDocBookFile(writefile, runparams, Buffer::OnlyBody);
}
runparams.exportdata->addExternalFile("docbook", writefile,
- Graphics insets show filename as a tooltip now.
+- New option to show only the preamble when viewing source (bug 7860).
* DOCUMENTATION AND LOCALIZATION