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"
37 /** \enum KernelDocType used to flag the different kinds of buffer
38 * without making the kernel header files available to the
39 * dialog's Controller or View.
41 enum class KernelDocType : int
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(QSettings & settings) 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 usable form.
91 virtual void showData(std::string const & data)
93 return showData(data, Qt::PopupFocusReason);
96 /// \param data is a string encoding of the data to be displayed.
97 /// It is passed to the Controller to be translated into a usable form.
98 /// \param reason provides the focus reason of the dialog.
99 /// E.g. dialog "findreplaceadv" requires special treatment after
100 /// obtaining focus in terms of the input method item transformation,
101 /// so should be marked as reason = Qt::OtherFocusReason.
102 virtual void showData(std::string const & data, Qt::FocusReason reason);
105 /// \return inset at current cursor location.
106 Inset const * inset(InsetCode code) const;
108 /** Check whether we may apply our data.
110 * The buttons are disabled if not and (re-)enabled if yes.
112 virtual void checkStatus();
114 /** When applying, it's useful to know whether the dialog is about
115 * to close or not (no point refreshing the display for example).
117 virtual bool isClosing() const { return false; }
120 * of a Model-Controller-View split of a generic dialog.
121 * These few methods are all that a generic dialog needs of a
125 /** A request to modify the data structures stored by the
126 * accompanying Controller in preparation for their dispatch to
129 virtual void applyView() = 0;
131 /// Hide the dialog from sight
134 /// Prepare dialog and display it.
135 void showView() { return showView(Qt::PopupFocusReason); }
137 /// Prepare dialog and display it.
138 /// \param reason provides the focus reason of the dialog.
139 /// E.g. dialog "findreplaceadv" requires special treatment after
140 /// obtaining focus in terms of the input method item transformation,
141 /// so should be marked as reason = Qt::OtherFocusReason.
142 void showView(Qt::FocusReason reason);
144 /// Prepare dialog before view.
147 /// Decide whether the dialog should grab thekeyboard focus when shown.
148 /// This method defaults to true, override if a different behaviour
150 virtual bool wantInitialFocus() const { return true; }
152 /// Update the display of the dialog whilst it is still visible.
153 virtual void updateView() = 0;
155 // Default Implementation does nothing.
156 // Each dialog has to choose what control to enable or disable.
157 virtual void enableView(bool /*enable*/) {}
159 /// \return true if the dialog is visible.
160 virtual bool isVisibleView() const;
163 /// Dialog identifier.
164 QString name() const { return name_; }
167 /** Enable the controller to initialise its data structures.
168 * \param data is a string encoding of the parameters to be displayed.
169 * \return true if the translation was successful.
171 virtual bool initialiseParams(std::string const & data) = 0;
173 /// Enable the controller to clean up its data structures.
174 virtual void clearParams() = 0;
176 /// Enable the Controller to dispatch its data back to the LyX kernel.
177 virtual void dispatchParams() = 0;
179 /** \return true if the dialog should be updated when the
180 * buffer has changed.
182 virtual bool isBufferDependent() const = 0;
184 /** \return true if the dialog should be shown only when
187 virtual bool needBufferOpen() const = 0;
189 /** \return true if the dialog can apply data also
190 * for ReadOnly buffers.
191 * This has to be distinguished from isBufferDependent()
193 virtual bool canApplyToReadOnly() const { return false; }
195 /** The lfun that is sent for applying the data.
197 * This method is used by the default implementation of canApply()
198 * for buffer dependent dialogs that send one lfun when applying the
200 * It should be used in dispatchParams(), too for consistency reasons.
201 * \returns the lfun that is sent for applying the data.
203 virtual FuncCode getLfun() const { return LFUN_INSET_APPLY; }
205 /** Check whether we may apply our data.
207 * The default implementation works for all dialogs that send one
208 * lfun when applying the data. Dialogs that send none or more than
209 * one lfun need to reimplement it.
210 * \returns whether the data can be applied or not.
212 virtual bool canApply() const;
214 /** \return true if the kernel should disconnect the dialog from
215 * a particular inset after the data has been applied to it.
216 * Clearly this makes sense only for dialogs modifying the contents
218 * In practise, only a very few dialogs (e.g. the citation dialog)
221 virtual bool disconnectOnApply() const { return false; }
225 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
226 * (Ie, it provides an interface to the Model part of the Model-Controller-
228 * In an ideal world, it will shrink as more info is passed to the
229 * Dialog::show() and Dialog::update() methods.
233 /** This method is the primary purpose of the class. It provides
234 * the "gateway" by which the dialog can send a request (of a
235 * change in the data, for more information) to the kernel.
236 * \param fr is the encoding of the request.
238 void dispatch(FuncRequest const & fr) const;
240 /** The dialog has received a request from the user
241 * (who pressed the "Restore" button) to update contents.
242 * It must, therefore, ask the kernel to provide this information.
243 * \param name is used to identify the dialog to the kernel.
245 void updateDialog() const;
247 /** A request from the Controller that future changes to the data
248 * stored by the dialog are not applied to the inset currently
249 * connected to the dialog. Instead, they will be used to generate
250 * a new inset at the cursor position.
252 void disconnect() const;
254 /** \name Kernel Wrappers
255 * Simple wrapper functions to Buffer methods.
258 bool isBufferAvailable() const;
259 bool isBufferReadonly() const;
260 QString bufferFilePath() const;
263 /// The type of the current buffer.
264 KernelDocType docType() const;
266 /** \name Kernel Nasties
267 * Unpleasantly public internals of the LyX kernel.
268 * We should aim to reduce/remove these from the interface.
271 GuiView const & lyxview() const { return lyxview_; }
273 Buffer const & buffer() const;
274 /// Main document buffer
275 Buffer const & documentBuffer() const;
276 /// Current BufferView
277 BufferView const * bufferview() const;
282 void setTitle(QString const & title) { title_ = title; }
284 virtual void apply();
285 /// To be called when the buffer view has changed
286 virtual void onBufferViewChanged() = 0;
288 virtual void onClosing(int) = 0;
290 void connectToNewInset();
293 /** The Dialog's name is the means by which a dialog identifies
294 * itself to the GuiView.
302 /// intentionally unimplemented, therefore uncopiable
303 Dialog(Dialog const &);
304 void operator=(Dialog const &);
308 } // namespace frontend