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)
35 Dialog * Dialogs::find_or_build(string const & name)
37 if (!isValidName(name))
40 std::map<string, DialogPtr>::iterator it =
43 if (it != dialogs_.end())
44 return it->second.get();
46 dialogs_[name].reset(build(name));
47 return dialogs_[name].get();
51 void Dialogs::show(string const & name, string const & data)
57 Dialog * dialog = find_or_build(name);
59 dialog->showData(data);
65 void Dialogs::show(string const & name, string const & data, Inset * inset)
71 Dialog * dialog = find_or_build(name);
73 dialog->showData(data);
74 open_insets_[name] = inset;
80 bool Dialogs::visible(string const & name) const
82 std::map<string, DialogPtr>::const_iterator it =
84 if (it == dialogs_.end())
86 return it->second.get()->isVisibleView();
90 void Dialogs::update(string const & name, string const & data)
92 std::map<string, DialogPtr>::const_iterator it =
94 if (it == dialogs_.end())
97 Dialog * const dialog = it->second.get();
98 if (dialog->isVisibleView())
99 dialog->updateData(data);
103 void Dialogs::hide(string const & name, Inset* inset)
105 // Don't send the signal if we are quitting, because on MSVC it is
106 // destructed before the cut stack in CutAndPaste.cpp, and this method
107 // is called from some inset destructor if the cut stack is not empty
112 std::map<string, DialogPtr>::const_iterator it =
114 if (it == dialogs_.end())
117 if (inset && inset != getOpenInset(name))
120 Dialog * const dialog = it->second.get();
121 if (dialog->isVisibleView())
123 open_insets_[name] = 0;
127 void Dialogs::disconnect(string const & name)
129 if (!isValidName(name))
132 if (open_insets_.find(name) != open_insets_.end())
133 open_insets_[name] = 0;
137 Inset * Dialogs::getOpenInset(string const & name) const
139 if (!isValidName(name))
142 std::map<string, Inset *>::const_iterator it =
143 open_insets_.find(name);
144 return it == open_insets_.end() ? 0 : it->second;
148 void Dialogs::hideAll() const
150 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
151 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
153 for(; it != end; ++it)
158 void Dialogs::hideBufferDependent() const
160 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
161 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
163 for(; it != end; ++it) {
164 Dialog * dialog = it->second.get();
165 if (dialog->controller().isBufferDependent())
171 void Dialogs::updateBufferDependent(bool switched) const
173 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
174 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
176 for(; it != end; ++it) {
177 Dialog * dialog = it->second.get();
178 if (switched && dialog->controller().isBufferDependent()) {
179 if (dialog->isVisibleView() && dialog->controller().initialiseParams(""))
180 dialog->updateView();
184 // A bit clunky, but the dialog will request
185 // that the kernel provides it with the necessary
187 dialog->slotRestore();
193 void Dialogs::redraw() const
195 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
196 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
198 for(; it != end; ++it)
199 it->second->redraw();
203 void Dialogs::checkStatus()
205 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
206 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
208 for(; it != end; ++it) {
209 Dialog * const dialog = it->second.get();
210 if (dialog->isVisibleView())
211 dialog->checkStatus();
215 } // namespace frontend