1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995-2001 The LyX Team.
8 * ======================================================
14 #pragma implementation
23 #include "frontends/LyXView.h"
30 #include "GPreamble.h"
31 #include "GTabularCreate.h"
36 bool Dialogs::tooltipsEnabled()
38 return Tooltips::enabled();
40 Dialogs::Dialogs(LyXView * lv)
43 add(new GUI<ControlError,GErrorDialog,
44 OkCancelPolicy, gnomeBC>(*lv, *this));
45 add(new GUI<ControlERT, GERT,
46 NoRepeatedApplyReadOnlyPolicy, gnomeBC>(*lv, *this));
47 add(new GUI<ControlUrl, GUrl,
48 NoRepeatedApplyReadOnlyPolicy, gnomeBC>(*lv,*this));
49 add(new GUI<ControlPreamble, GPreamble,
50 NoRepeatedApplyReadOnlyPolicy, gnomeBC>(*lv, *this));
51 add(new GUI<ControlTabularCreate, GTabularCreate,
52 OkApplyCancelReadOnlyPolicy, gnomeBC>(*lv, *this));
53 add(new GUI<ControlLog, GLog,
54 OkCancelPolicy, gnomeBC>(*lv, *this));
55 add(new GUI<ControlAboutlyx, GAbout,
56 OkCancelPolicy, gnomeBC>(*lv, *this));
57 add(new GUI<ControlFloat, GFloat,
58 NoRepeatedApplyReadOnlyPolicy, gnomeBC>(*lv, *this));
59 // reduce the number of connections needed in
60 // dialogs by a simple connection here.
61 hideAll.connect(hideBufferDependent);
64 /*****************************************************************************
66 Q. WHY does Dialogs::Dialogs pass `this' to dialog constructors?
68 A. To avoid a segfault.
69 The dialog constructors need to connect to their
70 respective showSomeDialog signal(*) but in order to do
71 that they need to get the address of the Dialogs instance
72 from LyXView::getDialogs(). However, since the Dialogs
73 instance is still being constructed at that time
74 LyXView::getDialogs() will *not* return the correct
75 address because it hasn't finished being constructed.
76 A Catch-22 situation (or is that the chicken and the egg...).
77 So to get around the problem we pass the address of
78 the newly created Dialogs instance using `this'.
80 (*) -- I'm using signals exclusively to guarantee that the gui code
81 remains hidden from the rest of the system. In fact the only
82 header related to dialogs that anything in the non-gui-specific
83 code gets to see is Dialogs.h! Even Dialogs.h doesn't know what a
84 FormCopyright class looks like or that its even going to be used!
86 No other gui dialog headers are seen outside of the gui-specific
87 directories! This ensures that the gui is completely separate from
88 the rest of LyX. All this through the use of a few simple signals.
89 BUT, the price is that during construction we need to connect the
90 implementations show() method to the showSomeDialog signal and this
91 requires that we have an instance of Dialogs and the problem mentioned
94 Almost all other dialogs should be able to operate using the same style
95 of signalling used for Copyright. Exceptions should be handled
96 by adding a specific show or update signal. For example, spellchecker
97 needs to set the next suspect word and its options/replacements so we
99 Signal0<void> updateSpellChecker;
101 Since we would have to have a
102 Signal0<void> showSpellChecker;
104 in order to just see the spellchecker and let the user push the [Start]
105 button then the updateSpellChecker signal will make the SpellChecker
106 dialog get the new word and replacements list from LyX. If you really,
107 really wanted to you could define a signal that would pass the new
108 word and replacements:
109 Signal2<void, string, vector<string> > updateSpellChecker;
111 (or something similar) but, why bother when the spellchecker can get
112 it anyway with a LyXFunc call or two. Besides if someone extends
113 what a dialog does then they also have to change code in the rest of
114 LyX to pass more parameters or get the extra info via a function
115 call anyway. Thus reducing the independence of the two code bases.
117 We don't need a separate update signal for each dialog because most of
118 them will be changed only when the buffer is changed (either by closing
119 the current open buffer or switching to another buffer in the current
120 LyXView -- different BufferView same LyXView or same BufferView same
123 So we minimise signals but maximise independence and programming
124 simplicity, understandability and maintainability. It's also
125 extremely easy to add support for Qt or gtk-- because they use
126 signals already. Guis that use callbacks, like xforms, must have their
127 code wrapped up like that in the form_copyright.[Ch] which is awkward
128 but will at least allow multiple instances of the same dialog.
130 LyXFuncs will be used for requesting/setting LyX internal info. This
131 will ensure that scripts or LyXServer-connected applications can all
132 have access to the same calls as the internal user-interface.
134 ******************************************************************************/