From: Abdelrazak Younes Date: Thu, 26 Oct 2006 13:29:10 +0000 (+0000) Subject: This commit fixes 3 crashes when reverting a document: X-Git-Tag: 1.6.10~12187 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=128a8ef3e86fedf60b2a123da089898994f4211e;p=lyx.git This commit fixes 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. * BufferView::loadLyXFile(): set buffer_ to 0 in case of a reload (when document is reverted) * LyXView: - busy() is not const anymore (work_area_ is modified in GuiView) - loadLyXFile(): encapsulate the file loading with busy(true)/busy(false) - setBuffer(): encapsulate the buffer-switching with busy(true)/busy(false) * GuiView::busy() - disable/enable workarea updates. - disable/enable blinking cursor. * WorkArea: new startBlinkingCursor() and stopBlinkingCursor() methods. * rowpainter.C: - paintText(): make sure there is a Buffer from which to paint. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15556 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView.C b/src/BufferView.C index ea667c43f9..e6f4f85bd7 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -246,6 +246,7 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles) if (!theBufferList().close(theBufferList().getBuffer(s), false)) return false; // Fall through to new load. (Asger) + buffer_ = 0; } Buffer * b = 0; diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index c8cc8b92ef..5b506ff57d 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -105,6 +105,8 @@ Buffer * LyXView::buffer() const void LyXView::setBuffer(Buffer * b) { + busy(true); + if (work_area_->bufferView().buffer()) disconnectBuffer(); @@ -129,12 +131,15 @@ void LyXView::setBuffer(Buffer * b) 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 @@ bool LyXView::loadLyXFile(string const & filename, bool tolastfiles) showErrorList("Parse"); } updateStatusBar(); + busy(false); work_area_->redraw(); return loaded; } diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index 21dd301c81..f9f7454c44 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -93,7 +93,7 @@ public: 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; diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C index cf2690620f..aa52291811 100644 --- a/src/frontends/WorkArea.C +++ b/src/frontends/WorkArea.C @@ -119,6 +119,18 @@ BufferView const & WorkArea::bufferView() const } +void WorkArea::stopBlinkingCursor() +{ + cursor_timeout_.stop(); +} + + +void WorkArea::startBlinkingCursor() +{ + cursor_timeout_.restart(); +} + + void WorkArea::checkAndGreyOut() { if (greyed_out_) diff --git a/src/frontends/WorkArea.h b/src/frontends/WorkArea.h index 0995364f24..6876bf7972 100644 --- a/src/frontends/WorkArea.h +++ b/src/frontends/WorkArea.h @@ -85,6 +85,9 @@ public: virtual void redraw(); /// void checkAndGreyOut(); + /// + void stopBlinkingCursor(); + void startBlinkingCursor(); protected: /// grey out (no buffer) diff --git a/src/frontends/qt4/GuiView.C b/src/frontends/qt4/GuiView.C index 1868891cb5..f1611262de 100644 --- a/src/frontends/qt4/GuiView.C +++ b/src/frontends/qt4/GuiView.C @@ -12,9 +12,10 @@ #include -#include "GuiImplementation.h" - #include "GuiView.h" + +#include "GuiImplementation.h" +#include "GuiWorkArea.h" #include "QLMenubar.h" #include "QLToolbar.h" #include "QCommandBuffer.h" @@ -288,12 +289,18 @@ void GuiView::show() } -void GuiView::busy(bool yes) const +void GuiView::busy(bool yes) { - if (yes) + static_cast(work_area_)->setUpdatesEnabled(!yes); + + if (yes) { + work_area_->stopBlinkingCursor(); QApplication::setOverrideCursor(Qt::WaitCursor); - else + } + else { + work_area_->startBlinkingCursor(); QApplication::restoreOverrideCursor(); + } } diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 1eec4bb535..f527dcec1d 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -63,7 +63,7 @@ public: 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); diff --git a/src/rowpainter.C b/src/rowpainter.C index 40144cc407..f4fb24d1e2 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -898,6 +898,9 @@ void paintPar void paintText(BufferView & bv, ViewMetricsInfo const & vi, Painter & pain) { + if (!bv.buffer()) + return; + LyXText & text = bv.buffer()->text(); bool const select = bv.cursor().selection();