]> git.lyx.org Git - features.git/commitdiff
Add common session handling infrastructure for dialogs.
authorAbdelrazak Younes <younes@lyx.org>
Mon, 10 Dec 2007 13:05:00 +0000 (13:05 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 10 Dec 2007 13:05:00 +0000 (13:05 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22061 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/Dialog.cpp
src/frontends/qt4/Dialog.h
src/frontends/qt4/DialogView.cpp
src/frontends/qt4/DialogView.h
src/frontends/qt4/DockView.h
src/frontends/qt4/GuiProgress.cpp
src/frontends/qt4/GuiView.cpp

index 15e96136a4427d1a6d8fe5e6493919873f3d9842..04e09a95fecd0829587faf7350c757d8be318b3c 100644 (file)
@@ -13,6 +13,7 @@
 #include "Dialog.h"
 
 #include "GuiView.h"
+#include "qt_helpers.h"
 
 #include "Buffer.h"
 #include "FuncRequest.h"
@@ -21,6 +22,9 @@
 
 #include "support/debug.h"
 
+#include <QSettings>
+#include <QString>
+
 #include <string>
 
 using namespace std;
@@ -241,5 +245,27 @@ void Dialog::checkStatus()
                enableView(false);
 }
 
+
+QString Dialog::sessionKey() const
+{
+       return "view-" + QString::number(lyxview_->id())
+               + "/" + toqstr(name());
+}
+
+
+void Dialog::saveSession() const
+{
+       QSettings settings;
+       settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
+}
+
+
+void Dialog::restoreSession()
+{
+       QSettings settings;
+       asQWidget()->restoreGeometry(
+               settings.value(sessionKey() + "/geometry").toByteArray());
+}
+
 } // namespace frontend
 } // namespace lyx
index 64dd73008644fb1b63c3d2fca40d0a92ae26f2d5..987211d91ff0f115dad1d9d0096782be86f9400e 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <string>
 
+class QString;
 class QWidget;
 
 namespace lyx {
@@ -56,6 +57,26 @@ public:
        virtual QWidget * asQWidget() = 0;
        virtual QWidget const * asQWidget() const = 0;
 
+       /// Session key.
+       /**
+        * This key must be used for any session setting.
+        **/
+       QString sessionKey() const;
+
+       /// Save session settings.
+       /**
+        * This default implementation saves the geometry state.
+        * Reimplement to save more settings.
+        **/
+       virtual void saveSession() const;
+
+       /// Restore session settings.
+       /**
+        * This default implementation restores the geometry state.
+        * Reimplement to restore more settings.
+        **/
+       virtual void restoreSession();
+
        /** \name Container Access
         *  These methods are publicly accessible because they are invoked
         *  by the parent container acting on commands from the LyX kernel.
index b193bca2ae2b738edaf829fdefc48a427ea0797d..c120ea391ded292823da3e4a886316432dc18446 100644 (file)
@@ -16,7 +16,6 @@
 #include "qt_helpers.h"
 
 #include <QCloseEvent>
-#include <QSettings>
 #include <QShowEvent>
 
 
@@ -33,24 +32,6 @@ void DialogView::setViewTitle(docstring const & title)
        setWindowTitle("LyX: " + toqstr(title));
 }
 
-
-void DialogView::showEvent(QShowEvent * e)
-{
-       QSettings settings;
-       QString key = toqstr(name()) + "/geometry";
-       restoreGeometry(settings.value(key).toByteArray());
-       QDialog::showEvent(e);
-}
-
-
-void DialogView::closeEvent(QCloseEvent * e)
-{
-       QSettings settings;
-       QString key = toqstr(name()) + "/geometry";
-       settings.setValue(key, saveGeometry());
-       QDialog::closeEvent(e);
-}
-
 } // namespace frontend
 } // namespace lyx
 
index 36f3ef2f0892e327735ee92eb82f40da7217683e..959423281f2be0e48bb5c00f8f2103bf25d2ec20 100644 (file)
@@ -39,14 +39,9 @@ public:
        virtual QWidget * asQWidget() { return this; }
        virtual QWidget const * asQWidget() const { return this; }
 
-public:
+protected:
        ///
        void setViewTitle(docstring const & title);
-
-       ///
-       void closeEvent(QCloseEvent *);
-       ///
-       void showEvent(QShowEvent *);
 };
 
 } // namespace frontend
index 3f0bd2347ab4f85ac4a05b5b0efaab2938ab862e..4b056789c4555661e27f261818c967dbda5567ab 100644 (file)
@@ -14,8 +14,6 @@
 
 #include "Dialog.h"
 #include "GuiView.h"
-#include "qt_helpers.h"
-#include "support/debug.h"
 
 #include <QDockWidget>
 
@@ -23,8 +21,11 @@ namespace lyx {
 namespace frontend {
 
 /// Dock Widget container for LyX dialogs.
-/// This template class that encapsulates a given Widget inside a
-/// QDockWidget and presents a Dialog interface
+/**
+ * This template class that encapsulates a given Widget inside a
+ * QDockWidget and presents a Dialog interface
+ * FIXME: create a DockView.cpp file
+ **/
 class DockView : public QDockWidget, public Dialog
 {
 public:
index 694a45ef8ea626bf72dd2738b264c5a5b24677a7..d9109b1c50c394917f6eff2ff99eacc900ddc8d3 100644 (file)
@@ -13,6 +13,8 @@
 
 #include "GuiProgress.h"
 
+#include "qt_helpers.h"
+
 #include "support/Systemcall.h"
 
 #include <QApplication>
@@ -27,7 +29,7 @@ GuiProgress::GuiProgress(GuiView & parent, Qt::DockWidgetArea area,
 {
        setWindowTitle(qt_("LaTeX Progress"));
        setWidget(&text_edit);
-       lyx::support::Systemcall::registerProgressInterface(this);
+       support::Systemcall::registerProgressInterface(this);
 }
 
 
index f2c7ced20391b7abbd35b60100cb5f64383c8a9c..5c537fa8107b102e1fcab00e0f2d01833f28c517 100644 (file)
@@ -421,6 +421,10 @@ void GuiView::closeEvent(QCloseEvent * close_event)
 #endif
                settings.setValue(key + "/icon_size", iconSize());
                d.toolbars_->saveToolbarInfo();
+               // Now take care of all other dialogs:
+               std::map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
+               for (; it!= d.dialogs_.end(); ++it)
+                       it->second->saveSession();
        }
 
        guiApp->unregisterView(id_);
@@ -1619,8 +1623,11 @@ Dialog * GuiView::find_or_build(string const & name)
        if (it != d.dialogs_.end())
                return it->second.get();
 
-       d.dialogs_[name].reset(build(name));
-       return d.dialogs_[name].get();
+       Dialog * dialog = build(name);
+       d.dialogs_[name].reset(dialog);
+       if (lyxrc.allow_geometry_session)
+               dialog->restoreSession();
+       return dialog;
 }