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