// -*- 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 #include "GuiImplementation.h" #include "GuiView.h" #include namespace { template void updateIds(std::map const & stdmap, std::vector & ids) { ids.clear(); typename std::map::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(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::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 const cmap = views_; std::map::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"