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(string const & name)
80 if (!isValidName(name))
83 std::map<string, DialogPtr>::iterator it =
86 if (it == dialogs_.end()) {
87 dialogs_[name] = DialogPtr(build(name));
88 return dialogs_[name].get();
91 return it->second.get();
95 void Dialogs::show(string const & name, string const & data)
97 Dialog * dialog = find(name);
101 // FIXME! Should check that the dialog is NOT an inset dialog.
106 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
108 Dialog * dialog = find(name);
112 // FIXME! Should check that the dialog IS an inset dialog.
114 open_insets_[name] = inset;
118 bool Dialogs::visible(string const & name) const
120 std::map<string, DialogPtr>::const_iterator it =
122 if (it == dialogs_.end())
124 return it->second.get()->isVisible();
128 void Dialogs::update(string const & name, string const & data)
130 Dialog * dialog = find(name);
134 if (dialog->isVisible())
135 dialog->update(data);
139 void Dialogs::hideSlot(string const & name, InsetBase * inset)
141 Dialog * dialog = find(name);
145 if (inset && inset != getOpenInset(name))
148 if (dialog->isVisible())
150 open_insets_[name] = 0;
154 void Dialogs::disconnect(string const & name)
156 if (!isValidName(name))
159 open_insets_[name] = 0;
163 InsetBase * Dialogs::getOpenInset(string const & name) const
165 if (!isValidName(name))
168 std::map<string, InsetBase *>::const_iterator it =
169 open_insets_.find(name);
170 return it == open_insets_.end() ? 0 : it->second;
174 void Dialogs::hideAll() const
176 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
177 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
179 for(; it != end; ++it) {
186 void Dialogs::hideBufferDependent() const
188 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
189 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
191 for(; it != end; ++it) {
192 Dialog * dialog = it->second.get();
193 if (dialog->controller().isBufferDependent())
196 hideBufferDependentSignal();
200 void Dialogs::updateBufferDependent(bool switched) const
202 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
203 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
205 for(; it != end; ++it) {
206 Dialog * dialog = it->second.get();
207 if (switched && dialog->controller().isBufferDependent()) {
210 // A bit clunky, but the dialog will request
211 // that the kernel provides it with the necessary
213 dialog->RestoreButton();
216 updateBufferDependentSignal(switched);
220 void Dialogs::redraw() const
222 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
223 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
225 for(; it != end; ++it) {
226 it->second->redraw();