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