2 * \file frontends/Dialogs.C
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 &, InsetBase*)> > hideSignal;
59 void Dialogs::hide(string const & name, InsetBase* inset)
61 // Don't send the signal if we are quitting, because on MSVC it is
62 // destructed before the cut stack in CutAndPaste.C, 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 hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
78 Dialog * Dialogs::find_or_build(string const & name)
80 if (!isValidName(name))
83 std::map<string, DialogPtr>::iterator it =
86 if (it != dialogs_.end())
87 return it->second.get();
89 dialogs_[name] = build(name);
90 return dialogs_[name].get();
94 void Dialogs::show(string const & name, string const & data)
100 Dialog * dialog = find_or_build(name);
102 // FIXME! Should check that the dialog is NOT an inset dialog.
109 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
115 Dialog * dialog = find_or_build(name);
117 // FIXME! Should check that the dialog IS an inset dialog.
119 open_insets_[name] = inset;
125 bool Dialogs::visible(string const & name) const
127 std::map<string, DialogPtr>::const_iterator it =
129 if (it == dialogs_.end())
131 return it->second.get()->isVisible();
135 void Dialogs::update(string const & name, string const & data)
137 std::map<string, DialogPtr>::const_iterator it =
139 if (it == dialogs_.end())
142 Dialog * const dialog = it->second.get();
143 if (dialog->isVisible())
144 dialog->update(data);
148 void Dialogs::hideSlot(string const & name, InsetBase * inset)
150 std::map<string, DialogPtr>::const_iterator it =
152 if (it == dialogs_.end())
155 if (inset && inset != getOpenInset(name))
158 Dialog * const dialog = it->second.get();
159 if (dialog->isVisible())
161 open_insets_[name] = 0;
165 void Dialogs::disconnect(string const & name)
167 if (!isValidName(name))
170 if (open_insets_.find(name) != open_insets_.end())
171 open_insets_[name] = 0;
175 InsetBase * Dialogs::getOpenInset(string const & name) const
177 if (!isValidName(name))
180 std::map<string, InsetBase *>::const_iterator it =
181 open_insets_.find(name);
182 return it == open_insets_.end() ? 0 : it->second;
186 void Dialogs::hideAll() const
188 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
189 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
191 for(; it != end; ++it) {
197 void Dialogs::hideBufferDependent() 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 Dialog * dialog = it->second.get();
204 if (dialog->controller().isBufferDependent())
210 void Dialogs::updateBufferDependent(bool switched) const
212 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
213 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
215 for(; it != end; ++it) {
216 Dialog * dialog = it->second.get();
217 if (switched && dialog->controller().isBufferDependent()) {
220 // A bit clunky, but the dialog will request
221 // that the kernel provides it with the necessary
223 dialog->RestoreButton();
229 void Dialogs::redraw() const
231 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
232 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
234 for(; it != end; ++it) {
235 it->second->redraw();
240 void Dialogs::checkStatus()
242 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
243 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
245 for(; it != end; ++it) {
246 Dialog * const dialog = it->second.get();
247 if (dialog->isVisible())
248 dialog->checkStatus();