Jürgen Spitzmüller wrote:
> I come back to this. Attached is a reworked version of the view source
> part. I have added a cache for the default flavor, since it is overkill to
> recheck for the flavor on each key stroke.

And here comes a further addition: this adds a combo with the available output 
formats to the view source widget. This way, one can check how the output 
would look in another format without having to change the default output 
format.

Opinions?

Jürgen
Index: src/Buffer.h
===================================================================
--- src/Buffer.h	(Revision 36759)
+++ src/Buffer.h	(Arbeitskopie)
@@ -553,8 +553,8 @@
 
 	/// 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 @@
 	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,
Index: src/frontends/qt4/GuiViewSource.cpp
===================================================================
--- src/frontends/qt4/GuiViewSource.cpp	(Revision 36759)
+++ src/frontends/qt4/GuiViewSource.cpp	(Arbeitskopie)
@@ -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 @@
 		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 @@
 	\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 @@
 	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 @@
 		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::updateDefaultFormat()
+{
+	if (!bv_)
+		return;
+
+	outputFormatCO->blockSignals(true);
+	outputFormatCO->clear();
+	outputFormatCO->addItem(qt_("Default"),
+				QVariant(QString("default")));
+	typedef vector<Format const *> 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::enableView(bool enable)
 {
 	widget_->setBufferView(bufferview());
+	widget_->updateDefaultFormat();
 	if (!enable)
 		// In the opposite case, updateView() will be called anyway.
 		widget_->updateView();
Index: src/frontends/qt4/ui/ViewSourceUi.ui
===================================================================
--- src/frontends/qt4/ui/ViewSourceUi.ui	(Revision 36757)
+++ src/frontends/qt4/ui/ViewSourceUi.ui	(Arbeitskopie)
@@ -1,92 +1,95 @@
-<ui version="4.0" >
+<ui version="4.0">
  <class>ViewSourceUi</class>
- <widget class="QWidget" name="ViewSourceUi" >
-  <property name="geometry" >
+ <widget class="QWidget" name="ViewSourceUi">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>446</width>
-    <height>94</height>
+    <width>452</width>
+    <height>120</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string/>
   </property>
-  <layout class="QGridLayout" >
-   <property name="margin" >
-    <number>0</number>
-   </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
-   <item row="0" column="1" >
-    <layout class="QVBoxLayout" >
-     <property name="spacing" >
-      <number>6</number>
+  <layout class="QGridLayout" name="gridLayout_2">
+   <item row="0" column="0">
+    <widget class="QTextEdit" name="viewSourceTV">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="MinimumExpanding" vsizetype="Ignored">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
      </property>
-     <property name="margin" >
-      <number>0</number>
+     <property name="whatsThis">
+      <string/>
      </property>
-     <item>
-      <widget class="QCheckBox" name="viewFullSourceCB" >
-       <property name="cursor" >
+    </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>&amp;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" >
+       <property name="text">
         <string>Complete source</string>
        </property>
       </widget>
      </item>
-     <item>
-      <widget class="QCheckBox" name="autoUpdateCB" >
-       <property name="text" >
+     <item row="2" column="0" colspan="2">
+      <widget class="QCheckBox" name="autoUpdateCB">
+       <property name="text">
         <string>Automatic update</string>
        </property>
-       <property name="checked" >
+       <property name="checked">
         <bool>true</bool>
        </property>
       </widget>
      </item>
-     <item>
-      <widget class="QPushButton" name="updatePB" >
-       <property name="enabled" >
+     <item row="3" column="0" colspan="2">
+      <widget class="QPushButton" name="updatePB">
+       <property name="enabled">
         <bool>false</bool>
        </property>
-       <property name="text" >
+       <property name="text">
         <string>&amp;Update</string>
        </property>
       </widget>
      </item>
-     <item>
+     <item row="4" column="0">
       <spacer>
-       <property name="orientation" >
+       <property name="orientation">
         <enum>Qt::Vertical</enum>
        </property>
-       <property name="sizeHint" stdset="0" >
+       <property name="sizeHint" stdset="0">
         <size>
          <width>20</width>
-         <height>1</height>
+         <height>17</height>
         </size>
        </property>
       </spacer>
      </item>
     </layout>
    </item>
-   <item row="0" column="0" >
-    <widget class="QTextEdit" name="viewSourceTV" >
-     <property name="sizePolicy" >
-      <sizepolicy>
-       <hsizetype>3</hsizetype>
-       <vsizetype>13</vsizetype>
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-     <property name="whatsThis" >
-      <string/>
-     </property>
-    </widget>
-   </item>
   </layout>
  </widget>
  <tabstops>
@@ -96,7 +99,7 @@
   <tabstop>updatePB</tabstop>
  </tabstops>
  <includes>
-  <include location="local" >qt_i18n.h</include>
+  <include location="local">qt_i18n.h</include>
  </includes>
  <resources/>
  <connections/>
Index: src/frontends/qt4/GuiViewSource.h
===================================================================
--- src/frontends/qt4/GuiViewSource.h	(Revision 36757)
+++ src/frontends/qt4/GuiViewSource.h	(Arbeitskopie)
@@ -44,6 +44,8 @@
 public Q_SLOTS:
 	// update content
 	void updateView();
+	///
+	void updateDefaultFormat();
 
 private:
 	///
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(Revision 36759)
+++ src/Buffer.cpp	(Arbeitskopie)
@@ -3071,12 +3071,13 @@
 }
 
 
-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(&params().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 @@
 }
 
 
-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);
 

Reply via email to