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/signal.hpp>
20 #include <boost/bind.hpp>
24 using lyx::frontend::Dialog;
27 // Note that static boost signals break some compilers, so this wrapper
28 // initialises the signal dynamically when it is first invoked.
29 template<typename Signal>
32 Signal & operator()() { return thesignal(); }
33 Signal const & operator()() const { return thesignal(); }
36 Signal & thesignal() const
39 signal_.reset(new Signal);
43 mutable boost::scoped_ptr<Signal> signal_;
47 boost::signal<void()> & Dialogs::redrawGUI()
49 static BugfixSignal<boost::signal<void()> > thesignal;
56 BugfixSignal<boost::signal<void(string const &, InsetBase*)> > hideSignal;
61 void Dialogs::hide(string const & name, InsetBase* inset)
63 hideSignal()(name, inset);
67 Dialogs::Dialogs(LyXView & lyxview)
68 : lyxview_(lyxview), in_show_(false)
71 redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
75 Dialog * Dialogs::find_or_build(string const & name)
77 if (!isValidName(name))
80 std::map<string, DialogPtr>::iterator it =
83 if (it != dialogs_.end())
84 return it->second.get();
86 dialogs_[name] = build(name);
87 return dialogs_[name].get();
91 void Dialogs::show(string const & name, string const & data)
97 Dialog * dialog = find_or_build(name);
99 // FIXME! Should check that the dialog is NOT an inset dialog.
106 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
112 Dialog * dialog = find_or_build(name);
114 // FIXME! Should check that the dialog IS an inset dialog.
116 open_insets_[name] = inset;
122 bool Dialogs::visible(string const & name) const
124 std::map<string, DialogPtr>::const_iterator it =
126 if (it == dialogs_.end())
128 return it->second.get()->isVisible();
132 void Dialogs::update(string const & name, string const & data)
134 std::map<string, DialogPtr>::const_iterator it =
136 if (it == dialogs_.end())
139 Dialog * const dialog = it->second.get();
140 if (dialog->isVisible())
141 dialog->update(data);
145 void Dialogs::hideSlot(string const & name, InsetBase * inset)
147 std::map<string, DialogPtr>::const_iterator it =
149 if (it == dialogs_.end())
152 if (inset && inset != getOpenInset(name))
155 Dialog * const dialog = it->second.get();
156 if (dialog->isVisible())
158 open_insets_[name] = 0;
162 void Dialogs::disconnect(string const & name)
164 if (!isValidName(name))
167 open_insets_[name] = 0;
171 InsetBase * Dialogs::getOpenInset(string const & name) const
173 if (!isValidName(name))
176 std::map<string, InsetBase *>::const_iterator it =
177 open_insets_.find(name);
178 return it == open_insets_.end() ? 0 : it->second;
182 void Dialogs::hideAll() const
184 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
185 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
187 for(; it != end; ++it) {
193 void Dialogs::hideBufferDependent() const
195 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
196 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
198 for(; it != end; ++it) {
199 Dialog * dialog = it->second.get();
200 if (dialog->controller().isBufferDependent())
206 void Dialogs::updateBufferDependent(bool switched) const
208 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
209 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
211 for(; it != end; ++it) {
212 Dialog * dialog = it->second.get();
213 if (switched && dialog->controller().isBufferDependent()) {
216 // A bit clunky, but the dialog will request
217 // that the kernel provides it with the necessary
219 dialog->RestoreButton();
225 void Dialogs::redraw() const
227 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
228 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
230 for(; it != end; ++it) {
231 it->second->redraw();
236 void Dialogs::checkStatus()
238 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
239 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
241 for(; it != end; ++it) {
242 Dialog * const dialog = it->second.get();
243 if (dialog->isVisible())
244 dialog->checkStatus();