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>
23 // Note that static boost signals break some compilers, so this wrapper
24 // initialises the signal dynamically when it is first invoked.
25 template<typename Signal>
28 Signal & operator()() { return thesignal(); }
29 Signal const & operator()() const { return thesignal(); }
32 Signal & thesignal() const
35 signal_.reset(new Signal);
39 mutable boost::scoped_ptr<Signal> signal_;
43 boost::signal0<void> & Dialogs::redrawGUI()
45 static BugfixSignal<boost::signal0<void> > thesignal;
52 BugfixSignal<boost::signal2<void, string const &, InsetBase*> > hideSignal;
57 void Dialogs::hide(string const & name, InsetBase* inset)
59 hideSignal()(name, inset);
63 Dialogs::Dialogs(LyXView & lyxview)
67 redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
68 hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
70 // All this is slated to go
72 // reduce the number of connections needed in
73 // dialogs by a simple connection here.
74 hideAllSignal.connect(hideBufferDependentSignal);
78 Dialog * Dialogs::find_or_build(string const & name)
80 if (!isValidName(name))
83 std::map<string, DialogPtr>::iterator it =
86 if (it != dialogs_.end())
87 return it->second.get();
89 dialogs_[name] = DialogPtr(build(name));
90 return dialogs_[name].get();
94 void Dialogs::show(string const & name, string const & data)
96 Dialog * dialog = find_or_build(name);
100 // FIXME! Should check that the dialog is NOT an inset dialog.
105 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
107 Dialog * dialog = find_or_build(name);
111 // FIXME! Should check that the dialog IS an inset dialog.
113 open_insets_[name] = inset;
117 bool Dialogs::visible(string const & name) const
119 std::map<string, DialogPtr>::const_iterator it =
121 if (it == dialogs_.end())
123 return it->second.get()->isVisible();
127 void Dialogs::update(string const & name, string const & data)
129 std::map<string, DialogPtr>::const_iterator it =
131 if (it == dialogs_.end())
134 Dialog * const dialog = it->second.get();
135 if (dialog->isVisible())
136 dialog->update(data);
140 void Dialogs::hideSlot(string const & name, InsetBase * inset)
142 std::map<string, DialogPtr>::const_iterator it =
144 if (it == dialogs_.end())
147 if (inset && inset != getOpenInset(name))
150 Dialog * const dialog = it->second.get();
151 if (dialog->isVisible())
153 open_insets_[name] = 0;
157 void Dialogs::disconnect(string const & name)
159 if (!isValidName(name))
162 open_insets_[name] = 0;
166 InsetBase * Dialogs::getOpenInset(string const & name) const
168 if (!isValidName(name))
171 std::map<string, InsetBase *>::const_iterator it =
172 open_insets_.find(name);
173 return it == open_insets_.end() ? 0 : it->second;
177 void Dialogs::hideAll() const
179 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
180 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
182 for(; it != end; ++it) {
189 void Dialogs::hideBufferDependent() const
191 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
192 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
194 for(; it != end; ++it) {
195 Dialog * dialog = it->second.get();
196 if (dialog->controller().isBufferDependent())
199 hideBufferDependentSignal();
203 void Dialogs::updateBufferDependent(bool switched) const
205 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
206 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
208 for(; it != end; ++it) {
209 Dialog * dialog = it->second.get();
210 if (switched && dialog->controller().isBufferDependent()) {
213 // A bit clunky, but the dialog will request
214 // that the kernel provides it with the necessary
216 dialog->RestoreButton();
219 updateBufferDependentSignal(switched);
223 void Dialogs::redraw() const
225 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
226 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
228 for(; it != end; ++it) {
229 it->second->redraw();