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