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>
26 // Note that static boost signals break some compilers, so this wrapper
27 // initialises the signal dynamically when it is first invoked.
28 template<typename Signal>
31 Signal & operator()() { return thesignal(); }
32 Signal const & operator()() const { return thesignal(); }
35 Signal & thesignal() const
38 signal_.reset(new Signal);
42 mutable boost::scoped_ptr<Signal> signal_;
46 boost::signal0<void> & Dialogs::redrawGUI()
48 static BugfixSignal<boost::signal0<void> > thesignal;
55 BugfixSignal<boost::signal2<void, string const &, InsetBase*> > hideSignal;
60 void Dialogs::hide(string const & name, InsetBase* inset)
62 hideSignal()(name, inset);
66 Dialogs::Dialogs(LyXView & lyxview)
70 redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
74 Dialog * Dialogs::find_or_build(string const & name)
76 if (!isValidName(name))
79 std::map<string, DialogPtr>::iterator it =
82 if (it != dialogs_.end())
83 return it->second.get();
85 dialogs_[name] = build(name);
86 return dialogs_[name].get();
90 void Dialogs::show(string const & name, string const & data)
92 Dialog * dialog = find_or_build(name);
96 // FIXME! Should check that the dialog is NOT an inset dialog.
101 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
103 Dialog * dialog = find_or_build(name);
107 // FIXME! Should check that the dialog IS an inset dialog.
109 open_insets_[name] = inset;
113 bool Dialogs::visible(string const & name) const
115 std::map<string, DialogPtr>::const_iterator it =
117 if (it == dialogs_.end())
119 return it->second.get()->isVisible();
123 void Dialogs::update(string const & name, string const & data)
125 std::map<string, DialogPtr>::const_iterator it =
127 if (it == dialogs_.end())
130 Dialog * const dialog = it->second.get();
131 if (dialog->isVisible())
132 dialog->update(data);
136 void Dialogs::hideSlot(string const & name, InsetBase * inset)
138 std::map<string, DialogPtr>::const_iterator it =
140 if (it == dialogs_.end())
143 if (inset && inset != getOpenInset(name))
146 Dialog * const dialog = it->second.get();
147 if (dialog->isVisible())
149 open_insets_[name] = 0;
153 void Dialogs::disconnect(string const & name)
155 if (!isValidName(name))
158 open_insets_[name] = 0;
162 InsetBase * Dialogs::getOpenInset(string const & name) const
164 if (!isValidName(name))
167 std::map<string, InsetBase *>::const_iterator it =
168 open_insets_.find(name);
169 return it == open_insets_.end() ? 0 : it->second;
173 void Dialogs::hideAll() const
175 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
176 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
178 for(; it != end; ++it) {
184 void Dialogs::hideBufferDependent() const
186 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
187 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
189 for(; it != end; ++it) {
190 Dialog * dialog = it->second.get();
191 if (dialog->controller().isBufferDependent())
197 void Dialogs::updateBufferDependent(bool switched) const
199 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
200 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
202 for(; it != end; ++it) {
203 Dialog * dialog = it->second.get();
204 if (switched && dialog->controller().isBufferDependent()) {
207 // A bit clunky, but the dialog will request
208 // that the kernel provides it with the necessary
210 dialog->RestoreButton();
216 void Dialogs::redraw() const
218 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
219 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
221 for(; it != end; ++it) {
222 it->second->redraw();