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 "support/strfwd.h"
33 /** \enum KernelDocType used to flag the different kinds of buffer
34 * without making the kernel header files available to the
35 * dialog's Controller or View.
45 /** \c Dialog collects the different parts of a Model-Controller-View
46 * split of a generic dialog together.
51 /// \param lv is the access point for the dialog to the LyX kernel.
52 /// \param name is the identifier given to the dialog by its parent
54 /// \param title is the window title used for decoration.
55 Dialog(GuiView & lv, QString const & name, QString const & title);
59 virtual QWidget * asQWidget() = 0;
60 virtual QWidget const * asQWidget() const = 0;
64 * This key must be used for any session setting.
66 QString sessionKey() const;
68 /// Save session settings.
70 * This default implementation saves the geometry state.
71 * Reimplement to save more settings.
73 virtual void saveSession() const;
75 /// Restore session settings.
77 * This default implementation restores the geometry state.
78 * Reimplement to restore more settings.
80 virtual void restoreSession();
82 /** \name Container Access
83 * These methods are publicly accessible because they are invoked
84 * by the parent container acting on commands from the LyX kernel.
87 /// \param data is a string encoding of the data to be displayed.
88 /// It is passed to the Controller to be translated into a useable form.
89 virtual void showData(std::string const & data);
90 virtual void updateData(std::string const & data);
93 /** Check whether we may apply our data.
95 * The buttons are disabled if not and (re-)enabled if yes.
97 virtual void checkStatus();
99 /** When applying, it's useful to know whether the dialog is about
100 * to close or not (no point refreshing the display for example).
102 virtual bool isClosing() const { return false; }
105 * of a Model-Controller-View split of a generic dialog.
106 * These few methods are all that a generic dialog needs of a
110 /** A request to modify the data structures stored by the
111 * accompanying Controller in preparation for their dispatch to
114 virtual void applyView() = 0;
116 /// Hide the dialog from sight
119 /// Create the dialog if necessary, update it and display it.
122 /// Update the display of the dialog whilst it is still visible.
123 virtual void updateView() = 0;
125 // Default Implementation does nothing.
126 // Each dialog has to choose what control to enable or disable.
127 virtual void enableView(bool /*enable*/) {}
129 /// \return true if the dialog is visible.
130 virtual bool isVisibleView() const;
133 /// Dialog identifier.
134 QString name() const { return name_; }
137 /** Enable the controller to initialise its data structures.
138 * \param data is a string encoding of the parameters to be displayed.
139 * \return true if the translation was successful.
141 virtual bool initialiseParams(std::string const & data) = 0;
143 /// Enable the controller to clean up its data structures.
144 virtual void clearParams() = 0;
146 /// Enable the Controller to dispatch its data back to the LyX kernel.
147 virtual void dispatchParams() = 0;
149 /** \return true if the dialog should be shown only when
152 virtual bool isBufferDependent() const = 0;
154 /** \return true if the dialog can apply data also
155 * for ReadOnly buffers.
156 * This has to be distinguished from isBufferDependent()
158 virtual bool canApplyToReadOnly() const { return false; }
160 /** The lfun that is sent for applying the data.
162 * This method is used by the default implementation of canApply()
163 * for buffer dependent dialogs that send one lfun when applying the
165 * It should be used in dispatchParams(), too for consistency reasons.
166 * \returns the lfun that is sent for applying the data.
168 virtual FuncCode getLfun() const { return LFUN_INSET_APPLY; }
170 /** Check whether we may apply our data.
172 * The default implementation works for all dialogs that send one
173 * lfun when applying the data. Dialogs that send none or more than
174 * one lfun need to reimplement it.
175 * \returns whether the data can be applied or not.
177 virtual bool canApply() const;
179 /** \return true if the kernel should disconnect the dialog from
180 * a particular inset after the data has been applied to it.
181 * Clearly this makes sense only for dialogs modifying the contents
183 * In practise, only a very few dialogs (e.g. the citation dialog)
186 virtual bool disconnectOnApply() const { return false; }
188 /** \return true if Dialog::View::show() should not display the dialog
189 * after running update. Currently, only ControlSpellchecker
192 virtual bool exitEarly() const { return false; }
195 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
196 * (Ie, it provides an interface to the Model part of the Model-Controller-
198 * In an ideal world, it will shrink as more info is passed to the
199 * Dialog::show() and Dialog::update() methods.
203 /** This method is the primary purpose of the class. It provides
204 * the "gateway" by which the dialog can send a request (of a
205 * change in the data, for more information) to the kernel.
206 * \param fr is the encoding of the request.
208 void dispatch(FuncRequest const & fr) const;
210 /** The dialog has received a request from the user
211 * (who pressed the "Restore" button) to update contents.
212 * It must, therefore, ask the kernel to provide this information.
213 * \param name is used to identify the dialog to the kernel.
215 void updateDialog() const;
217 /** A request from the Controller that future changes to the data
218 * stored by the dialog are not applied to the inset currently
219 * connected to the dialog. Instead, they will be used to generate
220 * a new inset at the cursor position.
221 * \param name is used to identify the dialog to the kernel.
223 void disconnect() const;
225 /** \name Kernel Wrappers
226 * Simple wrapper functions to Buffer methods.
229 bool isBufferAvailable() const;
230 bool isBufferReadonly() const;
231 QString bufferFilepath() const;
234 /// The type of the current buffer.
235 KernelDocType docType() const;
237 /** \name Kernel Nasties
238 * Unpleasantly public internals of the LyX kernel.
239 * We should aim to reduce/remove these from the interface.
242 GuiView & lyxview() { return *lyxview_; }
243 GuiView const & lyxview() const { return *lyxview_; }
246 Buffer const & buffer() const;
248 BufferView * bufferview();
249 BufferView const * bufferview() const;
254 void setTitle(QString const & title) { title_ = title; }
256 virtual void apply();
259 /** The Dialog's name is the means by which a dialog identifies
260 * itself to the LyXView.
268 /// intentionally unimplemented, therefore uncopiable
269 Dialog(Dialog const &);
270 void operator=(Dialog const &);
275 } // namespace frontend