2 * \file frontends/Dialogs.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
10 * Common to all frontends' Dialogs
19 #include "controllers/Dialog.h"
21 #include <boost/signal.hpp>
22 #include <boost/bind.hpp>
30 Dialogs::Dialogs(LyXView & lyxview)
31 : lyxview_(lyxview), in_show_(false)
36 Dialog * Dialogs::find_or_build(string const & name)
38 if (!isValidName(name))
41 std::map<string, DialogPtr>::iterator it =
44 if (it != dialogs_.end())
45 return it->second.get();
47 dialogs_[name] = build(name);
48 return dialogs_[name].get();
52 void Dialogs::show(string const & name, string const & data)
58 Dialog * dialog = find_or_build(name);
60 // FIXME! Should check that the dialog is NOT an inset dialog.
67 void Dialogs::show(string const & name, string const & data, Inset * inset)
73 Dialog * dialog = find_or_build(name);
75 // FIXME! Should check that the dialog IS an inset dialog.
77 open_insets_[name] = inset;
83 bool Dialogs::visible(string const & name) const
85 std::map<string, DialogPtr>::const_iterator it =
87 if (it == dialogs_.end())
89 return it->second.get()->isVisible();
93 void Dialogs::update(string const & name, string const & data)
95 std::map<string, DialogPtr>::const_iterator it =
97 if (it == dialogs_.end())
100 Dialog * const dialog = it->second.get();
101 if (dialog->isVisible())
102 dialog->update(data);
106 void Dialogs::hide(string const & name, Inset* inset)
108 // Don't send the signal if we are quitting, because on MSVC it is
109 // destructed before the cut stack in CutAndPaste.cpp, and this method
110 // is called from some inset destructor if the cut stack is not empty
115 std::map<string, DialogPtr>::const_iterator it =
117 if (it == dialogs_.end())
120 if (inset && inset != getOpenInset(name))
123 Dialog * const dialog = it->second.get();
124 if (dialog->isVisible())
126 open_insets_[name] = 0;
130 void Dialogs::disconnect(string const & name)
132 if (!isValidName(name))
135 if (open_insets_.find(name) != open_insets_.end())
136 open_insets_[name] = 0;
140 Inset * Dialogs::getOpenInset(string const & name) const
142 if (!isValidName(name))
145 std::map<string, Inset *>::const_iterator it =
146 open_insets_.find(name);
147 return it == open_insets_.end() ? 0 : it->second;
151 void Dialogs::hideAll() const
153 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
154 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
156 for(; it != end; ++it) {
162 void Dialogs::hideBufferDependent() const
164 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
165 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
167 for(; it != end; ++it) {
168 Dialog * dialog = it->second.get();
169 if (dialog->controller().isBufferDependent())
175 void Dialogs::updateBufferDependent(bool switched) const
177 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
178 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
180 for(; it != end; ++it) {
181 Dialog * dialog = it->second.get();
182 if (switched && dialog->controller().isBufferDependent()) {
183 if (dialog->isVisible() && dialog->controller().initialiseParams(""))
184 dialog->view().update();
188 // A bit clunky, but the dialog will request
189 // that the kernel provides it with the necessary
191 dialog->RestoreButton();
197 void Dialogs::redraw() const
199 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
200 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
202 for(; it != end; ++it) {
203 it->second->redraw();
208 void Dialogs::checkStatus()
210 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
211 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
213 for(; it != end; ++it) {
214 Dialog * const dialog = it->second.get();
215 if (dialog->isVisible())
216 dialog->checkStatus();
220 } // namespace frontend