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
17 #include "controllers/Dialog.h"
19 #include <boost/signal.hpp>
20 #include <boost/bind.hpp>
24 using lyx::frontend::Dialog;
27 // Note that static boost signals break some compilers, so this wrapper
28 // initialises the signal dynamically when it is first invoked.
29 template<typename Signal>
32 Signal & operator()() { return thesignal(); }
33 Signal const & operator()() const { return thesignal(); }
36 Signal & thesignal() const
39 signal_.reset(new Signal);
43 mutable boost::scoped_ptr<Signal> signal_;
49 BugfixSignal<boost::signal<void(string const &, InsetBase*)> > hideSignal;
54 void Dialogs::hide(string const & name, InsetBase* inset)
56 hideSignal()(name, inset);
60 Dialogs::Dialogs(LyXView & lyxview)
61 : lyxview_(lyxview), in_show_(false)
64 hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
68 Dialog * Dialogs::find_or_build(string const & name)
70 if (!isValidName(name))
73 std::map<string, DialogPtr>::iterator it =
76 if (it != dialogs_.end())
77 return it->second.get();
79 dialogs_[name] = build(name);
80 return dialogs_[name].get();
84 void Dialogs::show(string const & name, string const & data)
90 Dialog * dialog = find_or_build(name);
92 // FIXME! Should check that the dialog is NOT an inset dialog.
99 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
105 Dialog * dialog = find_or_build(name);
107 // FIXME! Should check that the dialog IS an inset dialog.
109 open_insets_[name] = inset;
115 bool Dialogs::visible(string const & name) const
117 std::map<string, DialogPtr>::const_iterator it =
119 if (it == dialogs_.end())
121 return it->second.get()->isVisible();
125 void Dialogs::update(string const & name, string const & data)
127 std::map<string, DialogPtr>::const_iterator it =
129 if (it == dialogs_.end())
132 Dialog * const dialog = it->second.get();
133 if (dialog->isVisible())
134 dialog->update(data);
138 void Dialogs::hideSlot(string const & name, InsetBase * inset)
140 std::map<string, DialogPtr>::const_iterator it =
142 if (it == dialogs_.end())
145 if (inset && inset != getOpenInset(name))
148 Dialog * const dialog = it->second.get();
149 if (dialog->isVisible())
151 open_insets_[name] = 0;
155 void Dialogs::disconnect(string const & name)
157 if (!isValidName(name))
160 open_insets_[name] = 0;
164 InsetBase * Dialogs::getOpenInset(string const & name) const
166 if (!isValidName(name))
169 std::map<string, InsetBase *>::const_iterator it =
170 open_insets_.find(name);
171 return it == open_insets_.end() ? 0 : it->second;
175 void Dialogs::hideAll() 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) {
186 void Dialogs::hideBufferDependent() 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) {
192 Dialog * dialog = it->second.get();
193 if (dialog->controller().isBufferDependent())
199 void Dialogs::updateBufferDependent(bool switched) const
201 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
202 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
204 for(; it != end; ++it) {
205 Dialog * dialog = it->second.get();
206 if (switched && dialog->controller().isBufferDependent()) {
209 // A bit clunky, but the dialog will request
210 // that the kernel provides it with the necessary
212 dialog->RestoreButton();
218 void Dialogs::redraw() const
220 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
221 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
223 for(; it != end; ++it) {
224 it->second->redraw();
229 void Dialogs::checkStatus()
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 Dialog * const dialog = it->second.get();
236 if (dialog->isVisible())
237 dialog->checkStatus();