]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Dialogs.cpp
next one
[lyx.git] / src / frontends / qt4 / Dialogs.cpp
1 /**
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.
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 #include "GuiDialog.h"
15
16 #include "ButtonController.h"
17 #include "DialogView.h"
18 #include "DockView.h"
19 #include "GuiAbout.h"
20 #include "GuiBibitem.h"
21 #include "GuiBibtex.h"
22 #include "GuiBox.h"
23 #include "GuiBranch.h"
24 #include "GuiChanges.h"
25 #include "GuiCharacter.h"
26 #include "GuiCitation.h"
27 #include "GuiDelimiter.h"
28 #include "GuiDocument.h"
29 #include "GuiEmbeddedFiles.h"
30 #include "GuiErrorList.h"
31 #include "GuiExternal.h"
32 #include "GuiGraphics.h"
33 #include "GuiInclude.h"
34 #include "GuiIndex.h"
35 #include "GuiMathMatrix.h"
36 #include "GuiNomencl.h"
37 #include "GuiLog.h"
38 #include "GuiParagraph.h"
39 #include "GuiPrefs.h"
40 #include "GuiPrint.h"
41 #include "GuiSearch.h"
42 #include "GuiSendto.h"
43 #include "GuiShowFile.h"
44 #include "GuiSpellchecker.h"
45 #include "GuiTabular.h"
46 #include "GuiTabularCreate.h"
47 #include "GuiTexinfo.h"
48 #include "GuiToc.h"
49 #include "GuiView.h"
50 #include "GuiViewSource.h"
51 #include "TocWidget.h"
52 #include "GuiURL.h"
53
54 #ifdef HAVE_LIBAIKSAURUS
55 #include "ControlThesaurus.h"
56 #include "GuiThesaurus.h"
57 #endif
58
59 // Uncomment this if you prefer dock widget
60 //#define USE_DOCK_WIDGET
61
62 #include "qt_helpers.h"
63
64 #include <boost/assert.hpp>
65
66 using std::string;
67
68 namespace lyx {
69 namespace frontend {
70
71 namespace {
72
73 // This list should be kept in sync with the list of insets in
74 // src/insets/Inset.cpp.  I.e., if a dialog goes with an inset, the
75 // dialog should have the same name as the inset.
76
77 char const * const dialognames[] = {
78 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
79 "citation", "document", "embedding", "errorlist", "ert", "external", "file",
80 "findreplace", "float", "graphics", "include", "index", "nomenclature", "label", "log",
81 "mathdelimiter", "mathmatrix", "note", "paragraph",
82 "prefs", "print", "ref", "sendto", "spellchecker","tabular", "tabularcreate",
83
84 #ifdef HAVE_LIBAIKSAURUS
85 "thesaurus",
86 #endif
87
88 "texinfo", "toc", "url", "view-source", "vspace", "wrap", "listings" };
89
90 char const * const * const end_dialognames =
91         dialognames + (sizeof(dialognames) / sizeof(char *));
92
93 class cmpCStr {
94 public:
95         cmpCStr(char const * name) : name_(name) {}
96         bool operator()(char const * other) {
97                 return strcmp(other, name_) == 0;
98         }
99 private:
100         char const * name_;
101 };
102
103
104 } // namespace anon
105
106 // will be replaced by a proper factory...
107 Dialog * createGuiAbout(LyXView & lv);
108 Dialog * createGuiBibitem(LyXView & lv);
109 Dialog * createGuiBibtex(LyXView & lv);
110 Dialog * createGuiBox(LyXView & lv);
111 Dialog * createGuiBranch(LyXView & lv);
112 Dialog * createGuiChanges(LyXView & lv);
113 Dialog * createGuiCharacter(LyXView & lv);
114 Dialog * createGuiCitation(LyXView & lv);
115 Dialog * createGuiDelimiter(LyXView & lv);
116 Dialog * createGuiDocument(LyXView & lv);
117 Dialog * createGuiErrorList(LyXView & lv);
118 Dialog * createGuiERT(LyXView & lv);
119 Dialog * createGuiExternal(LyXView & lv);
120 Dialog * createGuiFloat(LyXView & lv);
121 Dialog * createGuiGraphics(LyXView & lv);
122 Dialog * createGuiInclude(LyXView & lv);
123 Dialog * createGuiIndex(LyXView & lv);
124 Dialog * createGuiLabel(LyXView & lv);
125 Dialog * createGuiListings(LyXView & lv);
126 Dialog * createGuiLog(LyXView & lv);
127 Dialog * createGuiMathMatrix(LyXView & lv);
128 Dialog * createGuiNomencl(LyXView & lv);
129 Dialog * createGuiNote(LyXView & lv);
130 Dialog * createGuiPrefs(LyXView & lv);
131 Dialog * createGuiPrint(LyXView & lv);
132 Dialog * createGuiRef(LyXView & lv);
133 Dialog * createGuiSearch(LyXView & lv);
134 Dialog * createGuiSendto(LyXView & lv);
135 Dialog * createGuiShowFile(LyXView & lv);
136 Dialog * createGuiSpellchecker(LyXView & lv);
137 Dialog * createGuiTabularCreate(LyXView & lv);
138 Dialog * createGuiTabular(LyXView & lv);
139 Dialog * createGuiTexinfo(LyXView & lv);
140 Dialog * createGuiThesaurus(LyXView & lv);
141 Dialog * createGuiURL(LyXView & lv);
142 Dialog * createGuiVSpace(LyXView & lv);
143 Dialog * createGuiWrap(LyXView & lv);
144
145
146 bool Dialogs::isValidName(string const & name) const
147 {
148         return std::find_if(dialognames, end_dialognames,
149                             cmpCStr(name.c_str())) != end_dialognames;
150 }
151
152
153 Dialog * Dialogs::build(string const & name)
154 {
155         BOOST_ASSERT(isValidName(name));
156
157         Dialog * dialog = 0;
158         GuiViewBase & guiview = static_cast<GuiViewBase &>(lyxview_);
159
160         if (name == "aboutlyx") {
161                 dialog = new GuiAboutDialog(lyxview_);
162         } else if (name == "bibitem") {
163                 dialog = new GuiBibitemDialog(lyxview_);
164         } else if (name == "bibtex") {
165                 dialog = new GuiBibtexDialog(lyxview_);
166         } else if (name == "box") {
167                 dialog = new GuiBoxDialog(lyxview_);
168         } else if (name == "branch") {
169                 dialog = new GuiBranchDialog(lyxview_);
170         } else if (name == "changes") {
171                 dialog = new GuiChangesDialog(lyxview_);
172         } else if (name == "character") {
173                 dialog = new GuiCharacterDialog(lyxview_);
174         } else if (name == "citation") {
175                 dialog = new GuiCitationDialog(lyxview_);
176         } else if (name == "document") {
177                 dialog = new GuiDocumentDialog(lyxview_);
178         } else if (name == "embedding") {
179                 dialog = new DockView<ControlEmbeddedFiles, GuiEmbeddedFilesDialog>(
180                         guiview, name, Qt::RightDockWidgetArea);
181         } else if (name == "errorlist") {
182                 dialog = new GuiErrorListDialog(lyxview_);
183         } else if (name == "ert") {
184                 dialog = createGuiERT(lyxview_);
185         } else if (name == "external") {
186                 dialog = new GuiExternalDialog(lyxview_);
187         } else if (name == "file") {
188                 dialog = new GuiShowFileDialog(lyxview_);
189         } else if (name == "findreplace") {
190                 dialog = new GuiSearchDialog(lyxview_);
191         } else if (name == "float") {
192                 dialog = createGuiFloat(lyxview_);
193         } else if (name == "graphics") {
194                 dialog = new GuiGraphicsDialog(lyxview_);
195         } else if (name == "include") {
196                 dialog = new GuiIncludeDialog(lyxview_);
197         } else if (name == "index") {
198                 dialog = new GuiIndexDialog(lyxview_);
199         } else if (name == "nomenclature") {
200                 dialog = new GuiNomenclDialog(lyxview_);
201         } else if (name == "label") {
202                 dialog = new GuiLabelDialog(lyxview_);
203         } else if (name == "log") {
204                 dialog = new GuiLogDialog(lyxview_);
205         } else if (name == "view-source") {
206                 dialog = new DockView<ControlViewSource, GuiViewSourceDialog>(
207                         guiview, name, Qt::BottomDockWidgetArea);
208         } else if (name == "mathdelimiter") {
209                 dialog = new GuiDelimiterDialog(lyxview_);
210         } else if (name == "mathmatrix") {
211                 dialog = new GuiMathMatrixDialog(lyxview_);
212         } else if (name == "note") {
213                 dialog = createGuiNote(lyxview_);
214         } else if (name == "paragraph") {
215 #ifdef USE_DOCK_WIDGET
216                 DockView<ControlParagraph, GuiParagraph> * dv =
217                         new DockView<ControlParagraph, GuiParagraph>(guiview, name,
218                                 Qt::TopDockWidgetArea);
219 #else
220                 DialogView<ControlParagraph, GuiParagraph> * dv =
221                         new DialogView<ControlParagraph, GuiParagraph>(guiview, name);
222 #endif
223                 dialog = dv;
224         } else if (name == "prefs") {
225                 dialog = new GuiPrefsDialog(lyxview_);
226         } else if (name == "print") {
227                 dialog = new GuiPrintDialog(lyxview_);
228         } else if (name == "ref") {
229                 dialog = createGuiRef(lyxview_);
230         } else if (name == "sendto") {
231                 dialog = new GuiSendtoDialog(lyxview_);
232         } else if (name == "spellchecker") {
233                 dialog = new GuiSpellcheckerDialog(lyxview_);
234         } else if (name == "tabular") {
235                 dialog = new GuiTabularDialog(lyxview_);
236         } else if (name == "tabularcreate") {
237                 dialog = new GuiTabularCreateDialog(lyxview_);
238         } else if (name == "texinfo") {
239                 dialog = new GuiTexinfoDialog(lyxview_);
240 #ifdef HAVE_LIBAIKSAURUS
241         } else if (name == "thesaurus") {
242                 dialog = new GuiThesaurusDialog(lyxview_);
243 #endif
244         } else if (name == "toc") {
245 #ifdef Q_WS_MACX
246                 // On Mac show as a drawer at the right
247                 dialog = new DockView<GuiToc, TocWidget>(guiview, name,
248                         Qt::RightDockWidgetArea, Qt::Drawer);
249 #else
250                 dialog = new DockView<GuiToc, TocWidget>(guiview, name);
251 #endif
252         } else if (name == "url") {
253                 dialog = new GuiURLDialog(lyxview_);
254         } else if (name == "vspace") {
255                 dialog = createGuiVSpace(lyxview_);
256         } else if (name == "wrap") {
257                 dialog = createGuiWrap(lyxview_);
258         } else if (name == "listings") {
259                 dialog = createGuiListings(lyxview_);
260         }
261
262         return dialog;
263 }
264
265
266 /// Are the tooltips on or off?
267 bool Dialogs::tooltipsEnabled()
268 {
269         return false;
270 }
271
272 } // namespace frontend
273 } // namespace lyx