From fce745f111de3c3aae85a7bf81e41997d8d7e6c5 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 2 Oct 2007 16:32:58 +0000 Subject: [PATCH] Simplify WorkArea (de-)registering: now done at WorkArea construction and destruction. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20665 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/WorkArea.cpp | 3 +++ src/frontends/WorkAreaManager.cpp | 16 +++++++++------- src/frontends/qt4/GuiView.cpp | 8 -------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/frontends/WorkArea.cpp b/src/frontends/WorkArea.cpp index d3dbee4ec5..e97903a929 100644 --- a/src/frontends/WorkArea.cpp +++ b/src/frontends/WorkArea.cpp @@ -18,6 +18,7 @@ #include "frontends/Application.h" #include "frontends/FontMetrics.h" #include "frontends/LyXView.h" +#include "frontends/WorkAreaManager.h" #include "BufferView.h" #include "Buffer.h" @@ -68,6 +69,7 @@ WorkArea::WorkArea(Buffer & buffer, LyXView & lv) : buffer_view_(new BufferView(buffer)), lyx_view_(&lv), cursor_visible_(false), cursor_timeout_(400) { + buffer.workAreaManager().add(this); // Setup the signals timecon = cursor_timeout_.timeout .connect(boost::bind(&WorkArea::toggleCursor, this)); @@ -78,6 +80,7 @@ WorkArea::WorkArea(Buffer & buffer, LyXView & lv) WorkArea::~WorkArea() { + buffer_view_->buffer().workAreaManager().remove(this); delete buffer_view_; } diff --git a/src/frontends/WorkAreaManager.cpp b/src/frontends/WorkAreaManager.cpp index a8c90309fd..7970bfaf26 100644 --- a/src/frontends/WorkAreaManager.cpp +++ b/src/frontends/WorkAreaManager.cpp @@ -18,6 +18,9 @@ using std::list; namespace lyx { + +extern bool quitting; + namespace frontend { void WorkAreaManager::add(WorkArea * wa) @@ -44,13 +47,12 @@ void WorkAreaManager::redrawAll() void WorkAreaManager::closeAll() { - for (list::iterator it = work_areas_.begin(); - it != work_areas_.end(); ) { - (*it)->close(); - if (work_areas_.empty()) - break; - ++it; - } + if (quitting) + return; + + while (!work_areas_.empty()) + // WorkArea is de-registering itself. + (*work_areas_.begin())->close(); } } // namespace frontend diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index b8f489c09d..12bd110929 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -27,7 +27,6 @@ #include "frontends/Dialogs.h" #include "frontends/Gui.h" #include "frontends/WorkArea.h" -#include "frontends/WorkAreaManager.h" #include "support/filetools.h" #include "support/convert.h" @@ -298,8 +297,6 @@ void GuiViewBase::close() for (int i = 0; i != d.tab_widget_->count(); ++i) { GuiWorkArea * wa = dynamic_cast(d.tab_widget_->widget(i)); BOOST_ASSERT(wa); - Buffer & buffer = wa->bufferView().buffer(); - buffer.workAreaManager().remove(wa); d.tab_widget_->removeTab(i); delete wa; } @@ -867,8 +864,6 @@ WorkArea * GuiViewBase::addWorkArea(Buffer & buffer) d.stack_widget_->setCurrentWidget(d.tab_widget_); // Hide tabbar if there's only one tab. d.tab_widget_->showBar(d.tab_widget_->count() > 1); - /// - buffer.workAreaManager().add(wa); return wa; } @@ -919,9 +914,6 @@ void GuiViewBase::removeWorkArea(WorkArea * work_area) disconnectBufferView(); } - Buffer & buffer = work_area->bufferView().buffer(); - buffer.workAreaManager().remove(work_area); - // removing a work area often results from closing a file so // update the toc in any case. updateToc(); -- 2.39.2