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));
72 hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
76 Dialog * Dialogs::find_or_build(string const & name)
78 if (!isValidName(name))
81 std::map<string, DialogPtr>::iterator it =
84 if (it != dialogs_.end())
85 return it->second.get();
87 dialogs_[name] = build(name);
88 return dialogs_[name].get();
92 void Dialogs::show(string const & name, string const & data)
98 Dialog * dialog = find_or_build(name);
100 // FIXME! Should check that the dialog is NOT an inset dialog.
107 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
113 Dialog * dialog = find_or_build(name);
115 // FIXME! Should check that the dialog IS an inset dialog.
117 open_insets_[name] = inset;
123 bool Dialogs::visible(string const & name) const
125 std::map<string, DialogPtr>::const_iterator it =
127 if (it == dialogs_.end())
129 return it->second.get()->isVisible();
133 void Dialogs::update(string const & name, string const & data)
135 std::map<string, DialogPtr>::const_iterator it =
137 if (it == dialogs_.end())
140 Dialog * const dialog = it->second.get();
141 if (dialog->isVisible())
142 dialog->update(data);
146 void Dialogs::hideSlot(string const & name, InsetBase * inset)
148 std::map<string, DialogPtr>::const_iterator it =
150 if (it == dialogs_.end())
153 if (inset && inset != getOpenInset(name))
156 Dialog * const dialog = it->second.get();
157 if (dialog->isVisible())
159 open_insets_[name] = 0;
163 void Dialogs::disconnect(string const & name)
165 if (!isValidName(name))
168 open_insets_[name] = 0;
172 InsetBase * Dialogs::getOpenInset(string const & name) const
174 if (!isValidName(name))
177 std::map<string, InsetBase *>::const_iterator it =
178 open_insets_.find(name);
179 return it == open_insets_.end() ? 0 : it->second;
183 void Dialogs::hideAll() const
185 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
186 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
188 for(; it != end; ++it) {
194 void Dialogs::hideBufferDependent() const
196 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
197 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
199 for(; it != end; ++it) {
200 Dialog * dialog = it->second.get();
201 if (dialog->controller().isBufferDependent())
207 void Dialogs::updateBufferDependent(bool switched) const
209 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
210 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
212 for(; it != end; ++it) {
213 Dialog * dialog = it->second.get();
214 if (switched && dialog->controller().isBufferDependent()) {
217 // A bit clunky, but the dialog will request
218 // that the kernel provides it with the necessary
220 dialog->RestoreButton();
226 void Dialogs::redraw() const
228 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
229 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
231 for(; it != end; ++it) {
232 it->second->redraw();
237 void Dialogs::checkStatus()
239 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
240 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
242 for(; it != end; ++it) {
243 Dialog * const dialog = it->second.get();
244 if (dialog->isVisible())
245 dialog->checkStatus();