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
This commit is contained in:
Abdelrazak Younes 2007-10-02 16:32:58 +00:00
parent f0402e69c6
commit fce745f111
3 changed files with 12 additions and 15 deletions

View File

@ -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_;
}

View File

@ -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<WorkArea *>::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

View File

@ -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<GuiWorkArea *>(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();