lyx_mirror/src/frontends/qt4/GuiImplementation.cpp

113 lines
2.1 KiB
C++
Raw Normal View History

// -*- C++ -*-
/**
* \file GuiImplementation.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Levon
* \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "GuiImplementation.h"
#include "GuiView.h"
#include <QApplication>
namespace
{
template<class T>
void updateIds(std::map<int, T*> const & stdmap, std::vector<int> & ids)
{
ids.clear();
typename std::map<int, T*>::const_iterator it;
for (it = stdmap.begin(); it != stdmap.end(); ++it)
ids.push_back(it->first);
}
}
namespace lyx {
namespace frontend {
GuiImplementation::GuiImplementation()
{
view_ids_.clear();
}
LyXView& GuiImplementation::createRegisteredView()
{
updateIds(views_, view_ids_);
int id = 0;
while (views_.find(id) != views_.end())
id++;
views_.insert(std::pair<int, GuiView *>(id, new GuiView(id)));
updateIds(views_, view_ids_);
return *views_[id];
}
bool GuiImplementation::unregisterView(int id)
{
updateIds(views_, view_ids_);
BOOST_ASSERT(views_.find(id) != views_.end());
BOOST_ASSERT(views_[id]);
std::map<int, GuiView *>::iterator it;
for (it = views_.begin(); it != views_.end(); ++it) {
if (it->first == id) {
views_.erase(id);
break;
}
}
updateIds(views_, view_ids_);
return true;
}
bool GuiImplementation::closeAllViews()
{
updateIds(views_, view_ids_);
if (views_.empty())
{
// quit in CloseEvent will not be triggert
qApp->quit();
return true;
}
std::map<int, GuiView*> const cmap = views_;
std::map<int, GuiView*>::const_iterator it;
for (it = cmap.begin(); it != cmap.end(); ++it)
{
// TODO: return false when close event was ignored
// e.g. quitWriteAll()->'Cancel'
// maybe we need something like 'bool closeView()'
it->second->close();
// unregisterd by the CloseEvent
}
views_.clear();
view_ids_.clear();
return true;
}
LyXView& GuiImplementation::view(int id) const
{
BOOST_ASSERT(views_.find(id) != views_.end());
return *views_.find(id)->second;
}
} // namespace frontend
} // namespace lyx
#include "GuiImplementation_moc.cpp"