]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiViewSource.cpp
fix completion painting for RTL (inline completion and completion list)
[lyx.git] / src / frontends / qt4 / GuiViewSource.cpp
index f321d979e5c988bcc5f04d58bb27d521f545941b..2d9ec85655efd60093913a431712bba26ee87954 100644 (file)
 #include "Paragraph.h"
 #include "TexRow.h"
 
+#include "support/lassert.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
 
+#include <QSettings>
 #include <QTextCursor>
 #include <QTextDocument>
+#include <QVariant>
 
 using namespace std;
 
@@ -39,7 +42,6 @@ ViewSourceWidget::ViewSourceWidget(GuiViewSource & controller)
                highlighter_(new LaTeXHighlighter(document_))
 {
        setupUi(this);
-       setWindowTitle(qt_("LaTeX Source"));
 
        connect(viewFullSourceCB, SIGNAL(clicked()),
                this, SLOT(updateView()));
@@ -68,8 +70,14 @@ ViewSourceWidget::ViewSourceWidget(GuiViewSource & controller)
 
 void ViewSourceWidget::updateView()
 {
-       if (autoUpdateCB->isChecked())
-               update(viewFullSourceCB->isChecked());
+       BufferView * view = controller_.bufferview();
+       if (!view) {
+               document_->setPlainText(QString());
+               setEnabled(false);
+               return;
+       }
+       document_->setPlainText(controller_.getContent(
+               viewFullSourceCB->isChecked()));
 
        GuiViewSource::Row row = controller_.getRows();
        QTextCursor c = QTextCursor(viewSourceTV->document());
@@ -81,19 +89,12 @@ void ViewSourceWidget::updateView()
 }
 
 
-void ViewSourceWidget::update(bool full_source)
-{
-       document_->setPlainText(controller_.getContent(full_source));
-}
-
-
 GuiViewSource::GuiViewSource(GuiView & parent,
                Qt::DockWidgetArea area, Qt::WindowFlags flags)
-       : DockView(parent, "view-source", area, flags)
+       : DockView(parent, "view-source", qt_("LaTeX Source"), area, flags)
 {
        widget_ = new ViewSourceWidget(*this);
        setWidget(widget_);
-       setWindowTitle(widget_->windowTitle());
 }
 
 
@@ -105,7 +106,17 @@ GuiViewSource::~GuiViewSource()
 
 void GuiViewSource::updateView()
 {
-       widget_->updateView();
+       if (widget_->autoUpdateCB->isChecked())
+               widget_->updateView();
+}
+
+
+void GuiViewSource::enableView(bool enable)
+{
+       if (!enable)
+               // In the opposite case, updateView() will be called anyway.
+               widget_->updateView();
+       widget_->setEnabled(enable);
 }
 
 
@@ -168,11 +179,33 @@ QString GuiViewSource::title() const
                case LITERATE:
                        return qt_("Literate Source");
        }
-       BOOST_ASSERT(false);
+       LASSERT(false, /**/);
        return QString();
 }
 
 
+void GuiViewSource::saveSession() const
+{
+       Dialog::saveSession();
+       QSettings settings;
+       settings.setValue(
+               sessionKey() + "/fullsource", widget_->viewFullSourceCB->isChecked());
+       settings.setValue(
+               sessionKey() + "/autoupdate", widget_->autoUpdateCB->isChecked());
+}
+
+
+void GuiViewSource::restoreSession()
+{
+       Dialog::restoreSession();
+       QSettings settings;
+       widget_->viewFullSourceCB->setChecked(
+               settings.value(sessionKey() + "/fullsource", false).toBool());
+       widget_->autoUpdateCB->setChecked(
+               settings.value(sessionKey() + "/autoupdate", true).toBool());
+}
+
+
 Dialog * createGuiViewSource(GuiView & lv)
 {
        return new GuiViewSource(lv);