diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 7780fc15ab..e4e23b19e5 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1338,7 +1338,7 @@ bool Buffer::write(ostream & ofs) const 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; @@ -1369,8 +1369,7 @@ bool Buffer::makeLaTeXFile(FileName const & fname, 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; @@ -1415,7 +1414,7 @@ bool Buffer::makeLaTeXFile(FileName const & fname, 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. @@ -1430,6 +1429,11 @@ void Buffer::writeLaTeXSource(otexstream & os, 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) { @@ -1600,7 +1604,7 @@ void Buffer::writeLaTeXSource(otexstream & os, void Buffer::makeDocBookFile(FileName const & fname, OutputParams const & runparams, - bool const body_only) const + OutputWhat output) const { LYXERR(Debug::LATEX, "makeDocBookFile..."); @@ -1608,7 +1612,7 @@ void Buffer::makeDocBookFile(FileName const & fname, if (!openFileWrite(ofs, fname)) return; - writeDocBookSource(ofs, fname.absFileName(), runparams, body_only); + writeDocBookSource(ofs, fname.absFileName(), runparams, output); ofs.close(); if (ofs.fail()) @@ -1618,7 +1622,7 @@ void Buffer::makeDocBookFile(FileName const & fname, 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); @@ -1628,7 +1632,12 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname, 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 << "\n"; @@ -1663,31 +1672,33 @@ void Buffer::writeDocBookSource(odocstream & os, string const & fname, 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 (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 << "\n"; + + params().documentClass().counters().reset(); + + updateMacros(); - if (!params().options.empty()) { - top += ' '; - top += params().options; + sgml::openTag(os, top); + os << '\n'; + docbookParagraphs(text(), *this, os, runparams); + sgml::closeTag(os, top_element); } - - os << "\n"; - - params().documentClass().counters().reset(); - - updateMacros(); - - sgml::openTag(os, top); - os << '\n'; - docbookParagraphs(text(), *this, os, runparams); - sgml::closeTag(os, top_element); } @@ -1701,7 +1712,7 @@ void Buffer::makeLyXHTMLFile(FileName const & fname, if (!openFileWrite(ofs, fname)) return; - writeLyXHTMLSource(ofs, runparams, body_only); + writeLyXHTMLSource(ofs, runparams, FullSource); ofs.close(); if (ofs.fail()) @@ -1711,7 +1722,7 @@ void Buffer::makeLyXHTMLFile(FileName const & fname, void Buffer::writeLyXHTMLSource(odocstream & os, OutputParams const & runparams, - bool const only_body) const + OutputWhat output) const { LaTeXFeatures features(*this, params(), runparams); validate(features); @@ -1720,7 +1731,12 @@ void Buffer::writeLyXHTMLSource(odocstream & os, 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 << "\n" << "\n" // FIXME Language should be set properly. @@ -1764,14 +1780,19 @@ void Buffer::writeLyXHTMLSource(odocstream & os, << ";\n"; os << "}\n\n"; } - os << "\n\n"; + os << "\n"; } - XHTMLStream xs(os); - params().documentClass().counters().reset(); - xhtmlParagraphs(text(), *this, xs, runparams); - if (!only_body) - os << "\n\n"; + if (output_body) { + os << "\n"; + XHTMLStream xs(os); + params().documentClass().counters().reset(); + xhtmlParagraphs(text(), *this, xs, runparams); + os << "\n"; + } + + if (output_preamble) + os << "\n"; } @@ -3153,7 +3174,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to, 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; @@ -3162,21 +3183,7 @@ void Buffer::getSourceCode(odocstream & os, string const format, // 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) { @@ -3205,6 +3212,27 @@ void Buffer::getSourceCode(odocstream & os, string const format, 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); + } } } diff --git a/src/Buffer.h b/src/Buffer.h index 36834e7753..4249045600 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -275,12 +275,18 @@ public: /// 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 @@ -306,16 +312,15 @@ public: 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, @@ -323,7 +328,7 @@ public: /// 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 @@ -560,7 +565,7 @@ public: /// 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 diff --git a/src/BufferList.cpp b/src/BufferList.cpp index e19c8aa63d..5143c13126 100644 --- a/src/BufferList.cpp +++ b/src/BufferList.cpp @@ -213,7 +213,7 @@ void BufferList::updateIncludedTeXfiles(string const & masterTmpDir, if (!(*it)->isDepClean(masterTmpDir)) { string writefile = addName(masterTmpDir, (*it)->latexName()); (*it)->makeLaTeXFile(FileName(writefile), masterTmpDir, - runparams, false); + runparams, Buffer::OnlyBody); (*it)->markDepClean(masterTmpDir); } } diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index 345bfedd44..289a54a5a2 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -49,8 +49,8 @@ ViewSourceWidget::ViewSourceWidget() { 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)), @@ -90,7 +90,7 @@ static size_t crcCheck(docstring const & s) \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, @@ -108,7 +108,7 @@ static bool getContent(BufferView const * view, bool fullSource, 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); @@ -129,7 +129,7 @@ void ViewSourceWidget::setBufferView(BufferView const * bv) } -void ViewSourceWidget::fullSourceChanged() +void ViewSourceWidget::contentsChanged() { if (autoUpdateCB->isChecked()) updateView(); @@ -150,8 +150,15 @@ void ViewSourceWidget::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(); @@ -254,8 +261,9 @@ void GuiViewSource::saveSession() const { 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()); } @@ -265,9 +273,9 @@ void GuiViewSource::restoreSession() { 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()); diff --git a/src/frontends/qt4/GuiViewSource.h b/src/frontends/qt4/GuiViewSource.h index e3c7a814e5..697198301b 100644 --- a/src/frontends/qt4/GuiViewSource.h +++ b/src/frontends/qt4/GuiViewSource.h @@ -47,7 +47,7 @@ public Q_SLOTS: /// void updateDefaultFormat(); /// - void fullSourceChanged(); + void contentsChanged(); private: /// diff --git a/src/frontends/qt4/ui/ViewSourceUi.ui b/src/frontends/qt4/ui/ViewSourceUi.ui index 72e6736493..b9708e60f9 100644 --- a/src/frontends/qt4/ui/ViewSourceUi.ui +++ b/src/frontends/qt4/ui/ViewSourceUi.ui @@ -1,3 +1,4 @@ + ViewSourceUi @@ -5,15 +6,15 @@ 0 0 - 452 - 120 + 528 + 205 - - + + @@ -27,74 +28,86 @@ - - - - - &Output Format: - - - outputFormatCO - - + + + F&ormat: + + + outputFormatCO + + + + + + + true + + + Select the output format + + + + + + + + Current Paragraph + - - - - Select the output format - - + + + Complete Source + - - - - ArrowCursor - - - Complete source - - + + + Preamble Only + - - - - Automatic update - - - true - - + + + Body Only + - - - - false - - - &Update - - - - - - - Qt::Vertical - - - - 20 - 17 - - - - - + + + + + + Automatic update + + + true + + + + + + + false + + + &Update + + + + + + + Qt::Vertical + + + + 20 + 85 + + + viewSourceTV - viewFullSourceCB autoUpdateCB updatePB diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp index 9836eeb49a..cc66df7935 100644 --- a/src/graphics/PreviewLoader.cpp +++ b/src/graphics/PreviewLoader.cpp @@ -710,7 +710,7 @@ void PreviewLoader::Impl::dumpPreamble(otexstream & os) const 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: diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index c5a3b0d668..559baff07a 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -618,7 +618,7 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const 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."), @@ -785,7 +785,7 @@ docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const & rp) const 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 << "