]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiViewSource.cpp
Cleanup private part of Layout Box on destructor (probably not really an
[lyx.git] / src / frontends / qt4 / GuiViewSource.cpp
index 1afee03fba5da48fc82a8dcc9de29d6632c23d54..345bfedd44968b3644fa46b477b8304d49db6cc5 100644 (file)
@@ -17,8 +17,9 @@
 #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"
@@ -43,12 +44,13 @@ namespace frontend {
 
 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()));
+               this, SLOT(fullSourceChanged()));
        connect(autoUpdateCB, SIGNAL(toggled(bool)),
                updatePB, SLOT(setDisabled(bool)));
        connect(autoUpdateCB, SIGNAL(toggled(bool)),
@@ -89,7 +91,7 @@ static size_t crcCheck(docstring const & s)
        \return true if the content has changed since last call.
  */
 static bool getContent(BufferView const * view, bool fullSource,
-                      QString & qstr, string const format)
+                      QString & qstr, string const format, bool force_getcontent)
 {
        // get the *top* level paragraphs that contain the cursor,
        // or the selected text
@@ -110,7 +112,7 @@ static bool getContent(BufferView const * view, bool fullSource,
        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);
@@ -120,11 +122,20 @@ static bool getContent(BufferView const * view, bool fullSource,
 
 void ViewSourceWidget::setBufferView(BufferView const * bv)
 {
+       if (bv_ != bv)
+               force_getcontent_ = true;
        bv_ = bv;
        setEnabled(bv ?  true : false);
 }
 
 
+void ViewSourceWidget::fullSourceChanged()
+{
+       if (autoUpdateCB->isChecked())
+               updateView();
+}
+
+
 void ViewSourceWidget::updateView()
 {
        if (!bv_) {
@@ -139,7 +150,8 @@ void ViewSourceWidget::updateView()
                outputFormatCO->currentIndex()).toString());
 
        QString content;
-       if (getContent(bv_, viewFullSourceCB->isChecked(), content, format))
+       if (getContent(bv_, viewFullSourceCB->isChecked(), content,
+                 format, force_getcontent_))
                document_->setPlainText(content);
 
        CursorSlice beg = bv_->cursor().selectionBegin().bottom();
@@ -172,7 +184,7 @@ void ViewSourceWidget::updateDefaultFormat()
        outputFormatCO->addItem(qt_("Default"),
                                QVariant(QString("default")));
        typedef vector<Format const *> Formats;
-       Formats formats = bv_->buffer().exportableFormats(true);
+       Formats formats = bv_->buffer().params().exportableFormats(true);
        Formats::const_iterator cit = formats.begin();
        Formats::const_iterator end = formats.end();
        for (; cit != end; ++cit)