Fix some issues with buffer closing.

* Switch WorkAreaManager to std::list instead of vector.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20664 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-10-02 14:39:48 +00:00
parent 76b5c0dbd6
commit f0402e69c6
5 changed files with 50 additions and 10 deletions

View File

@ -276,11 +276,13 @@ void Buffer::changed()
} }
frontend::WorkAreaManager * Buffer::workAreaManager() const frontend::WorkAreaManager & Buffer::workAreaManager() const
{ {
return pimpl_->wa_; BOOST_ASSERT(pimpl_->wa_);
return *pimpl_->wa_;
} }
Text & Buffer::text() const Text & Buffer::text() const
{ {
return const_cast<Text &>(pimpl_->inset.text_); return const_cast<Text &>(pimpl_->inset.text_);

View File

@ -146,7 +146,7 @@ public:
void changed(); void changed();
/// ///
frontend::WorkAreaManager * workAreaManager() const; frontend::WorkAreaManager & workAreaManager() const;
/// This signal is emitted when the buffer structure is changed. /// This signal is emitted when the buffer structure is changed.
boost::signal<void()> structureChanged; boost::signal<void()> structureChanged;

View File

@ -15,6 +15,8 @@
#include "WorkAreaManager.h" #include "WorkAreaManager.h"
using std::list;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
@ -23,16 +25,32 @@ void WorkAreaManager::add(WorkArea * wa)
work_areas_.push_back(wa); work_areas_.push_back(wa);
} }
void WorkAreaManager::remove(WorkArea * wa)
{
work_areas_.remove(wa);
}
void WorkAreaManager::redrawAll() void WorkAreaManager::redrawAll()
{ {
for (size_t i = 0; i != work_areas_.size(); ++i) for (list<WorkArea *>::iterator it = work_areas_.begin();
work_areas_[i]->redraw(); it != work_areas_.end(); ) {
(*it)->redraw();
++it;
}
} }
void WorkAreaManager::closeAll() void WorkAreaManager::closeAll()
{ {
for (size_t i = 0; i != work_areas_.size(); ++i) for (list<WorkArea *>::iterator it = work_areas_.begin();
work_areas_[i]->close(); it != work_areas_.end(); ) {
(*it)->close();
if (work_areas_.empty())
break;
++it;
}
} }
} // namespace frontend } // namespace frontend

View File

@ -12,13 +12,19 @@
#ifndef WORKAREA_MANAGER_H #ifndef WORKAREA_MANAGER_H
#define WORKAREA_MANAGER_H #define WORKAREA_MANAGER_H
#include <vector> #include <list>
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
class WorkArea; class WorkArea;
/// \c WorkArea Manager.
/**
* This is a helper class designed to avoid signal/slot connections
* between a \c Buffer and the potentially multiple \c WorkArea(s)
* used to visualize this Buffer contents.
*/
class WorkAreaManager class WorkAreaManager
{ {
public: public:
@ -27,6 +33,9 @@ public:
/// ///
void add(WorkArea * wa); void add(WorkArea * wa);
///
void remove(WorkArea * wa);
/// ///
void redrawAll(); void redrawAll();
@ -34,7 +43,7 @@ public:
void closeAll(); void closeAll();
private: private:
std::vector<WorkArea *> work_areas_; std::list<WorkArea *> work_areas_;
}; };
} // namespace frontend } // namespace frontend

View File

@ -295,6 +295,14 @@ GuiViewBase::~GuiViewBase()
void GuiViewBase::close() void GuiViewBase::close()
{ {
quitting_by_menu_ = true; quitting_by_menu_ = true;
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;
}
QMainWindow::close(); QMainWindow::close();
quitting_by_menu_ = false; quitting_by_menu_ = false;
} }
@ -860,7 +868,7 @@ WorkArea * GuiViewBase::addWorkArea(Buffer & buffer)
// Hide tabbar if there's only one tab. // Hide tabbar if there's only one tab.
d.tab_widget_->showBar(d.tab_widget_->count() > 1); d.tab_widget_->showBar(d.tab_widget_->count() > 1);
/// ///
buffer.workAreaManager()->add(wa); buffer.workAreaManager().add(wa);
return wa; return wa;
} }
@ -911,6 +919,9 @@ void GuiViewBase::removeWorkArea(WorkArea * work_area)
disconnectBufferView(); disconnectBufferView();
} }
Buffer & buffer = work_area->bufferView().buffer();
buffer.workAreaManager().remove(work_area);
// removing a work area often results from closing a file so // removing a work area often results from closing a file so
// update the toc in any case. // update the toc in any case.
updateToc(); updateToc();