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 "controllers/ButtonControllerBase.h"
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;
47 Dialogs::Dialogs(LyXView & lyxview)
51 redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
53 // All this is slated to go
55 // reduce the number of connections needed in
56 // dialogs by a simple connection here.
57 hideAllSignal.connect(hideBufferDependentSignal);
61 Dialog * Dialogs::find(string const & name)
63 if (!isValidName(name))
66 std::map<string, DialogPtr>::iterator it =
69 if (it == dialogs_.end()) {
70 dialogs_[name] = DialogPtr(build(name));
71 return dialogs_[name].get();
74 return it->second.get();
78 void Dialogs::show(string const & name)
80 Dialog * dialog = find(name);
88 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
90 Dialog * dialog = find(name);
95 open_insets_[name] = inset;
99 void Dialogs::update(string const & name, string const & data)
101 Dialog * dialog = find(name);
105 if (dialog->isVisible())
106 dialog->update(data);
110 void Dialogs::hide(string const & name)
112 Dialog * dialog = find(name);
116 if (dialog->isVisible())
118 open_insets_[name] = 0;
122 void Dialogs::disconnect(string const & name)
124 if (!isValidName(name))
127 open_insets_[name] = 0;
131 InsetBase * Dialogs::getOpenInset(string const & name) const
133 if (!isValidName(name))
136 std::map<string, InsetBase *>::const_iterator it =
137 open_insets_.find(name);
138 return it == open_insets_.end() ? 0 : it->second;
142 void Dialogs::hideAll() const
144 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
145 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
147 for(; it != end; ++it) {
154 void Dialogs::hideBufferDependent() const
156 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
157 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
159 for(; it != end; ++it) {
160 Dialog * dialog = it->second.get();
161 if (dialog->controller().isBufferDependent())
164 hideBufferDependentSignal();
168 void Dialogs::updateBufferDependent(bool switched) const
170 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
171 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
173 for(; it != end; ++it) {
174 Dialog * dialog = it->second.get();
175 if (switched && dialog->controller().isBufferDependent()) {
178 // A bit clunky, but the dialog will request
179 // that the kernel provides it with the necessary
181 dialog->RestoreButton();
184 updateBufferDependentSignal(switched);
188 void Dialogs::redraw() const
190 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
191 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
193 for(; it != end; ++it) {
194 it->second->redraw();