Allow for nested setBusy calls.

Before, LyX could crash when calling setBusy(false) while LyX is still in a busy state due to a surrounding setBusy(true)/setBusy(false) construction.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36140 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2010-11-05 20:24:58 +00:00
parent 44279587e5
commit ab8d87f26a
2 changed files with 12 additions and 4 deletions

View File

@ -397,7 +397,7 @@ QSet<Buffer const *> GuiView::GuiViewPrivate::busyBuffers;
GuiView::GuiView(int id) GuiView::GuiView(int id)
: d(*new GuiViewPrivate(this)), id_(id), closing_(false) : d(*new GuiViewPrivate(this)), id_(id), closing_(false), busy_(0)
{ {
// GuiToolbars *must* be initialised before the menu bar. // GuiToolbars *must* be initialised before the menu bar.
normalSizedIcons(); // at least on Mac the default is 32 otherwise, which is huge normalSizedIcons(); // at least on Mac the default is 32 otherwise, which is huge
@ -1111,13 +1111,18 @@ bool GuiView::focusNextPrevChild(bool /*next*/)
bool GuiView::busy() const bool GuiView::busy() const
{ {
return busy_; return busy_ > 0;
} }
void GuiView::setBusy(bool busy) void GuiView::setBusy(bool busy)
{ {
busy_ = busy; bool const busy_before = busy_ > 0;
busy ? ++busy_ : --busy_;
if ((busy_ > 0) == busy_before)
// busy state didn't change
return;
if (d.current_work_area_) { if (d.current_work_area_) {
d.current_work_area_->setUpdatesEnabled(!busy); d.current_work_area_->setUpdatesEnabled(!busy);
if (busy) if (busy)

View File

@ -416,7 +416,10 @@ private:
/// flag to avoid two concurrent close events. /// flag to avoid two concurrent close events.
bool closing_; bool closing_;
/// if the view is busy the cursor shouldn't blink for instance. /// if the view is busy the cursor shouldn't blink for instance.
bool busy_; /// This counts the number of times more often we called
/// setBusy(true) compared to setBusy(false), so we can nest
/// functions that call setBusy;
int busy_;
}; };