mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-23 00:11:49 +00:00
a1cec91afa
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19935 a592a061-630c-0410-9148-cb99ea01b6c8
113 lines
2.2 KiB
C++
113 lines
2.2 KiB
C++
// -*- 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, GuiViewBase *>(id, new GuiViewBase(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, GuiViewBase *>::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, GuiViewBase*> const cmap = views_;
|
|
std::map<int, GuiViewBase*>::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"
|