#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 <boost/crc.hpp>
+
#include <QSettings>
#include <QTextCursor>
#include <QTextDocument>
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()));
}
+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
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);
}
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();
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);
}
QSettings settings;
widget_->autoUpdateCB->setChecked(
settings.value(sessionKey() + "/autoupdate", true).toBool());
+ widget_->updateView();
}
} // namespace frontend
} // namespace lyx
-#include "GuiViewSource_moc.cpp"
+#include "moc_GuiViewSource.cpp"