]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt4/GuiViewSource.cpp
Allow LyX format to be written to View>Source window.
[features.git] / src / frontends / qt4 / GuiViewSource.cpp
index 289a54a5a26e2c2ee4dc6a1c87dc01a61e3c5109..f4f197d1de8a08d9493027afe520b541e1ddcd7e 100644 (file)
@@ -58,7 +58,7 @@ ViewSourceWidget::ViewSourceWidget()
        connect(updatePB, SIGNAL(clicked()),
                this, SLOT(updateView()));
        connect(outputFormatCO, SIGNAL(activated(int)),
-               this, SLOT(updateView()));
+               this, SLOT(setViewFormat()));
 
        // setting a document at this point trigger an assertion in Qt
        // so we disable the signals here:
@@ -136,6 +136,14 @@ void ViewSourceWidget::contentsChanged()
 }
 
 
+void ViewSourceWidget::setViewFormat()
+{
+       view_format_ = outputFormatCO->itemData(
+             outputFormatCO->currentIndex()).toString();
+       updateView();
+}
+
+
 void ViewSourceWidget::updateView()
 {
        if (!bv_) {
@@ -146,8 +154,7 @@ void ViewSourceWidget::updateView()
 
        setEnabled(true);
 
-       string const format = fromqstr(outputFormatCO->itemData(
-               outputFormatCO->currentIndex()).toString());
+       string const format = fromqstr(view_format_);
 
        QString content;
        Buffer::OutputWhat output = Buffer::CurrentParagraph;
@@ -190,13 +197,27 @@ void ViewSourceWidget::updateDefaultFormat()
        outputFormatCO->clear();
        outputFormatCO->addItem(qt_("Default"),
                                QVariant(QString("default")));
-       typedef vector<Format const *> Formats;
-       Formats formats = bv_->buffer().params().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())));
+
+       int index = 0;
+       vector<string> tmp = bv_->buffer().params().backends();
+       vector<string>::const_iterator it = tmp.begin();
+       vector<string>::const_iterator en = tmp.end();
+       for (; it != en; ++it) {
+               string const format = *it;
+               Format const * fmt = formats.getFormat(format);
+               if (!fmt) {
+                       LYXERR0("Can't find format for backend " << format << "!");
+                       continue;
+               } 
+
+               QString const pretty = qt_(fmt->prettyname());
+               QString const qformat = toqstr(format);
+               outputFormatCO->addItem(pretty, QVariant(qformat));
+               if (qformat == view_format_)
+                  index = outputFormatCO->count() -1;
+       }
+       outputFormatCO->setCurrentIndex(index);
+
        outputFormatCO->blockSignals(false);
 }