From d08210e961311167b11d2872c642b2210961a7de Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Tue, 12 Dec 2006 01:39:50 +0000 Subject: [PATCH] Fix cancel on quit * src/lyxfunc.C (LyXFunc::dispatch): Move to GuiView::closeEvent the session code for lastpos in LFUN_LYX_QUIT. Check for unsaved changes before initiating the quit procedure in LFUN_LYX_QUIT and LFUN_WINDOW_CLOSE. * src/frontends/qt4/GuiView.h (class GuiView): New boolean member quitting_by_menu_. * src/frontends/qt4/GuiView.C (GuiView::GuiView): Initialize quitting_by_menu_. (GuiView::close): Set to true quitting_by_menu_ before calling the quit procedure and reset it afterwards. (GuiView::closeEvent): Account for the close window button. Save last positions to the session file. Remove wrongly placed call to quitWriteAll. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16248 a592a061-630c-0410-9148-cb99ea01b6c8 --- Status.15x | 7 ++++--- src/frontends/qt4/GuiView.C | 21 +++++++++++++++++++-- src/frontends/qt4/GuiView.h | 3 +++ src/lyxfunc.C | 20 +++++++------------- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/Status.15x b/Status.15x index 9dbe208cec..39992e8731 100644 --- a/Status.15x +++ b/Status.15x @@ -40,9 +40,6 @@ FILE * Non-ascii filenames do not work at all and result in an assertion or garbage. -* open lyx, create a new document, enter a few chars, quit, click cancel, lyx - still quits. - * Change Tools->Preferences->User interface->User interface to something like "kornel.default.ui"; save prefs; exit LyX; restart LyX; => crash; in the preferences file, there is an entry \bind_file "/Something/kornel.default" @@ -553,3 +550,7 @@ CREDITS: MSVC 2005 Prof., Scons) FIXED (JSpitzm 2006-12-11) +* open lyx, create a new document, enter a few chars, quit, click cancel, lyx + still quits. + FIXED (Enrico 2006-12-12) + diff --git a/src/frontends/qt4/GuiView.C b/src/frontends/qt4/GuiView.C index 094d606d83..04a370fce3 100644 --- a/src/frontends/qt4/GuiView.C +++ b/src/frontends/qt4/GuiView.C @@ -156,7 +156,8 @@ unsigned int GuiView::GuiViewPrivate::lastIconSize = 0; GuiView::GuiView(int id) - : QMainWindow(), LyXView(id), commandbuffer_(0), d(*new GuiViewPrivate) + : QMainWindow(), LyXView(id), commandbuffer_(0), d(*new GuiViewPrivate), + quitting_by_menu_(false) { // Qt bug? signal lastWindowClosed does not work setAttribute(Qt::WA_QuitOnClose, false); @@ -186,7 +187,9 @@ GuiView::~GuiView() void GuiView::close() { + quitting_by_menu_ = true; QMainWindow::close(); + quitting_by_menu_ = false; } @@ -240,13 +243,27 @@ void GuiView::macQuit() void GuiView::closeEvent(QCloseEvent * close_event) { + // we may have been called through the close window button + // which bypasses the LFUN machinery. + if (!quitting_by_menu_) { + if (!theBufferList().quitWriteAll()) { + close_event->ignore(); + return; + } + } + if (view()->buffer()) { + // save cursor position for opened files to .lyx/session + LyX::ref().session().lastFilePos().save( + FileName(buffer()->fileName()), + boost::tie(view()->cursor().pit(), + view()->cursor().pos())); + } theApp()->gui().unregisterView(id()); if (theApp()->gui().viewIds().empty()) { // this is the place where we leave the frontend. // it is the only point at which we start quitting. saveGeometry(); - theBufferList().quitWriteAll(); close_event->accept(); // quit the event loop qApp->quit(); diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 778b5d5977..5aaa1e9c89 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -132,6 +132,9 @@ private: /// command buffer QCommandBuffer * commandbuffer_; + /// are we quitting by the menu? + bool quitting_by_menu_; + /// void updateFloatingGeometry(); /// diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 107378c9e7..1ece1addda 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1034,19 +1034,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd) break; case LFUN_LYX_QUIT: - // FIXME: this code needs to be transfered somewhere else - // as lyx_view_ will most certainly be null and a same buffer - // might be visible in more than one LyXView. - if (lyx_view_ && lyx_view_->view()->buffer()) { - // save cursor Position for opened files to .lyx/session - LyX::ref().session().lastFilePos().save(FileName(lyx_view_->buffer()->fileName()), - boost::tie(view()->cursor().pit(), view()->cursor().pos()) ); - } - - // save the geometry of the current view - lyx_view_->saveGeometry(); - // quitting is triggered by the gui code (leaving the event loop) - theApp()->gui().closeAllViews(); + // quitting is triggered by the gui code + // (leaving the event loop). + if (theBufferList().quitWriteAll()) + theApp()->gui().closeAllViews(); break; case LFUN_TOC_VIEW: { @@ -1666,6 +1657,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd) case LFUN_WINDOW_CLOSE: BOOST_ASSERT(lyx_view_); BOOST_ASSERT(theApp()); + // ask the user for saving changes or cancel quit + if (!theBufferList().quitWriteAll()) + break; lyx_view_->close(); return; -- 2.39.5