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