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/signals/signal2.hpp>
20 #include <boost/bind.hpp>
26 // Note that static boost signals break some compilers, so this wrapper
27 // initialises the signal dynamically when it is first invoked.
28 template<typename Signal>
31 Signal & operator()() { return thesignal(); }
32 Signal const & operator()() const { return thesignal(); }
35 Signal & thesignal() const
38 signal_.reset(new Signal);
42 mutable boost::scoped_ptr<Signal> signal_;
46 boost::signal0<void> & Dialogs::redrawGUI()
48 static BugfixSignal<boost::signal0<void> > thesignal;
55 BugfixSignal<boost::signal2<void, string const &, InsetBase*> > hideSignal;
60 void Dialogs::hide(string const & name, InsetBase* inset)
62 hideSignal()(name, inset);
66 Dialogs::Dialogs(LyXView & lyxview)
70 redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
71 hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
73 // All this is slated to go
75 // reduce the number of connections needed in
76 // dialogs by a simple connection here.
77 hideAllSignal.connect(hideBufferDependentSignal);
81 Dialog * Dialogs::find_or_build(string const & name)
83 if (!isValidName(name))
86 std::map<string, DialogPtr>::iterator it =
89 if (it != dialogs_.end())
90 return it->second.get();
92 dialogs_[name] = DialogPtr(build(name));
93 return dialogs_[name].get();
97 void Dialogs::show(string const & name, string const & data)
99 Dialog * dialog = find_or_build(name);
103 // FIXME! Should check that the dialog is NOT an inset dialog.
108 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
110 Dialog * dialog = find_or_build(name);
114 // FIXME! Should check that the dialog IS an inset dialog.
116 open_insets_[name] = inset;
120 bool Dialogs::visible(string const & name) const
122 std::map<string, DialogPtr>::const_iterator it =
124 if (it == dialogs_.end())
126 return it->second.get()->isVisible();
130 void Dialogs::update(string const & name, string const & data)
132 std::map<string, DialogPtr>::const_iterator it =
134 if (it == dialogs_.end())
137 Dialog * const dialog = it->second.get();
138 if (dialog->isVisible())
139 dialog->update(data);
143 void Dialogs::hideSlot(string const & name, InsetBase * inset)
145 std::map<string, DialogPtr>::const_iterator it =
147 if (it == dialogs_.end())
150 if (inset && inset != getOpenInset(name))
153 Dialog * const dialog = it->second.get();
154 if (dialog->isVisible())
156 open_insets_[name] = 0;
160 void Dialogs::disconnect(string const & name)
162 if (!isValidName(name))
165 open_insets_[name] = 0;
169 InsetBase * Dialogs::getOpenInset(string const & name) const
171 if (!isValidName(name))
174 std::map<string, InsetBase *>::const_iterator it =
175 open_insets_.find(name);
176 return it == open_insets_.end() ? 0 : it->second;
180 void Dialogs::hideAll() const
182 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
183 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
185 for(; it != end; ++it) {
192 void Dialogs::hideBufferDependent() const
194 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
195 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
197 for(; it != end; ++it) {
198 Dialog * dialog = it->second.get();
199 if (dialog->controller().isBufferDependent())
202 hideBufferDependentSignal();
206 void Dialogs::updateBufferDependent(bool switched) const
208 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
209 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
211 for(; it != end; ++it) {
212 Dialog * dialog = it->second.get();
213 if (switched && dialog->controller().isBufferDependent()) {
216 // A bit clunky, but the dialog will request
217 // that the kernel provides it with the necessary
219 dialog->RestoreButton();
222 updateBufferDependentSignal(switched);
226 void Dialogs::redraw() const
228 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
229 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
231 for(; it != end; ++it) {
232 it->second->redraw();