]> git.lyx.org Git - features.git/commitdiff
Better session management for the source panel.
authorGuillaume Munch <gm@lyx.org>
Fri, 31 Jul 2015 00:05:54 +0000 (01:05 +0100)
committerGuillaume Munch <gm@lyx.org>
Sat, 12 Sep 2015 23:45:47 +0000 (00:45 +0100)
We now remember the previous GUI values across sessions.

src/frontends/qt4/GuiViewSource.cpp
src/frontends/qt4/GuiViewSource.h

index 50cfa31257793d35b448a8ee8056fca2afb3d91f..aa1b30dc6203f5f7e08483c89d6d1ec53304f1a2 100644 (file)
@@ -33,6 +33,7 @@
 #include <boost/crc.hpp>
 
 #include <QBoxLayout>
+#include <QComboBox>
 #include <QSettings>
 #include <QTextCursor>
 #include <QTextDocument>
@@ -56,13 +57,15 @@ ViewSourceWidget::ViewSourceWidget()
        connect(autoUpdateCB, SIGNAL(toggled(bool)),
                updatePB, SLOT(setDisabled(bool)));
        connect(autoUpdateCB, SIGNAL(toggled(bool)),
-               this, SLOT(updateViewNow()));
+               this, SLOT(contentsChanged()));
        connect(masterPerspectiveCB, SIGNAL(toggled(bool)),
-               this, SLOT(updateViewNow()));
+               this, SLOT(contentsChanged()));
        connect(updatePB, SIGNAL(clicked()),
                this, SLOT(updateViewNow()));
        connect(outputFormatCO, SIGNAL(activated(int)),
-               this, SLOT(setViewFormat()));
+               this, SLOT(setViewFormat(int)));
+       connect(outputFormatCO, SIGNAL(activated(int)),
+               this, SLOT(contentsChanged()));
 
        // setting the update timer
        update_timer_->setSingleShot(true);
@@ -149,11 +152,10 @@ void ViewSourceWidget::contentsChanged()
 }
 
 
-void ViewSourceWidget::setViewFormat()
+void ViewSourceWidget::setViewFormat(int const index)
 {
-       view_format_ = outputFormatCO->itemData(
-             outputFormatCO->currentIndex()).toString();
-       updateViewNow();
+       outputFormatCO->setCurrentIndex(index);
+       view_format_ = outputFormatCO->itemData(index).toString();
 }
 
 
@@ -244,7 +246,7 @@ void ViewSourceWidget::updateDefaultFormat()
                if (qformat == view_format_)
                   index = outputFormatCO->count() -1;
        }
-       outputFormatCO->setCurrentIndex(index);
+       setViewFormat(index);
 
        outputFormatCO->blockSignals(false);
 }
@@ -262,6 +264,35 @@ void ViewSourceWidget::resizeEvent (QResizeEvent * event)
        QWidget::resizeEvent(event);
 }
 
+void ViewSourceWidget::saveSession(QString const & session_key) const
+{
+       QSettings settings;
+       settings.setValue(session_key + "/output", view_format_);
+       settings.setValue(session_key + "/contents", contentsCO->currentIndex());
+       settings.setValue(session_key + "/autoupdate", autoUpdateCB->isChecked());
+       settings.setValue(session_key + "/masterview",
+                                         masterPerspectiveCB->isChecked());
+}
+
+
+void ViewSourceWidget::restoreSession(QString const & session_key)
+{
+       QSettings settings;
+    view_format_ = settings.value(session_key + "/output", 0).toString();
+       contentsCO->setCurrentIndex(settings
+                                                               .value(session_key + "/contents", 0)
+                                                               .toInt());
+       masterPerspectiveCB->setChecked(settings
+                                                                       .value(session_key + "/masterview", false)
+                                                                       .toBool());
+       bool const checked = settings
+               .value(session_key + "/autoupdate", true)
+               .toBool();
+       autoUpdateCB->setChecked(checked);
+       if (checked)
+               updateView();
+}
+
 
 GuiViewSource::GuiViewSource(GuiView & parent,
                Qt::DockWidgetArea area, Qt::WindowFlags flags)
@@ -294,7 +325,7 @@ void GuiViewSource::enableView(bool enable)
        widget_->updateDefaultFormat();
        if (!enable)
                // In the opposite case, updateView() will be called anyway.
-               widget_->updateView();
+               widget_->contentsChanged();
 }
 
 
@@ -323,26 +354,14 @@ QString GuiViewSource::title() const
 void GuiViewSource::saveSession() const
 {
        Dialog::saveSession();
-       QSettings settings;
-       // see below
-       // settings.setValue(
-       //      sessionKey() + "/output", widget_->contentsCO->currentIndex());
-       settings.setValue(
-               sessionKey() + "/autoupdate", widget_->autoUpdateCB->isChecked());
+       widget_->saveSession(sessionKey());
 }
 
 
 void GuiViewSource::restoreSession()
 {
        DockView::restoreSession();
-       // FIXME: Full source updating is too slow to be done at startup.
-       //widget_->outputCO-setCurrentIndex(
-       //      settings.value(sessionKey() + "/output", false).toInt());
-       widget_->contentsCO->setCurrentIndex(0);
-       QSettings settings;
-       widget_->autoUpdateCB->setChecked(
-               settings.value(sessionKey() + "/autoupdate", true).toBool());
-       widget_->updateView();
+       widget_->restoreSession(sessionKey());
 }
 
 
index d9425ac0907ccad0dbdc20f06d2f88074daa13b2..ee664a275cc80f0ae4427096233ec21b737eb31a 100644 (file)
@@ -38,6 +38,10 @@ public:
        ViewSourceWidget();
        ///
        void setBufferView(BufferView const * bv);
+       ///
+       void saveSession(QString const & session_key) const;
+       ///
+       void restoreSession(QString const & session_key);
 
 protected:
        ///
@@ -49,8 +53,8 @@ public Q_SLOTS:
        /// schedule an update now
        void updateViewNow();
        ///
-       void setViewFormat();
-       ///
+       void setViewFormat(int const index);
+       //
        void updateDefaultFormat();
        ///
        void contentsChanged();