]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt4/GuiView.cpp
Fix bug #740: Wish for added menu item: File->Close all.
[features.git] / src / frontends / qt4 / GuiView.cpp
index 73bddd61444319e61aa7e22c63778528bc939ad0..605426be8ba2677b7f0876d1c9447c2d71971d02 100644 (file)
@@ -536,6 +536,45 @@ void GuiView::closeEvent(QCloseEvent * close_event)
        // it can happen that this event arrives without selecting the view,
        // e.g. when clicking the close button on a background window.
        setFocus();
+       if (!closeBufferAll(true)) {
+               closing_ = false;
+               close_event->ignore();
+               return;
+       }
+
+       // Make sure that nothing will use this close to be closed View.
+       guiApp->unregisterView(this);
+
+       if (isFullScreen()) {
+               // Switch off fullscreen before closing.
+               toggleFullScreen();
+               updateDialogs();
+       }
+
+       // Make sure the timer time out will not trigger a statusbar update.
+       d.statusbar_timer_.stop();
+
+       // Saving fullscreen requires additional tweaks in the toolbar code.
+       // It wouldn't also work under linux natively.
+       if (lyxrc.allow_geometry_session) {
+               // Save this window geometry and layout.
+               saveLayout();
+               // Then the toolbar private states.
+               ToolbarMap::iterator end = d.toolbars_.end();
+               for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
+                       it->second->saveSession();
+               // Now take care of all other dialogs:
+               map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
+               for (; it!= d.dialogs_.end(); ++it)
+                       it->second->saveSession();
+       }
+
+       close_event->accept();
+}
+
+
+bool GuiView::closeBufferAll(bool tolastopened)
+{
        GuiWorkArea * active_wa = currentMainWorkArea();
        setCurrentWorkArea(active_wa);
 
@@ -563,11 +602,8 @@ void GuiView::closeEvent(QCloseEvent * close_event)
                        if (b->parent()) {
                                // This is a child document, just close the tab
                                // after saving but keep the file loaded.
-                               if (!closeBuffer(*b, true, is_active_wa)) {
-                                       closing_ = false;
-                                       close_event->ignore();
-                                       return;
-                               }
+                               if (!closeBuffer(*b, tolastopened, is_active_wa))
+                                       return false;
                                continue;
                        }
 
@@ -579,11 +615,8 @@ void GuiView::closeEvent(QCloseEvent * close_event)
                                Buffer * c = *it;
                                // If a child is dirty, do not close
                                // without user intervention
-                               if (!closeBuffer(*c, false)) {
-                                       closing_ = false;
-                                       close_event->ignore();
-                                       return;
-                               }
+                               if (!closeBuffer(*c, false))
+                                       return false;
                        }
 
                        QList<int> const ids = guiApp->viewIds();
@@ -606,41 +639,11 @@ void GuiView::closeEvent(QCloseEvent * close_event)
                        }
                        // closeBuffer() needs buffer workArea still alive and
                        // set as currrent one, and destroys it
-                       if (b && !closeBuffer(*b, true, is_active_wa)) {
-                               closing_ = false;
-                               close_event->ignore();
-                               return;
-                       }
+                       if (b && !closeBuffer(*b, tolastopened, is_active_wa))
+                               return false;
                }
        }
-       // Make sure that nothing will use this close to be closed View.
-       guiApp->unregisterView(this);
-
-       if (isFullScreen()) {
-               // Switch off fullscreen before closing.
-               toggleFullScreen();
-               updateDialogs();
-       }
-
-       // Make sure the timer time out will not trigger a statusbar update.
-       d.statusbar_timer_.stop();
-
-       // Saving fullscreen requires additional tweaks in the toolbar code.
-       // It wouldn't also work under linux natively.
-       if (lyxrc.allow_geometry_session) {
-               // Save this window geometry and layout.
-               saveLayout();
-               // Then the toolbar private states.
-               ToolbarMap::iterator end = d.toolbars_.end();
-               for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
-                       it->second->saveSession();
-               // Now take care of all other dialogs:
-               map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
-               for (; it!= d.dialogs_.end(); ++it)
-                       it->second->saveSession();
-       }
-
-       close_event->accept();
+       return true;
 }