X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiViewSource.cpp;h=a5beae5da691e673c05fa55d77e9ae9274527128;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=8b4f93f34df23c1eecb29ff27eaf7eb5526d8328;hpb=bcbf7c6452a446b13790a3fe41ee742d73b69181;p=lyx.git diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index 8b4f93f34d..a5beae5da6 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -23,11 +23,13 @@ #include "Paragraph.h" #include "TexRow.h" -#include "support/Debug.h" +#include "support/debug.h" #include "support/lassert.h" #include "support/docstream.h" #include "support/gettext.h" +#include + #include #include #include @@ -48,6 +50,8 @@ ViewSourceWidget::ViewSourceWidget() this, SLOT(updateView())); connect(autoUpdateCB, SIGNAL(toggled(bool)), updatePB, SLOT(setDisabled(bool))); + connect(autoUpdateCB, SIGNAL(toggled(bool)), + this, SLOT(updateView())); connect(updatePB, SIGNAL(clicked()), this, SLOT(updateView())); @@ -69,10 +73,19 @@ ViewSourceWidget::ViewSourceWidget() } +static size_t crcCheck(docstring const & s) +{ + boost::crc_32_type crc; + crc.process_bytes(&s[0], sizeof(char_type) * s.size()); + return crc.checksum(); +} + + /** get the source code of selected paragraphs, or the whole document \param fullSource get full source code + \return true if the content has changed since last call. */ -static QString getContent(BufferView const * view, bool fullSource) +static bool getContent(BufferView const * view, bool fullSource, QString & qstr) { // get the *top* level paragraphs that contain the cursor, // or the selected text @@ -90,13 +103,21 @@ static QString getContent(BufferView const * view, bool fullSource) swap(par_begin, par_end); odocstringstream ostr; view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource); - return toqstr(ostr.str()); + docstring s = ostr.str(); + static size_t crc = 0; + size_t newcrc = crcCheck(s); + if (newcrc == crc) + return false; + crc = newcrc; + qstr = toqstr(s); + return true; } void ViewSourceWidget::setBufferView(BufferView const * bv) { bv_ = bv; + setEnabled(bv ? true : false); } @@ -107,8 +128,12 @@ void ViewSourceWidget::updateView() setEnabled(false); return; } + + setEnabled(true); - document_->setPlainText(getContent(bv_, viewFullSourceCB->isChecked())); + QString content; + if (getContent(bv_, viewFullSourceCB->isChecked(), content)) + document_->setPlainText(content); CursorSlice beg = bv_->cursor().selectionBegin().bottom(); CursorSlice end = bv_->cursor().selectionEnd().bottom(); @@ -156,12 +181,10 @@ void GuiViewSource::updateView() void GuiViewSource::enableView(bool enable) { - if (!enable) { + widget_->setBufferView(bufferview()); + if (!enable) // In the opposite case, updateView() will be called anyway. - widget_->setBufferView(bufferview()); widget_->updateView(); - } - widget_->setEnabled(enable); } @@ -201,11 +224,14 @@ void GuiViewSource::saveSession() const void GuiViewSource::restoreSession() { 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); QSettings settings; - widget_->viewFullSourceCB->setChecked( - settings.value(sessionKey() + "/fullsource", false).toBool()); widget_->autoUpdateCB->setChecked( settings.value(sessionKey() + "/autoupdate", true).toBool()); + widget_->updateView(); } @@ -218,4 +244,4 @@ Dialog * createGuiViewSource(GuiView & lv) } // namespace frontend } // namespace lyx -#include "GuiViewSource_moc.cpp" +#include "moc_GuiViewSource.cpp"