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.
47 /** \c Dialog collects the different parts of a Model-Controller-View
48 * split of a generic dialog together.
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
56 /// \param title is the window title used for decoration.
57 Dialog(GuiView & lv, QString const & name, QString const & title);
61 virtual QWidget * asQWidget() = 0;
62 virtual QWidget const * asQWidget() const = 0;
66 * This key must be used for any session setting.
68 QString sessionKey() const;
70 /// Save session settings.
72 * This default implementation saves the geometry state.
73 * Reimplement to save more settings.
75 virtual void saveSession() const;
77 /// Restore session settings.
79 * This default implementation restores the geometry state.
80 * Reimplement to restore more settings.
82 virtual void restoreSession();
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.
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);
94 /// \return inset at current cursor location.
95 Inset const * inset(InsetCode code) const;
97 /** Check whether we may apply our data.
99 * The buttons are disabled if not and (re-)enabled if yes.
101 virtual void checkStatus();
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).
106 virtual bool isClosing() const { return false; }
109 * of a Model-Controller-View split of a generic dialog.
110 * These few methods are all that a generic dialog needs of a
114 /** A request to modify the data structures stored by the
115 * accompanying Controller in preparation for their dispatch to
118 virtual void applyView() = 0;
120 /// Hide the dialog from sight
123 /// Prepare dialog and display it.
126 /// Prepare dialog before view.
129 /// Decide wether the dialog should grab thekeyboard focus when shown.
130 /// This method defaults to true, override if a different behaviour
132 virtual bool wantInitialFocus() const { return true; }
134 /// Update the display of the dialog whilst it is still visible.
135 virtual void updateView() = 0;
137 // Default Implementation does nothing.
138 // Each dialog has to choose what control to enable or disable.
139 virtual void enableView(bool /*enable*/) {}
141 /// \return true if the dialog is visible.
142 virtual bool isVisibleView() const;
145 /// Dialog identifier.
146 QString name() const { return name_; }
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.
153 virtual bool initialiseParams(std::string const & data) = 0;
155 /// Enable the controller to clean up its data structures.
156 virtual void clearParams() = 0;
158 /// Enable the Controller to dispatch its data back to the LyX kernel.
159 virtual void dispatchParams() = 0;
161 /** \return true if the dialog should be updated when the
162 * buffer has changed.
164 virtual bool isBufferDependent() const = 0;
166 /** \return true if the dialog should be shown only when
169 virtual bool needBufferOpen() const = 0;
171 /** \return true if the dialog can apply data also
172 * for ReadOnly buffers.
173 * This has to be distinguished from isBufferDependent()
175 virtual bool canApplyToReadOnly() const { return false; }
177 /** The lfun that is sent for applying the data.
179 * This method is used by the default implementation of canApply()
180 * for buffer dependent dialogs that send one lfun when applying the
182 * It should be used in dispatchParams(), too for consistency reasons.
183 * \returns the lfun that is sent for applying the data.
185 virtual FuncCode getLfun() const { return LFUN_INSET_APPLY; }
187 /** Check whether we may apply our data.
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.
194 virtual bool canApply() const;
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
200 * In practise, only a very few dialogs (e.g. the citation dialog)
203 virtual bool disconnectOnApply() const { return false; }
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-
210 * In an ideal world, it will shrink as more info is passed to the
211 * Dialog::show() and Dialog::update() methods.
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.
220 void dispatch(FuncRequest const & fr) const;
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.
227 void updateDialog() const;
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.
234 void disconnect() const;
236 /** \name Kernel Wrappers
237 * Simple wrapper functions to Buffer methods.
240 bool isBufferAvailable() const;
241 bool isBufferReadonly() const;
242 QString bufferFilePath() const;
245 /// The type of the current buffer.
246 KernelDocType docType() const;
248 /** \name Kernel Nasties
249 * Unpleasantly public internals of the LyX kernel.
250 * We should aim to reduce/remove these from the interface.
253 GuiView const & lyxview() const { return *lyxview_; }
255 Buffer const & buffer() const;
256 /// Main document buffer
257 Buffer const & documentBuffer() const;
258 /// Current BufferView
259 BufferView const * bufferview() const;
264 void setTitle(QString const & title) { title_ = title; }
266 virtual void apply();
269 /** The Dialog's name is the means by which a dialog identifies
270 * itself to the GuiView.
278 /// intentionally unimplemented, therefore uncopiable
279 Dialog(Dialog const &);
280 void operator=(Dialog const &);
284 } // namespace frontend