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>
30 Dialogs::Dialogs(LyXView & lyxview)
31 : lyxview_(lyxview), in_show_(false)
35 Dialog * Dialogs::find_or_build(string const & name)
37 if (!isValidName(name))
40 std::map<string, DialogPtr>::iterator it =
43 if (it != dialogs_.end())
44 return it->second.get();
46 dialogs_[name].reset(build(name));
47 return dialogs_[name].get();
51 void Dialogs::show(string const & name, string const & data, Inset * inset)
57 Dialog * dialog = find_or_build(name);
59 dialog->showData(data);
61 open_insets_[name] = inset;
67 bool Dialogs::visible(string const & name) const
69 std::map<string, DialogPtr>::const_iterator it =
71 if (it == dialogs_.end())
73 return it->second.get()->isVisibleView();
77 void Dialogs::update(string const & name, string const & data)
79 std::map<string, DialogPtr>::const_iterator it =
81 if (it == dialogs_.end())
84 Dialog * const dialog = it->second.get();
85 if (dialog->isVisibleView())
86 dialog->updateData(data);
90 void Dialogs::hide(string const & name, Inset* inset)
92 // Don't send the signal if we are quitting, because on MSVC it is
93 // destructed before the cut stack in CutAndPaste.cpp, and this method
94 // is called from some inset destructor if the cut stack is not empty
99 std::map<string, DialogPtr>::const_iterator it =
101 if (it == dialogs_.end())
104 if (inset && inset != getOpenInset(name))
107 Dialog * const dialog = it->second.get();
108 if (dialog->isVisibleView())
110 open_insets_[name] = 0;
114 void Dialogs::disconnect(string const & name)
116 if (!isValidName(name))
119 if (open_insets_.find(name) != open_insets_.end())
120 open_insets_[name] = 0;
124 Inset * Dialogs::getOpenInset(string const & name) const
126 if (!isValidName(name))
129 std::map<string, Inset *>::const_iterator it =
130 open_insets_.find(name);
131 return it == open_insets_.end() ? 0 : it->second;
135 void Dialogs::hideAll() const
137 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
138 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
140 for(; it != end; ++it)
145 void Dialogs::hideBufferDependent() const
147 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
148 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
150 for(; it != end; ++it) {
151 Dialog * dialog = it->second.get();
152 if (dialog->controller().isBufferDependent())
158 void Dialogs::updateBufferDependent(bool switched) const
160 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
161 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
163 for(; it != end; ++it) {
164 Dialog * dialog = it->second.get();
165 if (switched && dialog->controller().isBufferDependent()) {
166 if (dialog->isVisibleView() && dialog->controller().initialiseParams(""))
167 dialog->updateView();
171 // A bit clunky, but the dialog will request
172 // that the kernel provides it with the necessary
174 dialog->slotRestore();
180 void Dialogs::redraw() const
182 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
183 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
185 for(; it != end; ++it)
186 it->second->redraw();
190 void Dialogs::checkStatus()
192 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
193 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
195 for(; it != end; ++it) {
196 Dialog * const dialog = it->second.get();
197 if (dialog->isVisibleView())
198 dialog->checkStatus();
202 } // namespace frontend