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
19 #include "controllers/Dialog.h"
21 #include <boost/signal.hpp>
22 #include <boost/bind.hpp>
26 using lyx::frontend::Dialog;
29 // Note that static boost signals break some compilers, so this wrapper
30 // initialises the signal dynamically when it is first invoked.
31 template<typename Signal>
34 Signal & operator()() { return thesignal(); }
35 Signal const & operator()() const { return thesignal(); }
38 Signal & thesignal() const
41 signal_.reset(new Signal);
45 mutable boost::scoped_ptr<Signal> signal_;
51 BugfixSignal<boost::signal<void(string const &, InsetBase*)> > hideSignal;
56 void Dialogs::hide(string const & name, InsetBase* inset)
58 // Don't send the signal if we are quitting, because on MSVC it is
59 // destructed before the cut stack in CutAndPaste.C, and this method
60 // is called from some inset destructor if the cut stack is not empty
63 hideSignal()(name, inset);
67 Dialogs::Dialogs(LyXView & lyxview)
68 : lyxview_(lyxview), in_show_(false)
71 hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
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 if (open_insets_.find(name) != open_insets_.end())
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();