]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/Dialogs.C
A lean, clean and working start to the new, improved gnome frontend.
[lyx.git] / src / frontends / gnome / Dialogs.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995-2001 The LyX Team.
7  *
8  * ======================================================
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "gettext.h"
18
19 #include "Dialogs.h"
20 #include "LyXView.h"
21 #include "gnomeBC.h"
22 #include "Tooltips.h"
23 #include "GUI.h"
24
25 #include "GUrl.h"
26 #include "GError.h"
27 #include "GTabularCreate.h"
28 #include "GERT.h"
29
30 bool Dialogs::tooltipsEnabled()
31 {
32         return Tooltips::enabled();
33 }
34 Dialogs::Dialogs(LyXView * lv)
35 {
36         add(new GUIUrl<FormUrl, gnomeBC>(*lv, *this));
37         add(new GUIError<FormError, gnomeBC>(*lv, *this));
38         add(new GUITabularCreate<FormTabularCreate, gnomeBC>(*lv, *this));
39         add(new GUIERT<FormERT, gnomeBC>(*lv, *this));
40
41         // reduce the number of connections needed in
42         // dialogs by a simple connection here.
43         hideAll.connect(hideBufferDependent.slot());
44 }
45
46 /*****************************************************************************
47
48 Q.  WHY does Dialogs::Dialogs pass `this' to dialog constructors?
49
50 A.  To avoid a segfault.
51     The dialog constructors need to connect to their
52     respective showSomeDialog signal(*) but in order to do
53     that they need to get the address of the Dialogs instance
54     from LyXView::getDialogs().  However, since the Dialogs
55     instance is still being constructed at that time
56     LyXView::getDialogs() will *not* return the correct
57     address because it hasn't finished being constructed.
58     A Catch-22 situation (or is that the chicken and the egg...).
59     So to get around the problem we pass the address of
60     the newly created Dialogs instance using `this'.
61
62 (*) -- I'm using signals exclusively to guarantee that the gui code
63        remains hidden from the rest of the system.  In fact the only
64        header related to dialogs that anything in the non-gui-specific
65        code gets to see is Dialogs.h!  Even Dialogs.h doesn't know what a
66        FormCopyright class looks like or that its even going to be used!
67
68        No other gui dialog headers are seen outside of the gui-specific
69        directories!  This ensures that the gui is completely separate from
70        the rest of LyX.  All this through the use of a few simple signals.
71        BUT, the price is that during construction we need to connect the
72        implementations show() method to the showSomeDialog signal and this
73        requires that we have an instance of Dialogs and the problem mentioned
74        above.
75
76        Almost all other dialogs should be able to operate using the same style
77        of signalling used for Copyright.  Exceptions should be handled
78        by adding a specific show or update signal.  For example, spellchecker
79        needs to set the next suspect word and its options/replacements so we
80        need a:
81                  Signal0<void> updateSpellChecker;
82
83        Since we would have to have a
84                  Signal0<void> showSpellChecker;
85
86        in order to just see the spellchecker and let the user push the [Start]
87        button then the updateSpellChecker signal will make the SpellChecker
88        dialog get the new word and replacements list from LyX.  If you really,
89        really wanted to you could define a signal that would pass the new
90        word and replacements:
91                  Signal2<void, string, vector<string> > updateSpellChecker;
92
93        (or something similar) but, why bother when the spellchecker can get
94        it anyway with a LyXFunc call or two.  Besides if someone extends
95        what a dialog does then they also have to change code in the rest of
96        LyX to pass more parameters or get the extra info via a function
97        call anyway.  Thus reducing the independence of the two code bases.
98
99        We don't need a separate update signal for each dialog because most of
100        them will be changed only when the buffer is changed (either by closing
101        the current open buffer or switching to another buffer in the current
102        LyXView -- different BufferView same LyXView or same BufferView same
103        LyXView).
104
105        So we minimise signals but maximise independence and programming
106        simplicity, understandability and maintainability.  It's also
107        extremely easy to add support for Qt or gtk-- because they use
108        signals already. Guis that use callbacks, like xforms, must have their
109        code wrapped up like that in the form_copyright.[Ch] which is awkward
110        but will at least allow multiple instances of the same dialog.
111
112        LyXFuncs will be used for requesting/setting LyX internal info.  This
113        will ensure that scripts or LyXServer-connected applications can all
114        have access to the same calls as the internal user-interface.
115
116 ******************************************************************************/