]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiViewSource.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / GuiViewSource.cpp
index 17ba47f83636ea1c21955a545f041a61bd0d883e..b2df874437206bde096e139e8559bd5bab06ac1b 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <boost/crc.hpp>
 
+#include <QBoxLayout>
 #include <QSettings>
 #include <QTextCursor>
 #include <QTextDocument>
@@ -55,6 +56,8 @@ ViewSourceWidget::ViewSourceWidget()
                updatePB, SLOT(setDisabled(bool)));
        connect(autoUpdateCB, SIGNAL(toggled(bool)),
                this, SLOT(updateView()));
+       connect(masterPerspectiveCB, SIGNAL(toggled(bool)),
+               this, SLOT(updateView()));
        connect(updatePB, SIGNAL(clicked()),
                this, SLOT(updateView()));
        connect(outputFormatCO, SIGNAL(activated(int)),
@@ -91,7 +94,8 @@ static size_t crcCheck(docstring const & s)
        \return true if the content has changed since last call.
  */
 static bool getContent(BufferView const * view, Buffer::OutputWhat output,
-                      QString & qstr, string const format, bool force_getcontent)
+                      QString & qstr, string const format, bool force_getcontent,
+                      bool master)
 {
        // get the *top* level paragraphs that contain the cursor,
        // or the selected text
@@ -108,8 +112,12 @@ static bool getContent(BufferView const * view, Buffer::OutputWhat output,
        if (par_begin > par_end)
                swap(par_begin, par_end);
        odocstringstream ostr;
-       view->buffer().getSourceCode(ostr, format, par_begin, par_end + 1, output);
+       view->buffer().getSourceCode(ostr, format, par_begin, par_end + 1,
+                                    output, master);
        docstring s = ostr.str();
+       // FIXME THREAD
+       // Could this be private to this particular dialog? We could have
+       // more than one of these, in different windows.
        static size_t crc = 0;
        size_t newcrc = crcCheck(s);
        if (newcrc == crc && !force_getcontent)
@@ -165,7 +173,8 @@ void ViewSourceWidget::updateView()
        else if (contentsCO->currentIndex() == 3)
                output = Buffer::OnlyBody;
 
-       if (getContent(bv_, output, content, format, force_getcontent_))
+       if (getContent(bv_, output, content, format,
+                     force_getcontent_, masterPerspectiveCB->isChecked()))
                document_->setPlainText(content);
 
        CursorSlice beg = bv_->cursor().selectionBegin().bottom();
@@ -207,10 +216,8 @@ void ViewSourceWidget::updateDefaultFormat()
                Format const * fmt = formats.getFormat(format);
                if (!fmt) {
                        LYXERR0("Can't find format for backend " << format << "!");
-            continue;
-        } else if (fmt->name() == "lyx")
-                       // we can't presently display the LyX format itself
                        continue;
+               } 
 
                QString const pretty = qt_(fmt->prettyname());
                QString const qformat = toqstr(format);
@@ -224,11 +231,24 @@ void ViewSourceWidget::updateDefaultFormat()
 }
 
 
+void ViewSourceWidget::resizeEvent (QResizeEvent * event)
+{
+       QSize const & formSize = formLayout->sizeHint();
+       // minimize the size of the part that contains the buttons
+       if (width() * formSize.height() < height() * formSize.width()) {
+               layout_->setDirection(QBoxLayout::TopToBottom);
+       } else {
+               layout_->setDirection(QBoxLayout::LeftToRight);
+       }
+       QWidget::resizeEvent(event);
+}
+
+
 GuiViewSource::GuiViewSource(GuiView & parent,
                Qt::DockWidgetArea area, Qt::WindowFlags flags)
        : DockView(parent, "view-source", qt_("LaTeX Source"), area, flags)
 {
-       widget_ = new ViewSourceWidget();
+       widget_ = new ViewSourceWidget;
        setWidget(widget_);
 }
 
@@ -245,6 +265,7 @@ void GuiViewSource::updateView()
                widget_->setBufferView(bufferview());
                widget_->updateView();
        }
+       widget_->masterPerspectiveCB->setEnabled(buffer().parent());
 }
 
 
@@ -275,7 +296,7 @@ QString GuiViewSource::title() const
                case LITERATE:
                        return qt_("Literate Source");
        }
-       LASSERT(false, /**/);
+       LATTEST(false);
        return QString();
 }