OK,

This patch fixes no less than 3 crashes when reverting a document!

1) crash in GuiWorkArea::paintEvent(), this one is solved by by encapsulating the file loading in LyXView by busy(true)/busy(false) and by disabling/enabling the work area update in GuiView::busy().

2) crash in the cursor blinking because the cursor is timed out at the moment you click on "Revert". So the blinking cursor is now disabled/enabled in GuiView::busy().

3) crash in BufferView::setBuffer() because the current buffer was already closed folling the "revert" command.

This is going in now.

Abdel.
Index: BufferView.C
===================================================================
--- BufferView.C        (revision 15554)
+++ BufferView.C        (working copy)
@@ -243,9 +243,11 @@
                        return true;
                }
                // FIXME: should be LFUN_REVERT
-               if (!theBufferList().close(theBufferList().getBuffer(s), false))
+               if (theBufferList().close(theBufferList().getBuffer(s), false))
+                       buffer_ = 0;
+                       // Fall through to new load. (Asger)
+               else
                        return false;
-               // Fall through to new load. (Asger)
        }
 
        Buffer * b = 0;
Index: frontends/LyXView.C
===================================================================
--- frontends/LyXView.C (revision 15553)
+++ frontends/LyXView.C (working copy)
@@ -105,6 +105,8 @@
 
 void LyXView::setBuffer(Buffer * b)
 {
+       busy(true);
+
        if (work_area_->bufferView().buffer())
                disconnectBuffer();
 
@@ -129,12 +131,15 @@
        updateLayoutChoice();
        updateWindowTitle();
        updateStatusBar();
+       busy(false);
        work_area_->redraw();
 }
 
 
 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
 {
+       busy(true);
+
        if (work_area_->bufferView().buffer())
                disconnectBuffer();
 
@@ -149,6 +154,7 @@
                showErrorList("Parse");
        }
        updateStatusBar();
+       busy(false);
        work_area_->redraw();
        return loaded;
 }
Index: frontends/LyXView.h
===================================================================
--- frontends/LyXView.h (revision 15548)
+++ frontends/LyXView.h (working copy)
@@ -93,7 +93,7 @@
        virtual void saveGeometry() = 0;
 
        /// show busy cursor
-       virtual void busy(bool) const = 0;
+       virtual void busy(bool) = 0;
 
        virtual Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const 
& tbb) = 0;
 
Index: frontends/qt4/GuiView.C
===================================================================
--- frontends/qt4/GuiView.C     (revision 15548)
+++ frontends/qt4/GuiView.C     (working copy)
@@ -12,9 +12,10 @@
 
 #include <config.h>
 
+#include "GuiView.h"
+
 #include "GuiImplementation.h"
-
-#include "GuiView.h"
+#include "GuiWorkArea.h"
 #include "QLMenubar.h"
 #include "QLToolbar.h"
 #include "QCommandBuffer.h"
@@ -288,12 +289,18 @@
 }
 
 
-void GuiView::busy(bool yes) const
+void GuiView::busy(bool yes)
 {
-       if (yes)
+       static_cast<GuiWorkArea *>(work_area_)->setUpdatesEnabled(!yes);
+
+       if (yes) {
+               work_area_->stopBlinkingCursor();
                QApplication::setOverrideCursor(Qt::WaitCursor);
-       else
+       }
+       else {
+               work_area_->startBlinkingCursor();
                QApplication::restoreOverrideCursor();
+       }
 }
 
 
Index: frontends/qt4/GuiView.h
===================================================================
--- frontends/qt4/GuiView.h     (revision 15548)
+++ frontends/qt4/GuiView.h     (working copy)
@@ -63,7 +63,7 @@
                int posx, int posy,
                bool maximize);
        virtual void saveGeometry();
-       virtual void busy(bool) const;
+       virtual void busy(bool);
        Toolbars::ToolbarPtr makeToolbar(ToolbarBackend::Toolbar const & tbb);
        virtual void updateStatusBar();
        virtual void message(lyx::docstring const & str);
Index: frontends/WorkArea.C
===================================================================
--- frontends/WorkArea.C        (revision 15553)
+++ frontends/WorkArea.C        (working copy)
@@ -119,6 +119,18 @@
 }
 
 
+void WorkArea::stopBlinkingCursor()
+{
+       cursor_timeout_.stop();
+}
+
+
+void WorkArea::startBlinkingCursor()
+{
+       cursor_timeout_.restart();
+}
+
+
 void WorkArea::checkAndGreyOut()
 {
        if (greyed_out_)
Index: frontends/WorkArea.h
===================================================================
--- frontends/WorkArea.h        (revision 15548)
+++ frontends/WorkArea.h        (working copy)
@@ -85,6 +85,9 @@
        virtual void redraw();
        ///
        void checkAndGreyOut();
+       ///
+       void stopBlinkingCursor();
+       void startBlinkingCursor();
 
 protected:
        /// grey out (no buffer)
Index: rowpainter.C
===================================================================
--- rowpainter.C        (revision 15548)
+++ rowpainter.C        (working copy)
@@ -898,6 +898,9 @@
 void paintText(BufferView & bv, ViewMetricsInfo const & vi,
               Painter & pain)
 {
+       if (!bv.buffer())
+               return;
+
        LyXText & text = bv.buffer()->text();
        bool const select = bv.cursor().selection();
 

Reply via email to