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"
38 /** \enum KernelDocType used to flag the different kinds of buffer
39 * without making the kernel header files available to the
40 * dialog's Controller or View.
50 // FIXME: Get rid of CheckedLineEdit in ButtonController and rename this one
52 class CheckedLineEdit2
55 CheckedLineEdit2(QLineEdit * input, QWidget * label = 0)
56 : input_(input), label_(label)
68 typedef QList<CheckedLineEdit2> CheckedLineEdits;
71 /** \c Dialog collects the different parts of a Model-Controller-View
72 * split of a generic dialog together.
77 /// \param lv is the access point for the dialog to the LyX kernel.
78 /// \param name is the identifier given to the dialog by its parent
80 /// \param title is the window title used for decoration.
81 Dialog(GuiView & lv, QString const & name, QString const & title);
85 virtual QWidget * asQWidget() = 0;
86 virtual QWidget const * asQWidget() const = 0;
89 void addCheckedWidget(QLineEdit * input, QWidget * label);
93 * This key must be used for any session setting.
95 QString sessionKey() const;
97 /// Save session settings.
99 * This default implementation saves the geometry state.
100 * Reimplement to save more settings.
102 virtual void saveSession() const;
104 /// Restore session settings.
106 * This default implementation restores the geometry state.
107 * Reimplement to restore more settings.
109 virtual void restoreSession();
111 /** \name Container Access
112 * These methods are publicly accessible because they are invoked
113 * by the parent container acting on commands from the LyX kernel.
116 /// \param data is a string encoding of the data to be displayed.
117 /// It is passed to the Controller to be translated into a useable form.
118 virtual void showData(std::string const & data);
121 /// \return inset at current cursor location.
122 Inset const * inset(InsetCode code) const;
124 /** Check whether we may apply our data.
126 * The buttons are disabled if not and (re-)enabled if yes.
128 virtual void checkStatus();
130 /** When applying, it's useful to know whether the dialog is about
131 * to close or not (no point refreshing the display for example).
133 virtual bool isClosing() const { return false; }
136 * of a Model-Controller-View split of a generic dialog.
137 * These few methods are all that a generic dialog needs of a
141 /** A request to modify the data structures stored by the
142 * accompanying Controller in preparation for their dispatch to
145 virtual void applyView() = 0;
147 /// Hide the dialog from sight
150 /// Prepare dialog and display it.
153 /// Prepare dialog before view.
156 /// Decide wether the dialog should grab thekeyboard focus when shown.
157 /// This method defaults to true, override if a different behaviour
159 virtual bool wantInitialFocus() const { return true; }
161 /// Update the display of the dialog whilst it is still visible.
162 virtual void updateView() = 0;
164 // Default Implementation does nothing.
165 // Each dialog has to choose what control to enable or disable.
166 virtual void enableView(bool /*enable*/) {}
168 /// \return true if the dialog is visible.
169 virtual bool isVisibleView() const;
172 /// Dialog identifier.
173 QString name() const { return name_; }
176 /** Enable the controller to initialise its data structures.
177 * \param data is a string encoding of the parameters to be displayed.
178 * \return true if the translation was successful.
180 virtual bool initialiseParams(std::string const & data) = 0;
182 /// Enable the controller to clean up its data structures.
183 virtual void clearParams() = 0;
185 /// Enable the Controller to dispatch its data back to the LyX kernel.
186 virtual void dispatchParams() = 0;
188 /** \return true if the dialog should be shown only when
191 virtual bool isBufferDependent() const = 0;
193 /** \return true if the dialog can apply data also
194 * for ReadOnly buffers.
195 * This has to be distinguished from isBufferDependent()
197 virtual bool canApplyToReadOnly() const { return false; }
199 /** The lfun that is sent for applying the data.
201 * This method is used by the default implementation of canApply()
202 * for buffer dependent dialogs that send one lfun when applying the
204 * It should be used in dispatchParams(), too for consistency reasons.
205 * \returns the lfun that is sent for applying the data.
207 virtual FuncCode getLfun() const { return LFUN_INSET_APPLY; }
209 /** Check whether we may apply our data.
211 * The default implementation works for all dialogs that send one
212 * lfun when applying the data. Dialogs that send none or more than
213 * one lfun need to reimplement it.
214 * \returns whether the data can be applied or not.
216 virtual bool canApply() const;
218 /** \return true if the kernel should disconnect the dialog from
219 * a particular inset after the data has been applied to it.
220 * Clearly this makes sense only for dialogs modifying the contents
222 * In practise, only a very few dialogs (e.g. the citation dialog)
225 virtual bool disconnectOnApply() const { return false; }
229 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
230 * (Ie, it provides an interface to the Model part of the Model-Controller-
232 * In an ideal world, it will shrink as more info is passed to the
233 * Dialog::show() and Dialog::update() methods.
237 /** This method is the primary purpose of the class. It provides
238 * the "gateway" by which the dialog can send a request (of a
239 * change in the data, for more information) to the kernel.
240 * \param fr is the encoding of the request.
242 void dispatch(FuncRequest const & fr) const;
244 /** The dialog has received a request from the user
245 * (who pressed the "Restore" button) to update contents.
246 * It must, therefore, ask the kernel to provide this information.
247 * \param name is used to identify the dialog to the kernel.
249 void updateDialog() const;
251 /** A request from the Controller that future changes to the data
252 * stored by the dialog are not applied to the inset currently
253 * connected to the dialog. Instead, they will be used to generate
254 * a new inset at the cursor position.
256 void disconnect() const;
258 /** \name Kernel Wrappers
259 * Simple wrapper functions to Buffer methods.
262 bool isBufferAvailable() const;
263 bool isBufferReadonly() const;
264 QString bufferFilepath() const;
267 /// The type of the current buffer.
268 KernelDocType docType() const;
270 /** \name Kernel Nasties
271 * Unpleasantly public internals of the LyX kernel.
272 * We should aim to reduce/remove these from the interface.
275 GuiView const & lyxview() const { return *lyxview_; }
276 Buffer const & buffer() const;
277 BufferView const * bufferview() const;
282 void setTitle(QString const & title) { title_ = title; }
284 virtual void apply();
285 /// \return true if all CheckedWidgets are in a valid state.
286 bool checkWidgets() const;
289 /** The Dialog's name is the means by which a dialog identifies
290 * itself to the LyXView.
298 /// intentionally unimplemented, therefore uncopiable
299 Dialog(Dialog const &);
300 void operator=(Dialog const &);
303 CheckedLineEdits checked_line_edits_;
307 } // namespace frontend