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