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, string const & data, InsetBase * inset)
80 Dialog * dialog = find(name);
85 open_insets_[name] = inset;
89 void Dialogs::update(string const & name, string const & data)
91 Dialog * dialog = find(name);
95 if (dialog->isVisible())
100 void Dialogs::hide(string const & name)
102 Dialog * dialog = find(name);
106 if (dialog->isVisible())
108 open_insets_[name] = 0;
112 void Dialogs::disconnect(string const & name)
114 if (!isValidName(name))
117 open_insets_[name] = 0;
121 InsetBase * Dialogs::getOpenInset(string const & name) const
123 if (!isValidName(name))
126 std::map<string, InsetBase *>::const_iterator it =
127 open_insets_.find(name);
128 return it == open_insets_.end() ? 0 : it->second;
132 void Dialogs::hideAll() const
134 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
135 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
137 for(; it != end; ++it) {
144 void Dialogs::hideBufferDependent() const
146 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
147 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
149 for(; it != end; ++it) {
150 Dialog * dialog = it->second.get();
151 if (dialog->controller().isBufferDependent())
154 hideBufferDependentSignal();
158 void Dialogs::updateBufferDependent(bool switched) const
160 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
161 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
163 for(; it != end; ++it) {
164 Dialog * dialog = it->second.get();
165 if (switched && dialog->controller().isBufferDependent()) {
168 // A bit clunky, but the dialog will request
169 // that the kernel provides it with the necessary
171 dialog->RestoreButton();
174 updateBufferDependentSignal(switched);
178 void Dialogs::redraw() const
180 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
181 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
183 for(; it != end; ++it) {
184 it->second->redraw();