]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Dialog.h
2861eb02419456472ca8b332767975450231c9f3
[lyx.git] / src / frontends / qt4 / Dialog.h
1 // -*- C++ -*-
2 /**
3  * \file Dialog.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef DIALOG_H
13 #define DIALOG_H
14
15 #include "lfuns.h"
16
17 #include <string>
18
19 namespace lyx {
20
21 class Buffer;
22 class BufferView;
23 class FuncRequest;
24
25 namespace frontend {
26
27 class GuiView;
28
29 /** \enum KernelDocType used to flag the different kinds of buffer
30  *  without making the kernel header files available to the
31  *  dialog's Controller or View.
32  */
33 enum KernelDocType
34 {
35         LATEX,
36         LITERATE,
37         DOCBOOK
38 };
39
40
41 /** \c Dialog collects the different parts of a Model-Controller-View
42  *  split of a generic dialog together.
43  */
44 class Dialog 
45 {
46 public:
47         /// \param lv is the access point for the dialog to the LyX kernel.
48         /// \param name is the identifier given to the dialog by its parent
49         /// container.
50         Dialog(GuiView & lv, std::string const & name);
51
52         virtual ~Dialog();
53
54         /** \name Container Access
55          *  These methods are publicly accessible because they are invoked
56          *  by the parent container acting on commands from the LyX kernel.
57          */
58         //@{
59         /// \param data is a string encoding of the data to be displayed.
60         /// It is passed to the Controller to be translated into a useable form.
61         virtual void showData(std::string const & /*data*/) {}
62         virtual void updateData(std::string const & /*data*/) {}
63
64         virtual void hide() {}
65
66         //@}
67
68         /** Check whether we may apply our data.
69          *
70          *  The buttons are disabled if not and (re-)enabled if yes.
71          */
72         virtual void checkStatus() {}
73
74         /** When applying, it's useful to know whether the dialog is about
75          *  to close or not (no point refreshing the display for example).
76          */
77         virtual bool isClosing() const { return false; }
78
79
80         /** \c Button controller part
81          */
82         virtual void setButtonsValid(bool /*valid*/) {}
83
84
85         /** \c View part
86          *  of a Model-Controller-View split of a generic dialog.
87          *  These few methods are all that a generic dialog needs of a
88          *  view.
89          */
90         //@{
91         /** A request to modify the data structures stored by the
92          *  accompanying Controller in preparation for their dispatch to
93          *  the LyX kernel.
94          */
95         virtual void applyView() = 0;
96
97         /// Hide the dialog from sight
98         virtual void hideView() = 0;
99
100         /// Create the dialog if necessary, update it and display it.
101         virtual void showView() = 0;
102
103         /// Update the display of the dialog whilst it is still visible.
104         virtual void updateView() = 0;
105
106         /// \return true if the dialog is visible.
107         virtual bool isVisibleView() const = 0;
108         //@}
109
110         /// Dialog identifier.
111         /// FIXME for Andre': Now that Dialog is entirely within qt4/
112         /// We can use QString instead in order to avoid <string> inclusion
113         /// or we can pimpl name_.
114         std::string const & name() const;
115
116         //@{
117         /** Enable the controller to initialise its data structures.
118          *  \param data is a string encoding of the parameters to be displayed.
119          *  \return true if the translation was successful.
120          */
121         virtual bool initialiseParams(std::string const & data) = 0;
122
123         /// Enable the controller to clean up its data structures.
124         virtual void clearParams() = 0;
125
126         /// Enable the Controller to dispatch its data back to the LyX kernel.
127         virtual void dispatchParams() = 0;
128
129         /** \return true if the dialog should be shown only when
130          *  a buffer is open.
131          */
132         virtual bool isBufferDependent() const = 0;
133
134         /** \return true if the dialog can apply data also
135          *  for ReadOnly buffers.
136          *  This has to be distinguished from isBufferDependent()
137          */
138         virtual bool canApplyToReadOnly() const { return false; }
139
140         /** The lfun that is sent for applying the data.
141          *
142          * This method is used by the default implementation of canApply()
143          * for buffer dependent dialogs that send one lfun when applying the
144          * data.
145          * It should be used in dispatchParams(), too for consistency reasons.
146          *  \returns the lfun that is sent for applying the data.
147          */
148         virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
149
150         /** Check whether we may apply our data.
151          *
152          * The default implementation works for all dialogs that send one
153          * lfun when applying the data. Dialogs that send none or more than
154          * one lfun need to reimplement it.
155          *  \returns whether the data can be applied or not.
156          */
157         virtual bool canApply() const;
158
159         /** \return true if the kernel should disconnect the dialog from
160          *  a particular inset after the data has been applied to it.
161          *  Clearly this makes sense only for dialogs modifying the contents
162          *  of an inset :-)
163          *  In practise, only a very few dialogs (e.g. the citation dialog)
164          *  return true.
165          */
166         virtual bool disconnectOnApply() const { return false; }
167
168         /** \return true if Dialog::View::show() should not display the dialog
169          *   after running update. Currently, only ControlSpellchecker
170          *   makes use of that.
171         */
172         virtual bool exitEarly() const { return false; }
173         //@}
174
175         /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
176          * (Ie, it provides an interface to the Model part of the Model-Controller-
177          *  View split.
178          *  In an ideal world, it will shrink as more info is passed to the
179          *  Dialog::show() and Dialog::update() methods.
180          */
181
182
183         /** This method is the primary purpose of the class. It provides
184          *  the "gateway" by which the dialog can send a request (of a
185          *  change in the data, for more information) to the kernel.
186          *  \param fr is the encoding of the request.
187          */
188         void dispatch(FuncRequest const & fr) const;
189
190         /** The dialog has received a request from the user
191          *  (who pressed the "Restore" button) to update contents.
192          *  It must, therefore, ask the kernel to provide this information.
193          *  \param name is used to identify the dialog to the kernel.
194          */
195         void updateDialog() const;
196
197         /** A request from the Controller that future changes to the data
198          *  stored by the dialog are not applied to the inset currently
199          *  connected to the dialog. Instead, they will be used to generate
200          *  a new inset at the cursor position.
201          *  \param name is used to identify the dialog to the kernel.
202          */
203         void disconnect() const;
204
205         /** \name Kernel Wrappers
206          *  Simple wrapper functions to Buffer methods.
207          */
208         //@{
209         bool isBufferAvailable() const;
210         bool isBufferReadonly() const;
211         std::string const bufferFilepath() const;
212         //@}
213
214         /// The type of the current buffer.
215         KernelDocType docType() const;
216
217         /** \name Kernel Nasties
218          *  Unpleasantly public internals of the LyX kernel.
219          *  We should aim to reduce/remove these from the interface.
220          */
221         //@{
222         GuiView & lyxview() { return *lyxview_; }
223         GuiView const & lyxview() const { return *lyxview_; }
224
225         Buffer & buffer();
226         Buffer const & buffer() const;
227
228         BufferView * bufferview();
229         BufferView const * bufferview() const;
230         //@}
231
232 protected:
233         virtual void apply() {}
234
235 private:
236         /** The Dialog's name is the means by which a dialog identifies
237          *  itself to the LyXView.
238          */
239         std::string const name_;
240         ///
241         GuiView * lyxview_;
242
243         /// intentionally unimplemented, therefore uncopiable
244         Dialog(Dialog const &);
245         void operator=(Dialog const &);
246
247 };
248
249
250 } // namespace frontend
251 } // namespace lyx
252
253 #endif // DIALOG_H