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/bind.hpp>
19 // Note that static boost signals break some compilers, so this wrapper
20 // initialises the signal dynamically when it is first invoked.
21 template<typename Signal>
24 Signal & operator()() { return thesignal(); }
25 Signal const & operator()() const { return thesignal(); }
28 Signal & thesignal() const
31 signal_.reset(new Signal);
35 mutable boost::scoped_ptr<Signal> signal_;
39 boost::signal0<void> & Dialogs::redrawGUI()
41 static BugfixSignal<boost::signal0<void> > thesignal;
46 boost::signal2<void, string const &, InsetBase*> & Dialogs::hide()
48 static BugfixSignal<boost::signal2<void, string const &, InsetBase*> >
54 Dialogs::Dialogs(LyXView & lyxview)
58 redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
59 hide().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
61 // All this is slated to go
63 // reduce the number of connections needed in
64 // dialogs by a simple connection here.
65 hideAllSignal.connect(hideBufferDependentSignal);
69 Dialog * Dialogs::find(string const & name)
71 if (!isValidName(name))
74 std::map<string, DialogPtr>::iterator it =
77 if (it == dialogs_.end()) {
78 dialogs_[name] = DialogPtr(build(name));
79 return dialogs_[name].get();
82 return it->second.get();
86 void Dialogs::show(string const & name)
88 Dialog * dialog = find(name);
96 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
98 Dialog * dialog = find(name);
103 open_insets_[name] = inset;
107 void Dialogs::update(string const & name, string const & data)
109 Dialog * dialog = find(name);
113 if (dialog->isVisible())
114 dialog->update(data);
118 void Dialogs::hideSlot(string const & name, InsetBase * inset)
120 Dialog * dialog = find(name);
124 if (inset && inset != getOpenInset(name))
127 if (dialog->isVisible())
129 open_insets_[name] = 0;
133 void Dialogs::disconnect(string const & name)
135 if (!isValidName(name))
138 open_insets_[name] = 0;
142 InsetBase * Dialogs::getOpenInset(string const & name) const
144 if (!isValidName(name))
147 std::map<string, InsetBase *>::const_iterator it =
148 open_insets_.find(name);
149 return it == open_insets_.end() ? 0 : it->second;
153 void Dialogs::hideAll() const
155 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
156 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
158 for(; it != end; ++it) {
165 void Dialogs::hideBufferDependent() const
167 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
168 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
170 for(; it != end; ++it) {
171 Dialog * dialog = it->second.get();
172 if (dialog->controller().isBufferDependent())
175 hideBufferDependentSignal();
179 void Dialogs::updateBufferDependent(bool switched) const
181 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
182 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
184 for(; it != end; ++it) {
185 Dialog * dialog = it->second.get();
186 if (switched && dialog->controller().isBufferDependent()) {
189 // A bit clunky, but the dialog will request
190 // that the kernel provides it with the necessary
192 dialog->RestoreButton();
195 updateBufferDependentSignal(switched);
199 void Dialogs::redraw() const
201 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
202 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
204 for(; it != end; ++it) {
205 it->second->redraw();