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
16 #include "controllers/Dialog.h"
17 #include <boost/signals/signal2.hpp>
18 #include <boost/bind.hpp>
21 // Note that static boost signals break some compilers, so this wrapper
22 // initialises the signal dynamically when it is first invoked.
23 template<typename Signal>
26 Signal & operator()() { return thesignal(); }
27 Signal const & operator()() const { return thesignal(); }
30 Signal & thesignal() const
33 signal_.reset(new Signal);
37 mutable boost::scoped_ptr<Signal> signal_;
41 boost::signal0<void> & Dialogs::redrawGUI()
43 static BugfixSignal<boost::signal0<void> > thesignal;
50 BugfixSignal<boost::signal2<void, string const &, InsetBase*> > hideSignal;
55 void Dialogs::hide(string const & name, InsetBase* inset)
57 hideSignal()(name, inset);
61 Dialogs::Dialogs(LyXView & lyxview)
65 redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
66 hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
68 // All this is slated to go
70 // reduce the number of connections needed in
71 // dialogs by a simple connection here.
72 hideAllSignal.connect(hideBufferDependentSignal);
76 Dialog * Dialogs::find(string const & name)
78 if (!isValidName(name))
81 std::map<string, DialogPtr>::iterator it =
84 if (it == dialogs_.end()) {
85 dialogs_[name] = DialogPtr(build(name));
86 return dialogs_[name].get();
89 return it->second.get();
93 void Dialogs::show(string const & name, string const & data)
95 Dialog * dialog = find(name);
99 // FIXME! Should check that the dialog is NOT an inset dialog.
104 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
106 Dialog * dialog = find(name);
110 // FIXME! Should check that the dialog IS an inset dialog.
112 open_insets_[name] = inset;
116 bool Dialogs::visible(string const & name) const
118 std::map<string, DialogPtr>::const_iterator it =
120 if (it == dialogs_.end())
122 return it->second.get()->isVisible();
126 void Dialogs::update(string const & name, string const & data)
128 Dialog * dialog = find(name);
132 if (dialog->isVisible())
133 dialog->update(data);
137 void Dialogs::hideSlot(string const & name, InsetBase * inset)
139 Dialog * dialog = find(name);
143 if (inset && inset != getOpenInset(name))
146 if (dialog->isVisible())
148 open_insets_[name] = 0;
152 void Dialogs::disconnect(string const & name)
154 if (!isValidName(name))
157 open_insets_[name] = 0;
161 InsetBase * Dialogs::getOpenInset(string const & name) const
163 if (!isValidName(name))
166 std::map<string, InsetBase *>::const_iterator it =
167 open_insets_.find(name);
168 return it == open_insets_.end() ? 0 : it->second;
172 void Dialogs::hideAll() const
174 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
175 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
177 for(; it != end; ++it) {
184 void Dialogs::hideBufferDependent() const
186 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
187 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
189 for(; it != end; ++it) {
190 Dialog * dialog = it->second.get();
191 if (dialog->controller().isBufferDependent())
194 hideBufferDependentSignal();
198 void Dialogs::updateBufferDependent(bool switched) const
200 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
201 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
203 for(; it != end; ++it) {
204 Dialog * dialog = it->second.get();
205 if (switched && dialog->controller().isBufferDependent()) {
208 // A bit clunky, but the dialog will request
209 // that the kernel provides it with the necessary
211 dialog->RestoreButton();
214 updateBufferDependentSignal(switched);
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();