Dear all,
Attached patch moves geometry-saving stuff to ~GuiView(), which
gurantees that session will be saved during the destruction of lyx
GUI. Since pimpl_->session_->writeFile() is executed before ~GuiView()
so I have to move wrieteFile() t0 ~session().
Any opinion? The correct behavior requires that session object,
defined in lyx::Singletons, is destroyed after all other objects that
use session, which may be in doubt.
Cheers,
Bo
Index: src/session.C
===================================================================
--- src/session.C (revision 15495)
+++ src/session.C (working copy)
@@ -167,6 +167,12 @@
}
+Session::~Session()
+{
+ writeFile();
+}
+
+
void Session::writeFile() const
{
ofstream ofs(session_file.c_str());
Index: src/frontends/qt4/GuiView.C
===================================================================
--- src/frontends/qt4/GuiView.C (revision 15495)
+++ src/frontends/qt4/GuiView.C (working copy)
@@ -87,6 +87,30 @@
GuiView::~GuiView()
{
+ // FIXME:
+ // change the ifdef to 'geometry = normalGeometry();' only
+ // when Trolltech has fixed the broken normalGeometry on X11:
+ // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
+ // Then also the moveEvent, resizeEvent, and the
+ // code for floatingGeometry_ can be removed;
+ // adjust GuiView::setGeometry()
+ std::cout << "Destructor called " << std::endl;
+#ifdef Q_OS_WIN32
+ QRect geometry = normalGeometry();
+#else
+ updateFloatingGeometry();
+ QRect geometry = floatingGeometry_;
+#endif
+
+ // save windows size and position
+ Session & session = LyX::ref().session();
+ session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
+ session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
+ session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
+ if (lyxrc.geometry_xysaved) {
+ session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
+ session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
+ }
}
@@ -230,29 +254,7 @@
void GuiView::closeEvent(QCloseEvent *)
{
- // FIXME:
- // change the ifdef to 'geometry = normalGeometry();' only
- // when Trolltech has fixed the broken normalGeometry on X11:
- // http://www.trolltech.com/developer/task-tracker/index_html?id=119684+&method=entry
- // Then also the moveEvent, resizeEvent, and the
- // code for floatingGeometry_ can be removed;
- // adjust GuiView::setGeometry()
-#ifdef Q_OS_WIN32
- QRect geometry = normalGeometry();
-#else
- updateFloatingGeometry();
- QRect geometry = floatingGeometry_;
-#endif
- // save windows size and position
- Session & session = LyX::ref().session();
- session.saveSessionInfo("WindowWidth", convert<string>(geometry.width()));
- session.saveSessionInfo("WindowHeight", convert<string>(geometry.height()));
- session.saveSessionInfo("WindowIsMaximized", (isMaximized() ? "yes" : "no"));
- if (lyxrc.geometry_xysaved) {
- session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
- session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
- }
// trigger LFUN_LYX_QUIT instead of quit directly
// since LFUN_LYX_QUIT may have more cleanup stuff
dispatch(FuncRequest(LFUN_LYX_QUIT));
Index: src/session.h
===================================================================
--- src/session.h (revision 15495)
+++ src/session.h (working copy)
@@ -59,9 +59,9 @@
*/
explicit Session(unsigned int num = 4);
- /** Write the session file.
+ /** call writeFile to write the session file
*/
- void writeFile() const;
+ ~Session();
/** Insert #file# into the lastfile dequeue.
This funtion inserts #file# into the last files list. If the file
@@ -158,6 +158,10 @@
*/
void readFile();
+ /** Write the session file.
+ */
+ void writeFile() const;
+
/** Used by the constructor to set the number of stored last files.
@param num the number of lastfiles to set.
*/
Index: src/lyx_main.C
===================================================================
--- src/lyx_main.C (revision 15495)
+++ src/lyx_main.C (working copy)
@@ -402,8 +402,6 @@
if (use_gui) {
if (!noask && !pimpl_->buffer_list_.quitWriteAll())
return;
-
- pimpl_->session_->writeFile();
}
prepareExit();