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 if (open_insets_.find(name) != open_insets_.end())
161 open_insets_[name] = 0;
165 InsetBase * Dialogs::getOpenInset(string const & name) const
167 if (!isValidName(name))
170 std::map<string, InsetBase *>::const_iterator it =
171 open_insets_.find(name);
172 return it == open_insets_.end() ? 0 : it->second;
176 void Dialogs::hideAll() const
178 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
179 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
181 for(; it != end; ++it) {
187 void Dialogs::hideBufferDependent() const
189 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
190 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
192 for(; it != end; ++it) {
193 Dialog * dialog = it->second.get();
194 if (dialog->controller().isBufferDependent())
200 void Dialogs::updateBufferDependent(bool switched) const
202 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
203 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
205 for(; it != end; ++it) {
206 Dialog * dialog = it->second.get();
207 if (switched && dialog->controller().isBufferDependent()) {
210 // A bit clunky, but the dialog will request
211 // that the kernel provides it with the necessary
213 dialog->RestoreButton();
219 void Dialogs::redraw() const
221 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
222 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
224 for(; it != end; ++it) {
225 it->second->redraw();
230 void Dialogs::checkStatus()
232 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
233 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
235 for(; it != end; ++it) {
236 Dialog * const dialog = it->second.get();
237 if (dialog->isVisible())
238 dialog->checkStatus();