void GuiApplication::commitData(QSessionManager & sm)
{
- /// The implementation is required to avoid an application exit
- /// when session state save is triggered by session manager.
- /// The default implementation sends a close event to all
- /// visible top level widgets when session managment allows
- /// interaction.
- /// We are changing that to close all wiew one by one.
- /// FIXME: verify if the default implementation is enough now.
+ /** The implementation is required to avoid an application exit
+ ** when session state save is triggered by session manager.
+ ** The default implementation sends a close event to all
+ ** visible top level widgets when session managment allows
+ ** interaction.
+ ** We are changing that to check the state of each buffer in all
+ ** views and ask the users what to do if buffers are dirty.
+ ** Furthermore, we save the session state.
+ ** We do NOT close the views here since the user still can cancel
+ ** the logout process (see #9277); also, this would hide LyX from
+ ** an OSes own session handling (application restoration).
+ **/
#ifdef QT_NO_SESSIONMANAGER
#ifndef _MSC_VER
#warning Qt is compiled without session manager
#endif
(void) sm;
#else
- if (sm.allowsInteraction() && !closeAllViews())
+ if (sm.allowsInteraction() && !prepareAllViewsForLogout())
sm.cancel();
+ else
+ sm.release();
#endif
}
}
+bool GuiApplication::prepareAllViewsForLogout()
+{
+ if (d->views_.empty())
+ return true;
+
+ QList<GuiView *> const views = d->views_.values();
+ foreach (GuiView * view, views) {
+ if (!view->prepareAllBuffersForLogout())
+ return false;
+ }
+
+ return true;
+}
+
+
GuiView & GuiApplication::view(int id) const
{
LAPPERR(d->views_.contains(id));
void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
///
bool closeAllViews();
+ /// Things that need to be done when the OSes session manager
+ /// requests a log out.
+ bool prepareAllViewsForLogout();
/// read the given ui (menu/toolbar) file
bool readUIFile(QString const & name, bool include = false);
///
}
+bool GuiView::prepareAllBuffersForLogout()
+{
+ Buffer * first = theBufferList().first();
+ if (!first)
+ return true;
+
+ // First, iterate over all buffers and ask the users if unsaved
+ // changes should be saved.
+ // We cannot use a for loop as the buffer list cycles.
+ Buffer * b = first;
+ do {
+ if (!saveBufferIfNeeded(const_cast<Buffer &>(*b), false))
+ return false;
+ b = theBufferList().next(b);
+ } while (b != first);
+
+ // Next, save session state
+ // When a view/window was closed before without quitting LyX, there
+ // are already entries in the lastOpened list.
+ theSession().lastOpened().clear();
+ writeSession();
+
+ return true;
+}
+
+
/** Destroy only all tabbed WorkAreas. Destruction of other WorkAreas
** is responsibility of the container (e.g., dialog)
**/