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 Dialogs::Dialogs(LyXView & lyxview)
50 redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
52 // All this is slated to go
54 // reduce the number of connections needed in
55 // dialogs by a simple connection here.
56 hideAllSignal.connect(hideBufferDependentSignal);
60 Dialog * Dialogs::find(string const & name)
62 if (!isValidName(name))
65 std::map<string, DialogPtr>::iterator it =
68 if (it == dialogs_.end()) {
69 dialogs_[name] = DialogPtr(build(name));
70 return dialogs_[name].get();
73 return it->second.get();
77 void Dialogs::show(string const & name)
79 Dialog * dialog = find(name);
87 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
89 Dialog * dialog = find(name);
94 open_insets_[name] = inset;
98 void Dialogs::update(string const & name, string const & data)
100 Dialog * dialog = find(name);
104 if (dialog->isVisible())
105 dialog->update(data);
109 void Dialogs::hide(string const & name)
111 Dialog * dialog = find(name);
115 if (dialog->isVisible())
117 open_insets_[name] = 0;
121 void Dialogs::disconnect(string const & name)
123 if (!isValidName(name))
126 open_insets_[name] = 0;
130 InsetBase * Dialogs::getOpenInset(string const & name) const
132 if (!isValidName(name))
135 std::map<string, InsetBase *>::const_iterator it =
136 open_insets_.find(name);
137 return it == open_insets_.end() ? 0 : it->second;
141 void Dialogs::hideAll() const
143 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
144 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
146 for(; it != end; ++it) {
153 void Dialogs::hideBufferDependent() 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) {
159 Dialog * dialog = it->second.get();
160 if (dialog->controller().isBufferDependent())
163 hideBufferDependentSignal();
167 void Dialogs::updateBufferDependent(bool switched) const
169 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
170 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
172 for(; it != end; ++it) {
173 Dialog * dialog = it->second.get();
174 if (switched && dialog->controller().isBufferDependent()) {
177 // A bit clunky, but the dialog will request
178 // that the kernel provides it with the necessary
180 dialog->RestoreButton();
183 updateBufferDependentSignal(switched);
187 void Dialogs::redraw() const
189 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
190 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
192 for(; it != end; ++it) {
193 it->second->redraw();