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
16 #include "controllers/Dialog.h"
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 =
70 if (it == dialogs_.end())
72 return it->second.get()->isVisibleView();
76 void Dialogs::update(string const & name, string const & data)
78 std::map<string, DialogPtr>::const_iterator it =
80 if (it == dialogs_.end())
83 Dialog * const dialog = it->second.get();
84 if (dialog->isVisibleView())
85 dialog->updateData(data);
89 void Dialogs::hide(string const & name, Inset* inset)
91 // Don't send the signal if we are quitting, because on MSVC it is
92 // destructed before the cut stack in CutAndPaste.cpp, and this method
93 // is called from some inset destructor if the cut stack is not empty
98 std::map<string, DialogPtr>::const_iterator it =
100 if (it == dialogs_.end())
103 if (inset && inset != getOpenInset(name))
106 Dialog * const dialog = it->second.get();
107 if (dialog->isVisibleView())
109 open_insets_[name] = 0;
113 void Dialogs::disconnect(string const & name)
115 if (!isValidName(name))
118 if (open_insets_.find(name) != open_insets_.end())
119 open_insets_[name] = 0;
123 Inset * Dialogs::getOpenInset(string const & name) const
125 if (!isValidName(name))
128 std::map<string, Inset *>::const_iterator it =
129 open_insets_.find(name);
130 return it == open_insets_.end() ? 0 : it->second;
134 void Dialogs::hideAll() const
136 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
137 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
139 for(; it != end; ++it)
144 void Dialogs::hideBufferDependent() const
146 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
147 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
149 for(; it != end; ++it) {
150 Dialog * dialog = it->second.get();
151 if (dialog->controller().isBufferDependent())
157 void Dialogs::updateBufferDependent(bool switched) const
159 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
160 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
162 for(; it != end; ++it) {
163 Dialog * dialog = it->second.get();
164 if (switched && dialog->controller().isBufferDependent()) {
165 if (dialog->isVisibleView() && dialog->controller().initialiseParams(""))
166 dialog->updateView();
170 // A bit clunky, but the dialog will request
171 // that the kernel provides it with the necessary
173 dialog->slotRestore();
179 void Dialogs::redraw() const
181 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
182 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
184 for(; it != end; ++it)
185 it->second->redraw();
189 void Dialogs::checkStatus()
191 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
192 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
194 for(; it != end; ++it) {
195 Dialog * const dialog = it->second.get();
196 if (dialog && dialog->isVisibleView())
197 dialog->checkStatus();
201 } // namespace frontend