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>
29 using lyx::frontend::Dialog;
32 // Note that static boost signals break some compilers, so this wrapper
33 // initialises the signal dynamically when it is first invoked.
34 template<typename Signal>
37 Signal & operator()() { return thesignal(); }
38 Signal const & operator()() const { return thesignal(); }
41 Signal & thesignal() const
44 signal_.reset(new Signal);
48 mutable boost::scoped_ptr<Signal> signal_;
54 BugfixSignal<boost::signal<void(string const &, Inset*)> > hideSignal;
59 void Dialogs::hide(string const & name, Inset* inset)
61 // Don't send the signal if we are quitting, because on MSVC it is
62 // destructed before the cut stack in CutAndPaste.cpp, and this method
63 // is called from some inset destructor if the cut stack is not empty
66 hideSignal()(name, inset);
70 Dialogs::Dialogs(LyXView & lyxview)
71 : lyxview_(lyxview), in_show_(false)
74 connection_ = hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
79 connection_.disconnect();
82 Dialog * Dialogs::find_or_build(string const & name)
84 if (!isValidName(name))
87 std::map<string, DialogPtr>::iterator it =
90 if (it != dialogs_.end())
91 return it->second.get();
93 dialogs_[name] = build(name);
94 return dialogs_[name].get();
98 void Dialogs::show(string const & name, string const & data)
104 Dialog * dialog = find_or_build(name);
106 // FIXME! Should check that the dialog is NOT an inset dialog.
113 void Dialogs::show(string const & name, string const & data, Inset * inset)
119 Dialog * dialog = find_or_build(name);
121 // FIXME! Should check that the dialog IS an inset dialog.
123 open_insets_[name] = inset;
129 bool Dialogs::visible(string const & name) const
131 std::map<string, DialogPtr>::const_iterator it =
133 if (it == dialogs_.end())
135 return it->second.get()->isVisible();
139 void Dialogs::update(string const & name, string const & data)
141 std::map<string, DialogPtr>::const_iterator it =
143 if (it == dialogs_.end())
146 Dialog * const dialog = it->second.get();
147 if (dialog->isVisible())
148 dialog->update(data);
152 void Dialogs::hideSlot(string const & name, Inset * inset)
154 std::map<string, DialogPtr>::const_iterator it =
156 if (it == dialogs_.end())
159 if (inset && inset != getOpenInset(name))
162 Dialog * const dialog = it->second.get();
163 if (dialog->isVisible())
165 open_insets_[name] = 0;
169 void Dialogs::disconnect(string const & name)
171 if (!isValidName(name))
174 if (open_insets_.find(name) != open_insets_.end())
175 open_insets_[name] = 0;
179 Inset * Dialogs::getOpenInset(string const & name) const
181 if (!isValidName(name))
184 std::map<string, Inset *>::const_iterator it =
185 open_insets_.find(name);
186 return it == open_insets_.end() ? 0 : it->second;
190 void Dialogs::hideAll() const
192 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
193 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
195 for(; it != end; ++it) {
201 void Dialogs::hideBufferDependent() const
203 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
204 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
206 for(; it != end; ++it) {
207 Dialog * dialog = it->second.get();
208 if (dialog->controller().isBufferDependent())
214 void Dialogs::updateBufferDependent(bool switched) const
216 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
217 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
219 for(; it != end; ++it) {
220 Dialog * dialog = it->second.get();
221 if (switched && dialog->controller().isBufferDependent()) {
222 if (dialog->isVisible() && dialog->controller().initialiseParams(""))
223 dialog->view().update();
227 // A bit clunky, but the dialog will request
228 // that the kernel provides it with the necessary
230 dialog->RestoreButton();
236 void Dialogs::redraw() const
238 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
239 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
241 for(; it != end; ++it) {
242 it->second->redraw();
247 void Dialogs::checkStatus()
249 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
250 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
252 for(; it != end; ++it) {
253 Dialog * const dialog = it->second.get();
254 if (dialog->isVisible())
255 dialog->checkStatus();