]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Dialogs.C
This new citation dialog follows a new design similar to lyx-1.3:
[lyx.git] / src / frontends / qt4 / Dialogs.C
1 /**
2  * \file qt2/Dialogs.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Dialogs.h"
14
15 #include "ControlAboutlyx.h"
16 #include "ControlBibtex.h"
17 #include "ControlBox.h"
18 #include "ControlBranch.h"
19 #include "ControlChanges.h"
20 #include "ControlCharacter.h"
21 #include "ControlCitation.h"
22 #include "ControlDocument.h"
23 #include "ControlErrorList.h"
24 #include "ControlERT.h"
25 #include "ControlExternal.h"
26 #include "ControlFloat.h"
27 #include "ControlGraphics.h"
28 #include "ControlInclude.h"
29 #include "ControlLog.h"
30 #include "ControlMath.h"
31 #include "ControlNote.h"
32 #include "ControlParagraph.h"
33 #include "ControlPrefs.h"
34 #include "ControlPrint.h"
35 #include "ControlRef.h"
36 #include "ControlSearch.h"
37 #include "ControlSendto.h"
38 #include "ControlShowFile.h"
39 #include "ControlSpellchecker.h"
40 #include "ControlTabular.h"
41 #include "ControlTabularCreate.h"
42 #include "ControlToc.h"
43 #include "ControlVSpace.h"
44 #include "ControlWrap.h"
45
46 #include "Qt2BC.h"
47 #include "ButtonController.h"
48 #include "QAbout.h"
49 #include "QBibitem.h"
50 #include "QBibtex.h"
51 #include "QBox.h"
52 #include "QBranch.h"
53 #include "QChanges.h"
54 #include "QCharacter.h"
55 #include "QCitation.h"
56 #include "QDocument.h"
57 #include "QErrorList.h"
58 #include "QERT.h"
59 #include "QExternal.h"
60 #include "QFloat.h"
61 // Here would be an appropriate point to lecture on the evils
62 // of the Qt headers, those most fucked up of disgusting ratholes.
63 // But I won't.
64 #undef signals
65 #include "QGraphics.h"
66 #include "QInclude.h"
67 #include "QIndex.h"
68 #include "QLog.h"
69 #include "QMath.h"
70 #include "QNote.h"
71 #include "QParagraph.h"
72 #include "QPrefs.h"
73 #include "QPrint.h"
74 #include "QRef.h"
75 #include "QSearch.h"
76 #include "QSendto.h"
77 #include "QShowFile.h"
78 #include "QSpellchecker.h"
79 #include "QTabular.h"
80 #include "QTabularCreate.h"
81 #include "QTexinfo.h"
82 #include "QToc.h"
83 #include "q3url.h"
84 #include "QVSpace.h"
85 #include "QWrap.h"
86
87 #ifdef HAVE_LIBAIKSAURUS
88 #include "ControlThesaurus.h"
89 #include "QThesaurus.h"
90 #endif
91
92 #include "qt_helpers.h"
93 #include "QURL.h"
94
95 #include <boost/assert.hpp>
96
97 using std::string;
98
99 using namespace lyx::frontend;
100
101 namespace {
102
103 char const * const dialognames[] = {
104 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
105 "citation", "document", "errorlist", "ert", "external", "file",
106 "findreplace", "float", "graphics", "include", "index", "label", "log",
107 "mathpanel", "mathdelimiter", "mathmatrix", "note", "paragraph", "preamble",
108 "prefs", "print", "ref", "sendto", "spellchecker","tabular", "tabularcreate",
109
110 #ifdef HAVE_LIBAIKSAURUS
111 "thesaurus",
112 #endif
113
114 "texinfo", "toc", "url", "vspace", "wrap" };
115
116 char const * const * const end_dialognames =
117         dialognames + (sizeof(dialognames) / sizeof(char *));
118
119 class cmpCStr {
120 public:
121         cmpCStr(char const * name) : name_(name) {}
122         bool operator()(char const * other) {
123                 return strcmp(other, name_) == 0;
124         }
125 private:
126         char const * name_;
127 };
128
129
130 } // namespace anon
131
132
133 bool Dialogs::isValidName(string const & name) const
134 {
135         return std::find_if(dialognames, end_dialognames,
136                             cmpCStr(name.c_str())) != end_dialognames;
137 }
138
139
140 Dialogs::DialogPtr Dialogs::build(string const & name)
141 {
142         BOOST_ASSERT(isValidName(name));
143
144         DialogPtr dialog(new Dialog(lyxview_, name));
145         dialog->bc().view(new Qt2BC(dialog->bc()));
146
147         if (name == "aboutlyx") {
148                 dialog->setController(new ControlAboutlyx(*dialog));
149                 dialog->setView(new QAbout(*dialog));
150                 dialog->bc().bp(new OkCancelPolicy);
151         } else if (name == "bibitem") {
152                 dialog->setController(new ControlCommand(*dialog, name));
153                 dialog->setView(new QBibitem(*dialog));
154                 dialog->bc().bp(new OkCancelReadOnlyPolicy);
155         } else if (name == "bibtex") {
156                 dialog->setController(new ControlBibtex(*dialog));
157                 dialog->setView(new QBibtex(*dialog));
158                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
159         } else if (name == "box") {
160                 dialog->setController(new ControlBox(*dialog));
161                 dialog->setView(new QBox(*dialog));
162                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
163         } else if (name == "branch") {
164                 dialog->setController(new ControlBranch(*dialog));
165                 dialog->setView(new QBranch(*dialog));
166                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
167         } else if (name == "changes") {
168                 dialog->setController(new ControlChanges(*dialog));
169                 dialog->setView(new QChanges(*dialog));
170                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
171         } else if (name == "character") {
172                 dialog->setController(new ControlCharacter(*dialog));
173                 dialog->setView(new QCharacter(*dialog));
174                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
175         } else if (name == "citation") {
176                 dialog->setController(new ControlCitation(*dialog));
177                 dialog->setView(new QCitation(*dialog));
178                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
179         } else if (name == "document" || name == "preamble") {
180
181                 // This nastiness will exist only as long as xforms
182                 // has a separate preamble dialog.
183
184                 string const other = (name == "document") ?
185                         "preamble" : "document";
186
187                 std::map<string, DialogPtr>::iterator it =
188                         dialogs_.find(other);
189
190                 if (it != dialogs_.end())
191                         dialog = it->second;
192                 else {
193                         dialog->setController(new ControlDocument(*dialog));
194                         dialog->setView(new QDocument(*dialog));
195                         dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
196                 }
197
198         } else if (name == "errorlist") {
199                 dialog->setController(new ControlErrorList(*dialog));
200                 dialog->setView(new QErrorList(*dialog));
201                 dialog->bc().bp(new OkCancelPolicy);
202         } else if (name == "ert") {
203                 dialog->setController(new ControlERT(*dialog));
204                 dialog->setView(new QERT(*dialog));
205                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
206         } else if (name == "external") {
207                 dialog->setController(new ControlExternal(*dialog));
208                 dialog->setView(new QExternal(*dialog));
209                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
210         } else if (name == "file") {
211                 dialog->setController(new ControlShowFile(*dialog));
212                 dialog->setView(new QShowFile(*dialog));
213                 dialog->bc().bp(new OkCancelPolicy);
214         } else if (name == "findreplace") {
215                 dialog->setController(new ControlSearch(*dialog));
216                 dialog->setView(new QSearch(*dialog));
217                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
218         } else if (name == "float") {
219                 dialog->setController(new ControlFloat(*dialog));
220                 dialog->setView(new QFloat(*dialog));
221                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
222         } else if (name == "graphics") {
223                 dialog->setController(new ControlGraphics(*dialog));
224                 dialog->setView(new QGraphics(*dialog));
225                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
226         } else if (name == "include") {
227                 dialog->setController(new ControlInclude(*dialog));
228                 dialog->setView(new QInclude(*dialog));
229                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
230         } else if (name == "index") {
231                 dialog->setController(new ControlCommand(*dialog, name));
232                 dialog->setView(new QIndex(*dialog,
233                                            _("Index Entry"),
234                                            qt_("&Keyword:")));
235                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
236         } else if (name == "label") {
237                 dialog->setController(new ControlCommand(*dialog, name));
238                 dialog->setView(new QIndex(*dialog,
239                                            _("Label"),
240                                            qt_("&Label:")));
241                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
242         } else if (name == "log") {
243                 dialog->setController(new ControlLog(*dialog));
244                 dialog->setView(new QLog(*dialog));
245                 dialog->bc().bp(new OkCancelPolicy);
246         } else if (name == "mathpanel") {
247                 dialog->setController(new ControlMath(*dialog));
248                 dialog->setView(new QMath(*dialog));
249                 dialog->bc().bp(new IgnorantPolicy);
250         } else if (name == "mathdelimiter") {
251                 dialog->setController(new ControlMath(*dialog));
252                 dialog->setView(new QMathDelimiter(*dialog));
253                 dialog->bc().bp(new IgnorantPolicy);
254         } else if (name == "mathmatrix") {
255                 dialog->setController(new ControlMath(*dialog));
256                 dialog->setView(new QMathMatrix(*dialog));
257                 dialog->bc().bp(new IgnorantPolicy);
258         } else if (name == "note") {
259                 dialog->setController(new ControlNote(*dialog));
260                 dialog->setView(new QNote(*dialog));
261                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
262         } else if (name == "paragraph") {
263                 dialog->setController(new ControlParagraph(*dialog));
264                 dialog->setView(new QParagraph(*dialog));
265                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
266         } else if (name == "prefs") {
267                 dialog->setController(new ControlPrefs(*dialog));
268                 dialog->setView(new QPrefs(*dialog));
269                 dialog->bc().bp(new PreferencesPolicy);
270         } else if (name == "print") {
271                 dialog->setController(new ControlPrint(*dialog));
272                 dialog->setView(new QPrint(*dialog));
273                 dialog->bc().bp(new OkApplyCancelPolicy);
274         } else if (name == "ref") {
275                 dialog->setController(new ControlRef(*dialog));
276                 dialog->setView(new QRef(*dialog));
277                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
278         } else if (name == "sendto") {
279                 dialog->setController(new ControlSendto(*dialog));
280                 dialog->setView(new QSendto(*dialog));
281                 dialog->bc().bp(new OkApplyCancelPolicy);
282         } else if (name == "spellchecker") {
283                 dialog->setController(new ControlSpellchecker(*dialog));
284                 dialog->setView(new QSpellchecker(*dialog));
285                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
286         } else if (name == "tabular") {
287                 dialog->setController(new ControlTabular(*dialog));
288                 dialog->setView(new QTabular(*dialog));
289                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
290         } else if (name == "tabularcreate") {
291                 dialog->setController(new ControlTabularCreate(*dialog));
292                 dialog->setView(new QTabularCreate(*dialog));
293                 dialog->bc().bp(new IgnorantPolicy);
294         } else if (name == "texinfo") {
295                 dialog->setController(new ControlTexinfo(*dialog));
296                 dialog->setView(new QTexinfo(*dialog));
297                 dialog->bc().bp(new OkCancelPolicy);
298 #ifdef HAVE_LIBAIKSAURUS
299         } else if (name == "thesaurus") {
300                 dialog->setController(new ControlThesaurus(*dialog));
301                 dialog->setView(new QThesaurus(*dialog));
302                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
303 #endif
304         } else if (name == "toc") {
305                 dialog->setController(new ControlToc(*dialog));
306                 dialog->setView(new QToc(*dialog));
307                 dialog->bc().bp(new OkCancelPolicy);
308         } else if (name == "url") {
309                 dialog->setController(new ControlCommand(*dialog, name));
310                 dialog->setView(new QURL(*dialog));
311                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
312         } else if (name == "vspace") {
313                 dialog->setController(new ControlVSpace(*dialog));
314                 dialog->setView(new QVSpace(*dialog));
315                 dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
316         } else if (name == "wrap") {
317                 dialog->setController(new ControlWrap(*dialog));
318                 dialog->setView(new QWrap(*dialog));
319                 dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
320         }
321
322         return dialog;
323 }
324
325
326 void Dialogs::toggleTooltips()
327 {}
328
329
330 /// Are the tooltips on or off?
331 bool Dialogs::tooltipsEnabled()
332 {
333         return false;
334 }