]> git.lyx.org Git - features.git/commitdiff
Fix bug #740: Wish for added menu item: File->Close all.
authorVincent van Ravesteijn <vfr@lyx.org>
Thu, 6 Aug 2009 23:17:16 +0000 (23:17 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Thu, 6 Aug 2009 23:17:16 +0000 (23:17 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30882 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ui/stdmenus.inc
src/FuncCode.h
src/LyXAction.cpp
src/LyXFunc.cpp
src/frontends/LyXView.h
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h

index 675888921830ccafa75f3bcefcb5a7638fcaeca6..648c91c5b41a3c5984908a17e5c3c9c760f7e8a6 100644 (file)
@@ -46,6 +46,7 @@ Menuset
                Submenu "Open Recent|t" "file_lastfiles"
                Separator
                Item "Close|C" "buffer-close"
+               Item "Close All" "buffer-close-all"
                Item "Save|S" "buffer-write"
                Item "Save As...|A" "buffer-write-as"
                Item "Save All|l" "buffer-write-all"
index f3a66249f78fae3a560bb92459eb0de0e4c6bb55..52ee7739b9eee5d0d3589943a653a4579b3abc95 100644 (file)
@@ -439,6 +439,7 @@ enum FuncCode
        LFUN_BRANCH_ADD_INSERT,
        // 340
        LFUN_BRANCHES_RENAME,           // spitz 20090709
+       LFUN_BUFFER_CLOSE_ALL,          // vfr 20090806
 
        LFUN_LASTACTION                 // end of the table
 };
index f8e6498b78b9ce16d2106e053b23b16857942c34..892e5a3ba24ff1a4e2a2aee8a5f2481c5904281f 100644 (file)
@@ -2837,6 +2837,15 @@ void LyXAction::init()
  * \endvar
  */
                { LFUN_BUFFER_CLOSE, "buffer-close", ReadOnly, Buffer },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_BUFFER_CLOSE_ALL
+ * \li Action: Closes all buffers.
+ * \li Notion: Closes all buffers, asking whether to save it, etc,
+               if a buffer has been modified.
+ * \li Syntax: buffer-close_all
+ * \endvar
+ */
+               { LFUN_BUFFER_CLOSE_ALL, "buffer-close-all", ReadOnly, Buffer },
 /*!
  * \var lyx::FuncCode lyx::LFUN_BUFFER_EXPORT
  * \li Action: Exports the current buffer (document) to the given format.
index 0c985b35ec603b3da7ab50e81597fd360f9b921b..948edbe331d7e4a16021449eb2737ccc53af48ec 100644 (file)
@@ -633,6 +633,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_CANCEL:
        case LFUN_META_PREFIX:
        case LFUN_BUFFER_CLOSE:
+       case LFUN_BUFFER_CLOSE_ALL:
        case LFUN_BUFFER_IMPORT:
        case LFUN_BUFFER_AUTO_SAVE:
        case LFUN_RECONFIGURE:
@@ -879,6 +880,12 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        updateFlags = Update::None;
                        break;
 
+               case LFUN_BUFFER_CLOSE_ALL:
+                       lyx_view_->closeBufferAll();
+                       buffer = 0;
+                       updateFlags = Update::None;
+                       break;
+
                case LFUN_BUFFER_RELOAD: {
                        LASSERT(lyx_view_ && buffer, /**/);
                        docstring const file = makeDisplayPath(buffer->absFileName(), 20);
index cb183a011b1b5e77ecb41ea727674694794835ae..77297c4b429789fcdda2e3713b23f1eac6a84774 100644 (file)
@@ -67,6 +67,8 @@ public:
        ///
        virtual bool closeBuffer() = 0;
        ///
+       virtual bool closeBufferAll(bool tolastopened = false) = 0;
+       ///
        virtual bool hasFocus() const = 0;
 
        /// load a document into the current workarea.
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;
 }
 
 
index 0ce40726f13234461ff1e9fb585cab064a3f6430..c2fb794d11655abea962d3f88f39b2de040d2911 100644 (file)
@@ -297,6 +297,8 @@ private:
        bool closeBuffer(Buffer & buf, bool tolastopened = false,
                bool mark_active = false);
        ///
+       bool closeBufferAll(bool tolastopened = false);
+       ///
        enum NextOrPrevious {
                NEXTBUFFER,
                PREVBUFFER