2 * \file qt4/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.
16 #include <boost/assert.hpp>
26 Dialogs::Dialogs(LyXView & lyxview)
27 : lyxview_(lyxview), in_show_(false)
31 Dialog * Dialogs::find_or_build(string const & name)
33 if (!isValidName(name))
36 std::map<string, DialogPtr>::iterator it =
39 if (it != dialogs_.end())
40 return it->second.get();
42 dialogs_[name].reset(build(name));
43 return dialogs_[name].get();
47 void Dialogs::show(string const & name, string const & data, Inset * inset)
53 Dialog * dialog = find_or_build(name);
55 dialog->showData(data);
57 open_insets_[name] = inset;
63 bool Dialogs::visible(string const & name) const
65 std::map<string, DialogPtr>::const_iterator it = dialogs_.find(name);
66 if (it == dialogs_.end())
68 return it->second.get()->isVisibleView();
72 void Dialogs::update(string const & name, string const & data)
74 std::map<string, DialogPtr>::const_iterator it = dialogs_.find(name);
75 if (it == dialogs_.end())
78 Dialog * const dialog = it->second.get();
79 if (dialog->isVisibleView())
80 dialog->updateData(data);
84 void Dialogs::hide(string const & name, Inset* inset)
86 // Don't send the signal if we are quitting, because on MSVC it is
87 // destructed before the cut stack in CutAndPaste.cpp, and this method
88 // is called from some inset destructor if the cut stack is not empty
93 std::map<string, DialogPtr>::const_iterator it =
95 if (it == dialogs_.end())
98 if (inset && inset != getOpenInset(name))
101 Dialog * const dialog = it->second.get();
102 if (dialog->isVisibleView())
104 open_insets_[name] = 0;
108 void Dialogs::disconnect(string const & name)
110 if (!isValidName(name))
113 if (open_insets_.find(name) != open_insets_.end())
114 open_insets_[name] = 0;
118 Inset * Dialogs::getOpenInset(string const & name) const
120 if (!isValidName(name))
123 std::map<string, Inset *>::const_iterator it =
124 open_insets_.find(name);
125 return it == open_insets_.end() ? 0 : it->second;
129 void Dialogs::hideAll() const
131 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
132 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
134 for(; it != end; ++it)
139 void Dialogs::hideBufferDependent() const
141 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
142 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
144 for(; it != end; ++it) {
145 Dialog * dialog = it->second.get();
146 if (dialog->isBufferDependent())
152 void Dialogs::updateBufferDependent(bool switched) 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) {
158 Dialog * dialog = it->second.get();
159 if (switched && dialog->isBufferDependent()) {
160 if (dialog->isVisibleView() && dialog->initialiseParams(""))
161 dialog->updateView();
165 // A bit clunky, but the dialog will request
166 // that the kernel provides it with the necessary
168 dialog->slotRestore();
174 void Dialogs::redraw() const
176 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
177 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
179 for(; it != end; ++it)
180 it->second->redraw();
184 void Dialogs::checkStatus()
186 std::map<string, DialogPtr>::const_iterator it = dialogs_.begin();
187 std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
189 for(; it != end; ++it) {
190 Dialog * const dialog = it->second.get();
191 if (dialog && dialog->isVisibleView())
192 dialog->checkStatus();
199 // This list should be kept in sync with the list of insets in
200 // src/insets/Inset.cpp. I.e., if a dialog goes with an inset, the
201 // dialog should have the same name as the inset.
203 char const * const dialognames[] = {
204 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
205 "citation", "document", "embedding", "errorlist", "ert", "external", "file",
206 "findreplace", "float", "graphics", "include", "index", "nomenclature", "label", "log",
207 "mathdelimiter", "mathmatrix", "note", "paragraph",
208 "prefs", "print", "ref", "sendto", "spellchecker","tabular", "tabularcreate",
210 #ifdef HAVE_LIBAIKSAURUS
214 "texinfo", "toc", "href", "view-source", "vspace", "wrap", "listings" };
216 char const * const * const end_dialognames =
217 dialognames + (sizeof(dialognames) / sizeof(char *));
221 cmpCStr(char const * name) : name_(name) {}
222 bool operator()(char const * other) {
223 return strcmp(other, name_) == 0;
232 // will be replaced by a proper factory...
233 Dialog * createGuiAbout(LyXView & lv);
234 Dialog * createGuiBibitem(LyXView & lv);
235 Dialog * createGuiBibtex(LyXView & lv);
236 Dialog * createGuiBox(LyXView & lv);
237 Dialog * createGuiBranch(LyXView & lv);
238 Dialog * createGuiChanges(LyXView & lv);
239 Dialog * createGuiCharacter(LyXView & lv);
240 Dialog * createGuiCitation(LyXView & lv);
241 Dialog * createGuiDelimiter(LyXView & lv);
242 Dialog * createGuiDocument(LyXView & lv);
243 Dialog * createGuiErrorList(LyXView & lv);
244 Dialog * createGuiERT(LyXView & lv);
245 Dialog * createGuiExternal(LyXView & lv);
246 Dialog * createGuiFloat(LyXView & lv);
247 Dialog * createGuiGraphics(LyXView & lv);
248 Dialog * createGuiInclude(LyXView & lv);
249 Dialog * createGuiIndex(LyXView & lv);
250 Dialog * createGuiLabel(LyXView & lv);
251 Dialog * createGuiListings(LyXView & lv);
252 Dialog * createGuiLog(LyXView & lv);
253 Dialog * createGuiMathMatrix(LyXView & lv);
254 Dialog * createGuiNomenclature(LyXView & lv);
255 Dialog * createGuiNote(LyXView & lv);
256 Dialog * createGuiParagraph(LyXView & lv);
257 Dialog * createGuiPreferences(LyXView & lv);
258 Dialog * createGuiPrint(LyXView & lv);
259 Dialog * createGuiRef(LyXView & lv);
260 Dialog * createGuiSearch(LyXView & lv);
261 Dialog * createGuiSendTo(LyXView & lv);
262 Dialog * createGuiShowFile(LyXView & lv);
263 Dialog * createGuiSpellchecker(LyXView & lv);
264 Dialog * createGuiTabularCreate(LyXView & lv);
265 Dialog * createGuiTabular(LyXView & lv);
266 Dialog * createGuiTexInfo(LyXView & lv);
267 Dialog * createGuiToc(LyXView & lv);
268 Dialog * createGuiThesaurus(LyXView & lv);
269 Dialog * createGuiHyperlink(LyXView & lv);
270 Dialog * createGuiVSpace(LyXView & lv);
271 Dialog * createGuiViewSource(LyXView & lv);
272 Dialog * createGuiWrap(LyXView & lv);
275 bool Dialogs::isValidName(string const & name) const
277 return std::find_if(dialognames, end_dialognames,
278 cmpCStr(name.c_str())) != end_dialognames;
282 Dialog * Dialogs::build(string const & name)
284 BOOST_ASSERT(isValidName(name));
286 if (name == "aboutlyx")
287 return createGuiAbout(lyxview_);
288 if (name == "bibitem")
289 return createGuiBibitem(lyxview_);
290 if (name == "bibtex")
291 return createGuiBibtex(lyxview_);
293 return createGuiBox(lyxview_);
294 if (name == "branch")
295 return createGuiBranch(lyxview_);
296 if (name == "changes")
297 return createGuiChanges(lyxview_);
298 if (name == "character")
299 return createGuiCharacter(lyxview_);
300 if (name == "citation")
301 return createGuiCitation(lyxview_);
302 if (name == "document")
303 return createGuiDocument(lyxview_);
304 if (name == "errorlist")
305 return createGuiErrorList(lyxview_);
307 return createGuiERT(lyxview_);
308 if (name == "external")
309 return createGuiExternal(lyxview_);
311 return createGuiShowFile(lyxview_);
312 if (name == "findreplace")
313 return createGuiSearch(lyxview_);
315 return createGuiFloat(lyxview_);
316 if (name == "graphics")
317 return createGuiGraphics(lyxview_);
318 if (name == "include")
319 return createGuiInclude(lyxview_);
321 return createGuiIndex(lyxview_);
322 if (name == "nomenclature")
323 return createGuiNomenclature(lyxview_);
325 return createGuiLabel(lyxview_);
327 return createGuiLog(lyxview_);
328 if (name == "view-source")
329 return createGuiViewSource(lyxview_);
330 if (name == "mathdelimiter")
331 return createGuiDelimiter(lyxview_);
332 if (name == "mathmatrix")
333 return createGuiMathMatrix(lyxview_);
335 return createGuiNote(lyxview_);
336 if (name == "paragraph")
337 return createGuiParagraph(lyxview_);
339 return createGuiPreferences(lyxview_);
341 return createGuiPrint(lyxview_);
343 return createGuiRef(lyxview_);
344 if (name == "sendto")
345 return createGuiSendTo(lyxview_);
346 if (name == "spellchecker")
347 return createGuiSpellchecker(lyxview_);
348 if (name == "tabular")
349 return createGuiTabular(lyxview_);
350 if (name == "tabularcreate")
351 return createGuiTabularCreate(lyxview_);
352 if (name == "texinfo")
353 return createGuiTexInfo(lyxview_);
354 #ifdef HAVE_LIBAIKSAURUS
355 if (name == "thesaurus")
356 return createGuiThesaurus(lyxview_);
359 return createGuiToc(lyxview_);
361 return createGuiHyperlink(lyxview_);
362 if (name == "vspace")
363 return createGuiVSpace(lyxview_);
365 return createGuiWrap(lyxview_);
366 if (name == "listings")
367 return createGuiListings(lyxview_);
373 /// Are the tooltips on or off?
374 bool Dialogs::tooltipsEnabled()
379 } // namespace frontend