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