2 * \file frontends/Dialogs.cpp
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
18 #include <boost/signal.hpp>
19 #include <boost/bind.hpp>
29 Dialogs::Dialogs(LyXView & lyxview)
30 : lyxview_(lyxview), in_show_(false)
34 Dialog * Dialogs::find_or_build(string const & name)
36 if (!isValidName(name))
39 std::map<string, DialogPtr>::iterator it =
42 if (it != dialogs_.end())
43 return it->second.get();
45 dialogs_[name].reset(build(name));
46 return dialogs_[name].get();
50 void Dialogs::show(string const & name, string const & data, Inset * inset)
56 Dialog * dialog = find_or_build(name);
58 dialog->showData(data);
60 open_insets_[name] = inset;
66 bool Dialogs::visible(string const & name) const
68 std::map<string, DialogPtr>::const_iterator it = dialogs_.find(name);
69 if (it == dialogs_.end())
71 return it->second.get()->isVisibleView();
75 void Dialogs::update(string const & name, string const & data)
77 std::map<string, DialogPtr>::const_iterator it = dialogs_.find(name);
78 if (it == dialogs_.end())
81 Dialog * const dialog = it->second.get();
82 if (dialog->isVisibleView())
83 dialog->updateData(data);
87 void Dialogs::hide(string const & name, Inset* inset)
89 // Don't send the signal if we are quitting, because on MSVC it is
90 // destructed before the cut stack in CutAndPaste.cpp, and this method
91 // is called from some inset destructor if the cut stack is not empty
96 std::map<string, DialogPtr>::const_iterator it =
98 if (it == dialogs_.end())
101 if (inset && inset != getOpenInset(name))
104 Dialog * const dialog = it->second.get();
105 if (dialog->isVisibleView())
107 open_insets_[name] = 0;
111 void Dialogs::disconnect(string const & name)
113 if (!isValidName(name))
116 if (open_insets_.find(name) != open_insets_.end())
117 open_insets_[name] = 0;
121 Inset * Dialogs::getOpenInset(string const & name) const
123 if (!isValidName(name))
126 std::map<string, Inset *>::const_iterator it =
127 open_insets_.find(name);
128 return it == open_insets_.end() ? 0 : it->second;
132 void Dialogs::hideAll() const
134 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
135 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
137 for(; it != end; ++it)
142 void Dialogs::hideBufferDependent() const
144 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
145 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
147 for(; it != end; ++it) {
148 Dialog * dialog = it->second.get();
149 if (dialog->isBufferDependent())
155 void Dialogs::updateBufferDependent(bool switched) const
157 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
158 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
160 for(; it != end; ++it) {
161 Dialog * dialog = it->second.get();
162 if (switched && dialog->isBufferDependent()) {
163 if (dialog->isVisibleView() && dialog->initialiseParams(""))
164 dialog->updateView();
168 // A bit clunky, but the dialog will request
169 // that the kernel provides it with the necessary
171 dialog->slotRestore();
177 void Dialogs::redraw() const
179 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
180 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
182 for(; it != end; ++it)
183 it->second->redraw();
187 void Dialogs::checkStatus()
189 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
190 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
192 for(; it != end; ++it) {
193 Dialog * const dialog = it->second.get();
194 if (dialog && dialog->isVisibleView())
195 dialog->checkStatus();
199 } // namespace frontend