From: Vincent van Ravesteijn Date: Thu, 6 Aug 2009 23:17:16 +0000 (+0000) Subject: Fix bug #740: Wish for added menu item: File->Close all. X-Git-Tag: 2.0.0~5832 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=97efae2561dfed55556e8d53067d91d2de0b8050;p=features.git Fix bug #740: Wish for added menu item: File->Close all. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30882 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index 6758889218..648c91c5b4 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -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" diff --git a/src/FuncCode.h b/src/FuncCode.h index f3a66249f7..52ee7739b9 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -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 }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index f8e6498b78..892e5a3ba2 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -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. diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 0c985b35ec..948edbe331 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -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); diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index cb183a011b..77297c4b42 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -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. diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 73bddd6144..605426be8b 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -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::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 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::const_iterator it = d.dialogs_.begin(); - for (; it!= d.dialogs_.end(); ++it) - it->second->saveSession(); - } - - close_event->accept(); + return true; } diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 0ce40726f1..c2fb794d11 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -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