4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
17 #include "insets/InsetCode.h"
19 #include "support/strfwd.h"
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.
48 /** \c Dialog collects the different parts of a Model-Controller-View
49 * split of a generic dialog together.
54 /// \param lv is the access point for the dialog to the LyX kernel.
55 /// \param name is the identifier given to the dialog by its parent
57 /// \param title is the window title used for decoration.
58 Dialog(GuiView & lv, QString const & name, QString const & title);
62 virtual QWidget * asQWidget() = 0;
63 virtual QWidget const * asQWidget() const = 0;
67 * This key must be used for any session setting.
69 QString sessionKey() const;
71 /// Save session settings.
73 * This default implementation saves the geometry state.
74 * Reimplement to save more settings.
76 virtual void saveSession() const;
78 /// Restore session settings.
80 * This default implementation restores the geometry state.
81 * Reimplement to restore more settings.
83 virtual void restoreSession();
85 /** \name Container Access
86 * These methods are publicly accessible because they are invoked
87 * by the parent container acting on commands from the LyX kernel.
90 /// \param data is a string encoding of the data to be displayed.
91 /// It is passed to the Controller to be translated into a useable form.
92 virtual void showData(std::string const & data);
95 /// \return inset at current cursor location.
96 Inset * inset(InsetCode code) const;
98 /** Check whether we may apply our data.
100 * The buttons are disabled if not and (re-)enabled if yes.
102 virtual void checkStatus();
104 /** When applying, it's useful to know whether the dialog is about
105 * to close or not (no point refreshing the display for example).
107 virtual bool isClosing() const { return false; }
110 * of a Model-Controller-View split of a generic dialog.
111 * These few methods are all that a generic dialog needs of a
115 /** A request to modify the data structures stored by the
116 * accompanying Controller in preparation for their dispatch to
119 virtual void applyView() = 0;
121 /// Hide the dialog from sight
124 /// Create the dialog if necessary, update it and display it.
127 /// Update the display of the dialog whilst it is still visible.
128 virtual void updateView() = 0;
130 // Default Implementation does nothing.
131 // Each dialog has to choose what control to enable or disable.
132 virtual void enableView(bool /*enable*/) {}
134 /// \return true if the dialog is visible.
135 virtual bool isVisibleView() const;
138 /// Dialog identifier.
139 QString name() const { return name_; }
142 /** Enable the controller to initialise its data structures.
143 * \param data is a string encoding of the parameters to be displayed.
144 * \return true if the translation was successful.
146 virtual bool initialiseParams(std::string const & data) = 0;
148 /// Enable the controller to clean up its data structures.
149 virtual void clearParams() = 0;
151 /// Enable the Controller to dispatch its data back to the LyX kernel.
152 virtual void dispatchParams() = 0;
154 /** \return true if the dialog should be shown only when
157 virtual bool isBufferDependent() const = 0;
159 /** \return true if the dialog can apply data also
160 * for ReadOnly buffers.
161 * This has to be distinguished from isBufferDependent()
163 virtual bool canApplyToReadOnly() const { return false; }
165 /** The lfun that is sent for applying the data.
167 * This method is used by the default implementation of canApply()
168 * for buffer dependent dialogs that send one lfun when applying the
170 * It should be used in dispatchParams(), too for consistency reasons.
171 * \returns the lfun that is sent for applying the data.
173 virtual FuncCode getLfun() const { return LFUN_INSET_APPLY; }
175 /** Check whether we may apply our data.
177 * The default implementation works for all dialogs that send one
178 * lfun when applying the data. Dialogs that send none or more than
179 * one lfun need to reimplement it.
180 * \returns whether the data can be applied or not.
182 virtual bool canApply() const;
184 /** \return true if the kernel should disconnect the dialog from
185 * a particular inset after the data has been applied to it.
186 * Clearly this makes sense only for dialogs modifying the contents
188 * In practise, only a very few dialogs (e.g. the citation dialog)
191 virtual bool disconnectOnApply() const { return false; }
193 /** \return true if Dialog::View::show() should not display the dialog
194 * after running update. Currently, only ControlSpellchecker
197 virtual bool exitEarly() const { return false; }
200 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
201 * (Ie, it provides an interface to the Model part of the Model-Controller-
203 * In an ideal world, it will shrink as more info is passed to the
204 * Dialog::show() and Dialog::update() methods.
208 /** This method is the primary purpose of the class. It provides
209 * the "gateway" by which the dialog can send a request (of a
210 * change in the data, for more information) to the kernel.
211 * \param fr is the encoding of the request.
213 void dispatch(FuncRequest const & fr) const;
215 /** The dialog has received a request from the user
216 * (who pressed the "Restore" button) to update contents.
217 * It must, therefore, ask the kernel to provide this information.
218 * \param name is used to identify the dialog to the kernel.
220 void updateDialog() const;
222 /** A request from the Controller that future changes to the data
223 * stored by the dialog are not applied to the inset currently
224 * connected to the dialog. Instead, they will be used to generate
225 * a new inset at the cursor position.
226 * \param name is used to identify the dialog to the kernel.
228 void disconnect() const;
230 /** \name Kernel Wrappers
231 * Simple wrapper functions to Buffer methods.
234 bool isBufferAvailable() const;
235 bool isBufferReadonly() const;
236 QString bufferFilepath() const;
239 /// The type of the current buffer.
240 KernelDocType docType() const;
242 /** \name Kernel Nasties
243 * Unpleasantly public internals of the LyX kernel.
244 * We should aim to reduce/remove these from the interface.
247 GuiView & lyxview() { return *lyxview_; }
248 GuiView const & lyxview() const { return *lyxview_; }
251 Buffer const & buffer() const;
253 BufferView * bufferview();
254 BufferView const * bufferview() const;
259 void setTitle(QString const & title) { title_ = title; }
261 virtual void apply();
264 /** The Dialog's name is the means by which a dialog identifies
265 * itself to the LyXView.
273 /// intentionally unimplemented, therefore uncopiable
274 Dialog(Dialog const &);
275 void operator=(Dialog const &);
280 } // namespace frontend