diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 48dbe7398d..a7851a781d 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -3071,12 +3071,13 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to, } -void Buffer::getSourceCode(odocstream & os, pit_type par_begin, - pit_type par_end, bool full_source) const +void Buffer::getSourceCode(odocstream & os, string const format, + pit_type par_begin, pit_type par_end, + bool full_source) const { OutputParams runparams(¶ms().encoding()); runparams.nice = true; - runparams.flavor = getDefaultOutputFlavor(); + runparams.flavor = getOutputFlavor(format); runparams.linelen = lyxrc.plaintext_linelen; // No side effect of file copying and image conversion runparams.dryrun = true; @@ -3388,9 +3389,10 @@ string Buffer::getDefaultOutputFormat() const } -OutputParams::FLAVOR Buffer::getDefaultOutputFlavor() const +OutputParams::FLAVOR Buffer::getOutputFlavor(string const format) const { - string const dformat = getDefaultOutputFormat(); + string const dformat = (format.empty() || format == "default") ? + getDefaultOutputFormat() : format; DefaultFlavorCache::const_iterator it = default_flavors_.find(dformat); diff --git a/src/Buffer.h b/src/Buffer.h index a2a74136a5..4283dc3102 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -553,8 +553,8 @@ public: /// get source code (latex/docbook) for some paragraphs, or all paragraphs /// including preamble - void getSourceCode(odocstream & os, pit_type par_begin, pit_type par_end, - bool full_source) const; + void getSourceCode(odocstream & os, std::string const format, + pit_type par_begin, pit_type par_end, bool full_source) const; /// Access to error list. /// This method is used only for GUI visualisation of Buffer related @@ -602,8 +602,9 @@ public: std::string bufferFormat() const; /// return the default output format of the current backend std::string getDefaultOutputFormat() const; - /// return the default output flavor - OutputParams::FLAVOR getDefaultOutputFlavor() const; + /// return the output flavor of \p format or the default + OutputParams::FLAVOR getOutputFlavor( + std::string const format = std::string()) const; /// bool doExport(std::string const & format, bool put_in_tempdir, diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index a5beae5da6..1afee03fba 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -20,6 +20,7 @@ #include "BufferView.h" #include "Buffer.h" #include "Cursor.h" +#include "Format.h" #include "Paragraph.h" #include "TexRow.h" @@ -54,6 +55,8 @@ ViewSourceWidget::ViewSourceWidget() this, SLOT(updateView())); connect(updatePB, SIGNAL(clicked()), this, SLOT(updateView())); + connect(outputFormatCO, SIGNAL(activated(int)), + this, SLOT(updateView())); // setting a document at this point trigger an assertion in Qt // so we disable the signals here: @@ -85,7 +88,8 @@ 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, QString & qstr) +static bool getContent(BufferView const * view, bool fullSource, + QString & qstr, string const format) { // get the *top* level paragraphs that contain the cursor, // or the selected text @@ -102,7 +106,7 @@ static bool getContent(BufferView const * view, bool fullSource, QString & qstr) if (par_begin > par_end) swap(par_begin, par_end); odocstringstream ostr; - view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource); + view->buffer().getSourceCode(ostr, format, par_begin, par_end + 1, fullSource); docstring s = ostr.str(); static size_t crc = 0; size_t newcrc = crcCheck(s); @@ -128,11 +132,14 @@ void ViewSourceWidget::updateView() setEnabled(false); return; } - + setEnabled(true); + string const format = fromqstr(outputFormatCO->itemData( + outputFormatCO->currentIndex()).toString()); + QString content; - if (getContent(bv_, viewFullSourceCB->isChecked(), content)) + if (getContent(bv_, viewFullSourceCB->isChecked(), content, format)) document_->setPlainText(content); CursorSlice beg = bv_->cursor().selectionBegin().bottom(); @@ -155,6 +162,26 @@ void ViewSourceWidget::updateView() } +void ViewSourceWidget::updateDefaultFormat() +{ + if (!bv_) + return; + + outputFormatCO->blockSignals(true); + outputFormatCO->clear(); + outputFormatCO->addItem(qt_("Default"), + QVariant(QString("default"))); + typedef vector Formats; + Formats formats = bv_->buffer().exportableFormats(true); + Formats::const_iterator cit = formats.begin(); + Formats::const_iterator end = formats.end(); + for (; cit != end; ++cit) + outputFormatCO->addItem(qt_((*cit)->prettyname()), + QVariant(toqstr((*cit)->name()))); + outputFormatCO->blockSignals(false); +} + + GuiViewSource::GuiViewSource(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags) : DockView(parent, "view-source", qt_("LaTeX Source"), area, flags) @@ -182,6 +209,7 @@ void GuiViewSource::updateView() void GuiViewSource::enableView(bool enable) { widget_->setBufferView(bufferview()); + widget_->updateDefaultFormat(); if (!enable) // In the opposite case, updateView() will be called anyway. widget_->updateView(); diff --git a/src/frontends/qt4/GuiViewSource.h b/src/frontends/qt4/GuiViewSource.h index d5553ac2ea..e364e6ff83 100644 --- a/src/frontends/qt4/GuiViewSource.h +++ b/src/frontends/qt4/GuiViewSource.h @@ -44,6 +44,8 @@ public: public Q_SLOTS: // update content void updateView(); + /// + void updateDefaultFormat(); private: /// diff --git a/src/frontends/qt4/ui/ViewSourceUi.ui b/src/frontends/qt4/ui/ViewSourceUi.ui index 4cfc9b064f..72e6736493 100644 --- a/src/frontends/qt4/ui/ViewSourceUi.ui +++ b/src/frontends/qt4/ui/ViewSourceUi.ui @@ -1,92 +1,95 @@ - + ViewSourceUi - - + + 0 0 - 446 - 94 + 452 + 120 - + - - - 0 - - - 6 - - - - - 6 + + + + + + 0 + 0 + - - 0 + + - - - + + + + + + + + &Output Format: + + + outputFormatCO + + + + + + + Select the output format + + + + + + ArrowCursor - + Complete source - - - + + + Automatic update - + true - - - + + + false - + &Update - + - + Qt::Vertical - + 20 - 1 + 17 - - - - - 3 - 13 - 0 - 0 - - - - - - - @@ -96,7 +99,7 @@ updatePB - qt_i18n.h + qt_i18n.h