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)
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)
93 Dialog * dialog = find_or_build(name);
97 // FIXME! Should check that the dialog is NOT an inset dialog.
102 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
104 Dialog * dialog = find_or_build(name);
108 // FIXME! Should check that the dialog IS an inset dialog.
110 open_insets_[name] = inset;
114 bool Dialogs::visible(string const & name) const
116 std::map<string, DialogPtr>::const_iterator it =
118 if (it == dialogs_.end())
120 return it->second.get()->isVisible();
124 void Dialogs::update(string const & name, string const & data)
126 std::map<string, DialogPtr>::const_iterator it =
128 if (it == dialogs_.end())
131 Dialog * const dialog = it->second.get();
132 if (dialog->isVisible())
133 dialog->update(data);
137 void Dialogs::hideSlot(string const & name, InsetBase * inset)
139 std::map<string, DialogPtr>::const_iterator it =
141 if (it == dialogs_.end())
144 if (inset && inset != getOpenInset(name))
147 Dialog * const dialog = it->second.get();
148 if (dialog->isVisible())
150 open_insets_[name] = 0;
154 void Dialogs::disconnect(string const & name)
156 if (!isValidName(name))
159 open_insets_[name] = 0;
163 InsetBase * Dialogs::getOpenInset(string const & name) const
165 if (!isValidName(name))
168 std::map<string, InsetBase *>::const_iterator it =
169 open_insets_.find(name);
170 return it == open_insets_.end() ? 0 : it->second;
174 void Dialogs::hideAll() const
176 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
177 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
179 for(; it != end; ++it) {
185 void Dialogs::hideBufferDependent() const
187 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
188 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
190 for(; it != end; ++it) {
191 Dialog * dialog = it->second.get();
192 if (dialog->controller().isBufferDependent())
198 void Dialogs::updateBufferDependent(bool switched) const
200 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
201 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
203 for(; it != end; ++it) {
204 Dialog * dialog = it->second.get();
205 if (switched && dialog->controller().isBufferDependent()) {
208 // A bit clunky, but the dialog will request
209 // that the kernel provides it with the necessary
211 dialog->RestoreButton();
217 void Dialogs::redraw() const
219 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
220 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
222 for(; it != end; ++it) {
223 it->second->redraw();