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);
102 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
104 Dialog * dialog = find(name);
109 open_insets_[name] = inset;
113 bool Dialogs::visible(string const & name) const
115 std::map<string, DialogPtr>::const_iterator it =
117 if (it == dialogs_.end())
119 return it->second.get()->isVisible();
123 void Dialogs::update(string const & name, string const & data)
125 Dialog * dialog = find(name);
129 if (dialog->isVisible())
130 dialog->update(data);
134 void Dialogs::hideSlot(string const & name, InsetBase * inset)
136 Dialog * dialog = find(name);
140 if (inset && inset != getOpenInset(name))
143 if (dialog->isVisible())
145 open_insets_[name] = 0;
149 void Dialogs::disconnect(string const & name)
151 if (!isValidName(name))
154 open_insets_[name] = 0;
158 InsetBase * Dialogs::getOpenInset(string const & name) const
160 if (!isValidName(name))
163 std::map<string, InsetBase *>::const_iterator it =
164 open_insets_.find(name);
165 return it == open_insets_.end() ? 0 : it->second;
169 void Dialogs::hideAll() const
171 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
172 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
174 for(; it != end; ++it) {
181 void Dialogs::hideBufferDependent() const
183 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
184 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
186 for(; it != end; ++it) {
187 Dialog * dialog = it->second.get();
188 if (dialog->controller().isBufferDependent())
191 hideBufferDependentSignal();
195 void Dialogs::updateBufferDependent(bool switched) const
197 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
198 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
200 for(; it != end; ++it) {
201 Dialog * dialog = it->second.get();
202 if (switched && dialog->controller().isBufferDependent()) {
205 // A bit clunky, but the dialog will request
206 // that the kernel provides it with the necessary
208 dialog->RestoreButton();
211 updateBufferDependentSignal(switched);
215 void Dialogs::redraw() const
217 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
218 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
220 for(; it != end; ++it) {
221 it->second->redraw();