mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-22 16:37:28 +00:00
Add the option to select the output format in Source View.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36806 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
ab883f647f
commit
1e98a4f240
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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<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::updateView()
|
||||
void GuiViewSource::enableView(bool enable)
|
||||
{
|
||||
widget_->setBufferView(bufferview());
|
||||
widget_->updateDefaultFormat();
|
||||
if (!enable)
|
||||
// In the opposite case, updateView() will be called anyway.
|
||||
widget_->updateView();
|
||||
|
@ -44,6 +44,8 @@ public:
|
||||
public Q_SLOTS:
|
||||
// update content
|
||||
void updateView();
|
||||
///
|
||||
void updateDefaultFormat();
|
||||
|
||||
private:
|
||||
///
|
||||
|
@ -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>&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>&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/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user