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.
5 * \author Angus Leeming
7 * Full author contact details are available in file CREDITS
9 * Common to all frontends' Dialogs
15 #include "controllers/Dialog.h"
16 #include <boost/signals/signal2.hpp>
17 #include <boost/bind.hpp>
20 // Note that static boost signals break some compilers, so this wrapper
21 // initialises the signal dynamically when it is first invoked.
22 template<typename Signal>
25 Signal & operator()() { return thesignal(); }
26 Signal const & operator()() const { return thesignal(); }
29 Signal & thesignal() const
32 signal_.reset(new Signal);
36 mutable boost::scoped_ptr<Signal> signal_;
40 boost::signal0<void> & Dialogs::redrawGUI()
42 static BugfixSignal<boost::signal0<void> > thesignal;
49 BugfixSignal<boost::signal2<void, string const &, InsetBase*> > hideSignal;
54 void Dialogs::hide(string const & name, InsetBase* inset)
56 hideSignal()(name, inset);
60 Dialogs::Dialogs(LyXView & lyxview)
64 redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
65 hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
67 // All this is slated to go
69 // reduce the number of connections needed in
70 // dialogs by a simple connection here.
71 hideAllSignal.connect(hideBufferDependentSignal);
75 Dialog * Dialogs::find(string const & name)
77 if (!isValidName(name))
80 std::map<string, DialogPtr>::iterator it =
83 if (it == dialogs_.end()) {
84 dialogs_[name] = DialogPtr(build(name));
85 return dialogs_[name].get();
88 return it->second.get();
92 void Dialogs::show(string const & name, string const & data)
94 Dialog * dialog = find(name);
98 // FIXME! Should check that the dialog is NOT an inset dialog.
103 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
105 Dialog * dialog = find(name);
109 // FIXME! Should check that the dialog IS an inset dialog.
111 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 Dialog * dialog = find(name);
131 if (dialog->isVisible())
132 dialog->update(data);
136 void Dialogs::hideSlot(string const & name, InsetBase * inset)
138 Dialog * dialog = find(name);
142 if (inset && inset != getOpenInset(name))
145 if (dialog->isVisible())
147 open_insets_[name] = 0;
151 void Dialogs::disconnect(string const & name)
153 if (!isValidName(name))
156 open_insets_[name] = 0;
160 InsetBase * Dialogs::getOpenInset(string const & name) const
162 if (!isValidName(name))
165 std::map<string, InsetBase *>::const_iterator it =
166 open_insets_.find(name);
167 return it == open_insets_.end() ? 0 : it->second;
171 void Dialogs::hideAll() const
173 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
174 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
176 for(; it != end; ++it) {
183 void Dialogs::hideBufferDependent() const
185 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
186 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
188 for(; it != end; ++it) {
189 Dialog * dialog = it->second.get();
190 if (dialog->controller().isBufferDependent())
193 hideBufferDependentSignal();
197 void Dialogs::updateBufferDependent(bool switched) 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 (switched && dialog->controller().isBufferDependent()) {
207 // A bit clunky, but the dialog will request
208 // that the kernel provides it with the necessary
210 dialog->RestoreButton();
213 updateBufferDependentSignal(switched);
217 void Dialogs::redraw() const
219 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
220 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
222 for(; it != end; ++it) {
223 it->second->redraw();