From: Abdelrazak Younes Date: Wed, 27 Feb 2008 10:35:28 +0000 (+0000) Subject: Cleanup app quitting and window closing now that there is a clean separation between... X-Git-Tag: 1.6.10~6056 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=9940ca77308e968444611aaa411da2059fefbdc6;p=lyx.git Cleanup app quitting and window closing now that there is a clean separation between the frontend and the core. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23271 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index 4d7d800b6e..b97f8241c8 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -49,8 +49,6 @@ public: virtual ~LyXView() {} /// virtual int id() const = 0; - /// - virtual void close() = 0; /// show busy cursor virtual void setBusy(bool) = 0; diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 5335fd0194..172dfbf2ca 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -251,9 +251,6 @@ bool GuiApplication::dispatch(FuncRequest const & cmd) // update bookmark pit of the current buffer before window close for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i) theLyXFunc().gotoBookmark(i+1, false, false); - // ask the user for saving changes or cancel quit - if (!current_view_->quitWriteAll()) - break; current_view_->close(); break; @@ -261,8 +258,8 @@ bool GuiApplication::dispatch(FuncRequest const & cmd) // quitting is triggered by the gui code // (leaving the event loop). current_view_->message(from_utf8(N_("Exiting."))); - if (current_view_->quitWriteAll()) - closeAllViews(); + if (closeAllViews()) + quit(); break; case LFUN_SCREEN_FONT_UPDATE: { @@ -548,8 +545,9 @@ void GuiApplication::commitData(QSessionManager & sm) /// The default implementation sends a close event to all /// visible top level widgets when session managment allows /// interaction. - /// We are changing that to write all unsaved buffers... - if (sm.allowsInteraction() && !current_view_->quitWriteAll()) + /// We are changing that to close all wiew one by one. + /// FIXME: verify if the default implementation is enough now. + if (sm.allowsInteraction() && !closeAllViews()) sm.cancel(); } @@ -581,20 +579,14 @@ bool GuiApplication::unregisterView(int id) bool GuiApplication::closeAllViews() { updateIds(views_, view_ids_); - if (views_.empty()) { - // quit in CloseEvent will not be triggert - qApp->quit(); + if (views_.empty()) return true; - } map const cmap = views_; map::const_iterator it; for (it = cmap.begin(); it != cmap.end(); ++it) { - // TODO: return false when close event was ignored - // e.g. quitWriteAll()->'Cancel' - // maybe we need something like 'bool closeView()' - it->second->close(); - // unregisterd by the CloseEvent + if (!it->second->close()) + return false; } views_.clear(); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index de370d0c69..4454a4652e 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -145,8 +145,8 @@ typedef boost::shared_ptr DialogPtr; struct GuiView::GuiViewPrivate { GuiViewPrivate() - : current_work_area_(0), layout_(0), - quitting_by_menu_(false), autosave_timeout_(5000), in_show_(false) + : current_work_area_(0), layout_(0), autosave_timeout_(5000), + in_show_(false) { // hardcode here the platform specific icon size smallIconSize = 14; // scaling problems @@ -263,8 +263,6 @@ public: unsigned int bigIconSize; /// QTimer statusbar_timer_; - /// are we quitting by the menu? - bool quitting_by_menu_; /// auto-saving of buffers Timeout autosave_timeout_; /// flag against a race condition due to multiclicks, see bug #1119 @@ -336,20 +334,6 @@ GuiView::~GuiView() } -void GuiView::close() -{ - d.quitting_by_menu_ = true; - d.current_work_area_ = 0; - for (int i = 0; i != d.splitter_->count(); ++i) { - TabWorkArea * twa = d.tabWorkArea(i); - if (twa) - twa->closeAll(); - } - QMainWindow::close(); - d.quitting_by_menu_ = false; -} - - void GuiView::setFocus() { if (d.current_work_area_) @@ -381,15 +365,6 @@ void GuiView::showEvent(QShowEvent * e) void GuiView::closeEvent(QCloseEvent * close_event) { - // we may have been called through the close window button - // which bypasses the LFUN machinery. - if (!d.quitting_by_menu_ && guiApp->viewCount() == 1) { - if (!quitWriteAll()) { - close_event->ignore(); - return; - } - } - while (Buffer * b = buffer()) { if (b->parent()) { // This is a child document, just close the tab after saving @@ -406,7 +381,7 @@ void GuiView::closeEvent(QCloseEvent * close_event) for (int i = 0; i != ids.size(); ++i) { if (id_ == ids[i]) continue; - if (GuiWorkArea * wa = guiApp->view(ids[i]).workArea(*b)) { + if (guiApp->view(ids[i]).workArea(*b)) { // FIXME 1: should we put an alert box here that the buffer // is viewed elsewhere? // FIXME 2: should we try to save this buffer in any case? @@ -1627,6 +1602,10 @@ bool GuiView::closeBuffer(Buffer & buf) else file = buf.fileName().displayName(30); + // Bring this window to top before asking questions. + raise(); + activateWindow(); + docstring const text = bformat(_("The document %1$s has unsaved changes." "\n\nDo you want to save the document or discard the changes?"), file); int const ret = Alert::prompt(_("Save changed document?"), @@ -1658,17 +1637,6 @@ bool GuiView::closeBuffer(Buffer & buf) } -bool GuiView::quitWriteAll() -{ - while (!theBufferList().empty()) { - Buffer * b = theBufferList().first(); - if (!closeBuffer(*b)) - return false; - } - return true; -} - - bool GuiView::dispatch(FuncRequest const & cmd) { BufferView * bv = view(); diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 4274bdc8a8..49433ce137 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -62,7 +62,6 @@ public: /// int id() const { return id_; } - void close(); void setFocus(); void setBusy(bool); /// returns true if this view has the focus. @@ -99,8 +98,6 @@ public: void importDocument(std::string const &); /// void newDocument(std::string const & filename, bool fromTemplate); - /// write all buffers, asking the user, returns false if cancelled - bool quitWriteAll(); /// GuiBufferDelegate. ///@{