]> git.lyx.org Git - features.git/commitdiff
Fix cancel on quit
authorEnrico Forestieri <forenr@lyx.org>
Tue, 12 Dec 2006 01:39:50 +0000 (01:39 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Tue, 12 Dec 2006 01:39:50 +0000 (01:39 +0000)
* 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
src/frontends/qt4/GuiView.C
src/frontends/qt4/GuiView.h
src/lyxfunc.C

index 9dbe208cec79c4136775025690b61d31010d7c94..39992e8731804dfbe7949324c615ae05f0cc3bfe 100644 (file)
@@ -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)
+
index 094d606d838971930015e4be3635bbb7f2aef0ff..04a370fce3d84276fc88d463992f079873fd9edc 100644 (file)
@@ -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();
index 778b5d597724d0466384a03cc06633abc289dfeb..5aaa1e9c896d9214f1adfd38c6f6a7c7c389737f 100644 (file)
@@ -132,6 +132,9 @@ private:
        /// command buffer
        QCommandBuffer * commandbuffer_;
 
+       /// are we quitting by the menu?
+       bool quitting_by_menu_;
+
        ///
        void updateFloatingGeometry();
        ///
index 107378c9e7576ea4af6171fa96b866b73d4e8152..1ece1addda7cd565d9c24aee084a518f9ffe4c68 100644 (file)
@@ -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;