From 9eaa64b2cbcbfd6ef99f8ae5e0e53e533f5242c8 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Sat, 29 Oct 2011 21:00:23 +0000 Subject: [PATCH] Initial work for view source improvements. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40073 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 100 ++++++++++--------- src/Buffer.h | 5 +- src/frontends/qt4/GuiViewSource.cpp | 32 +++--- src/frontends/qt4/GuiViewSource.h | 2 +- src/frontends/qt4/ui/ViewSourceUi.ui | 139 +++++++++++++++------------ 5 files changed, 157 insertions(+), 121 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 0ffac77a6d..237a7924a1 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1639,29 +1639,31 @@ 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 (!params().options.empty()) { - top += ' '; - top += params().options; + 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(); + + sgml::openTag(os, top); + os << '\n'; + docbookParagraphs(text(), *this, os, runparams); + sgml::closeTag(os, top_element); } - - os << "\n"; - - params().documentClass().counters().reset(); - - sgml::openTag(os, top); - os << '\n'; - docbookParagraphs(text(), *this, os, runparams); - sgml::closeTag(os, top_element); } @@ -1742,14 +1744,19 @@ void Buffer::writeLyXHTMLSource(odocstream & os, << ";\n"; os << "}\n\n"; } - os << "\n\n"; + os << "\n"; + } + + if (output_body) { + os << "\n"; + XHTMLStream xs(os); + params().documentClass().counters().reset(); + xhtmlParagraphs(text(), *this, xs, runparams); + os << "\n"; } - XHTMLStream xs(os); - params().documentClass().counters().reset(); - xhtmlParagraphs(text(), *this, xs, runparams); if (output_preamble) - os << "\n\n"; + os << "\n"; } @@ -3179,7 +3186,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; @@ -3188,21 +3195,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, FullSource); - else if (runparams.flavor == OutputParams::HTML) - writeLyXHTMLSource(os, runparams, FullSource); - else { - // latex or literate - otexstream ots(os, d->texrow); - writeLaTeXSource(ots, string(), runparams, FullSource); - } - } else { + if (output == CurrentParagraph) { runparams.par_begin = par_begin; runparams.par_end = par_end; if (par_begin + 1 == par_end) { @@ -3231,6 +3224,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 3a042989cb..fe39b4653f 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -288,7 +288,8 @@ public: enum OutputWhat { FullSource, OnlyBody, - OnlyPreamble + OnlyPreamble, + CurrentParagraph }; /// Just a wrapper for writeLaTeXSource, first creating the ofstream. @@ -575,7 +576,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/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 - - - - - - - Select the output format - - - - - - - ArrowCursor - - - Complete source - - + + + F&ormat: + + + outputFormatCO + + + + + + + true + + + Select the output format + + + + + + + + Current Paragraph + - - - - Automatic update - - - true - - + + + Complete Source + - - - - false - - - &Update - - + + + Preamble Only + - - - - Qt::Vertical - - - - 20 - 17 - - - + + + Body Only + - + + + + + + Automatic update + + + true + + + + + + + false + + + &Update + + + + + + + Qt::Vertical + + + + 20 + 85 + + + viewSourceTV - viewFullSourceCB autoUpdateCB updatePB -- 2.39.2