#include "LaTeXHighlighter.h"
#include "qt_helpers.h"
-#include "BufferView.h"
#include "Buffer.h"
+#include "BufferParams.h"
+#include "BufferView.h"
#include "Cursor.h"
+#include "Format.h"
#include "Paragraph.h"
#include "TexRow.h"
ViewSourceWidget::ViewSourceWidget()
: bv_(0), document_(new QTextDocument(this)),
- highlighter_(new LaTeXHighlighter(document_))
+ highlighter_(new LaTeXHighlighter(document_)),
+ force_getcontent_(true)
{
setupUi(this);
- connect(viewFullSourceCB, SIGNAL(clicked()),
- this, SLOT(updateView()));
+ connect(contentsCO, SIGNAL(activated(int)),
+ this, SLOT(contentsChanged()));
connect(autoUpdateCB, SIGNAL(toggled(bool)),
updatePB, SLOT(setDisabled(bool)));
connect(autoUpdateCB, SIGNAL(toggled(bool)),
this, SLOT(updateView()));
connect(updatePB, SIGNAL(clicked()),
this, SLOT(updateView()));
+ connect(outputFormatCO, SIGNAL(activated(int)),
+ this, SLOT(setViewFormat()));
// setting a document at this point trigger an assertion in Qt
// so we disable the signals here:
\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, Buffer::OutputWhat output,
+ QString & qstr, string const format, bool force_getcontent)
{
// get the *top* level paragraphs that contain the cursor,
// or the selected text
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, output);
docstring s = ostr.str();
static size_t crc = 0;
size_t newcrc = crcCheck(s);
- if (newcrc == crc)
+ if (newcrc == crc && !force_getcontent)
return false;
crc = newcrc;
qstr = toqstr(s);
void ViewSourceWidget::setBufferView(BufferView const * bv)
{
+ if (bv_ != bv)
+ force_getcontent_ = true;
bv_ = bv;
setEnabled(bv ? true : false);
}
+void ViewSourceWidget::contentsChanged()
+{
+ if (autoUpdateCB->isChecked())
+ updateView();
+}
+
+
+void ViewSourceWidget::setViewFormat()
+{
+ view_format_ = outputFormatCO->itemData(
+ outputFormatCO->currentIndex()).toString();
+ updateView();
+}
+
void ViewSourceWidget::updateView()
{
if (!bv_) {
setEnabled(false);
return;
}
-
+
setEnabled(true);
+ string const format = fromqstr(view_format_);
+
QString content;
- if (getContent(bv_, viewFullSourceCB->isChecked(), content))
+ 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();
}
+void ViewSourceWidget::updateDefaultFormat()
+{
+ if (!bv_)
+ return;
+
+ outputFormatCO->blockSignals(true);
+ outputFormatCO->clear();
+ outputFormatCO->addItem(qt_("Default"),
+ QVariant(QString("default")));
+
+ int index = 0;
+ 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) {
+ QString const fname = toqstr((*cit)->name());
+ outputFormatCO->addItem(qt_((*cit)->prettyname()),
+ QVariant(fname));
+ if (fname == view_format_)
+ index = outputFormatCO->count() -1;
+ }
+ outputFormatCO->setCurrentIndex(index);
+ outputFormatCO->blockSignals(false);
+}
+
+
GuiViewSource::GuiViewSource(GuiView & parent,
Qt::DockWidgetArea area, Qt::WindowFlags flags)
: DockView(parent, "view-source", qt_("LaTeX Source"), area, flags)
void GuiViewSource::enableView(bool enable)
{
widget_->setBufferView(bufferview());
+ widget_->updateDefaultFormat();
if (!enable)
// In the opposite case, updateView() will be called anyway.
widget_->updateView();
{
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());
}
{
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());