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
19 #include "controllers/Dialog.h"
21 #include <boost/signal.hpp>
22 #include <boost/bind.hpp>
28 using lyx::frontend::Dialog;
31 Dialogs::Dialogs(LyXView & lyxview)
32 : lyxview_(lyxview), in_show_(false)
37 Dialog * Dialogs::find_or_build(string const & name)
39 if (!isValidName(name))
42 std::map<string, DialogPtr>::iterator it =
45 if (it != dialogs_.end())
46 return it->second.get();
48 dialogs_[name] = build(name);
49 return dialogs_[name].get();
53 void Dialogs::show(string const & name, string const & data)
59 Dialog * dialog = find_or_build(name);
61 // FIXME! Should check that the dialog is NOT an inset dialog.
68 void Dialogs::show(string const & name, string const & data, Inset * inset)
74 Dialog * dialog = find_or_build(name);
76 // FIXME! Should check that the dialog IS an inset dialog.
78 open_insets_[name] = inset;
84 bool Dialogs::visible(string const & name) const
86 std::map<string, DialogPtr>::const_iterator it =
88 if (it == dialogs_.end())
90 return it->second.get()->isVisible();
94 void Dialogs::update(string const & name, string const & data)
96 std::map<string, DialogPtr>::const_iterator it =
98 if (it == dialogs_.end())
101 Dialog * const dialog = it->second.get();
102 if (dialog->isVisible())
103 dialog->update(data);
107 void Dialogs::hide(string const & name, Inset* inset)
109 // Don't send the signal if we are quitting, because on MSVC it is
110 // destructed before the cut stack in CutAndPaste.cpp, and this method
111 // is called from some inset destructor if the cut stack is not empty
116 std::map<string, DialogPtr>::const_iterator it =
118 if (it == dialogs_.end())
121 if (inset && inset != getOpenInset(name))
124 Dialog * const dialog = it->second.get();
125 if (dialog->isVisible())
127 open_insets_[name] = 0;
131 void Dialogs::disconnect(string const & name)
133 if (!isValidName(name))
136 if (open_insets_.find(name) != open_insets_.end())
137 open_insets_[name] = 0;
141 Inset * Dialogs::getOpenInset(string const & name) const
143 if (!isValidName(name))
146 std::map<string, Inset *>::const_iterator it =
147 open_insets_.find(name);
148 return it == open_insets_.end() ? 0 : it->second;
152 void Dialogs::hideAll() const
154 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
155 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
157 for(; it != end; ++it) {
163 void Dialogs::hideBufferDependent() const
165 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
166 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
168 for(; it != end; ++it) {
169 Dialog * dialog = it->second.get();
170 if (dialog->controller().isBufferDependent())
176 void Dialogs::updateBufferDependent(bool switched) const
178 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
179 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
181 for(; it != end; ++it) {
182 Dialog * dialog = it->second.get();
183 if (switched && dialog->controller().isBufferDependent()) {
184 if (dialog->isVisible() && dialog->controller().initialiseParams(""))
185 dialog->view().update();
189 // A bit clunky, but the dialog will request
190 // that the kernel provides it with the necessary
192 dialog->RestoreButton();
198 void Dialogs::redraw() 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 it->second->redraw();
209 void Dialogs::checkStatus()
211 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
212 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
214 for(; it != end; ++it) {
215 Dialog * const dialog = it->second.get();
216 if (dialog->isVisible())
217 dialog->checkStatus();