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