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;
90 * This key must be used for any session setting.
92 QString sessionKey() const;
94 /// Save session settings.
96 * This default implementation saves the geometry state.
97 * Reimplement to save more settings.
99 virtual void saveSession() const;
101 /// Restore session settings.
103 * This default implementation restores the geometry state.
104 * Reimplement to restore more settings.
106 virtual void restoreSession();
108 /** \name Container Access
109 * These methods are publicly accessible because they are invoked
110 * by the parent container acting on commands from the LyX kernel.
113 /// \param data is a string encoding of the data to be displayed.
114 /// It is passed to the Controller to be translated into a useable form.
115 virtual void showData(std::string const & data);
118 /// \return inset at current cursor location.
119 Inset const * inset(InsetCode code) const;
121 /** Check whether we may apply our data.
123 * The buttons are disabled if not and (re-)enabled if yes.
125 virtual void checkStatus();
127 /** When applying, it's useful to know whether the dialog is about
128 * to close or not (no point refreshing the display for example).
130 virtual bool isClosing() const { return false; }
133 * of a Model-Controller-View split of a generic dialog.
134 * These few methods are all that a generic dialog needs of a
138 /** A request to modify the data structures stored by the
139 * accompanying Controller in preparation for their dispatch to
142 virtual void applyView() = 0;
144 /// Hide the dialog from sight
147 /// Prepare dialog and display it.
150 /// Prepare dialog before view.
153 /// Decide wether the dialog should grab thekeyboard focus when shown.
154 /// This method defaults to true, override if a different behaviour
156 virtual bool wantInitialFocus() const { return true; }
158 /// Update the display of the dialog whilst it is still visible.
159 virtual void updateView() = 0;
161 // Default Implementation does nothing.
162 // Each dialog has to choose what control to enable or disable.
163 virtual void enableView(bool /*enable*/) {}
165 /// \return true if the dialog is visible.
166 virtual bool isVisibleView() const;
169 /// Dialog identifier.
170 QString name() const { return name_; }
173 /** Enable the controller to initialise its data structures.
174 * \param data is a string encoding of the parameters to be displayed.
175 * \return true if the translation was successful.
177 virtual bool initialiseParams(std::string const & data) = 0;
179 /// Enable the controller to clean up its data structures.
180 virtual void clearParams() = 0;
182 /// Enable the Controller to dispatch its data back to the LyX kernel.
183 virtual void dispatchParams() = 0;
185 /** \return true if the dialog should be shown only when
188 virtual bool isBufferDependent() const = 0;
190 /** \return true if the dialog can apply data also
191 * for ReadOnly buffers.
192 * This has to be distinguished from isBufferDependent()
194 virtual bool canApplyToReadOnly() const { return false; }
196 /** The lfun that is sent for applying the data.
198 * This method is used by the default implementation of canApply()
199 * for buffer dependent dialogs that send one lfun when applying the
201 * It should be used in dispatchParams(), too for consistency reasons.
202 * \returns the lfun that is sent for applying the data.
204 virtual FuncCode getLfun() const { return LFUN_INSET_APPLY; }
206 /** Check whether we may apply our data.
208 * The default implementation works for all dialogs that send one
209 * lfun when applying the data. Dialogs that send none or more than
210 * one lfun need to reimplement it.
211 * \returns whether the data can be applied or not.
213 virtual bool canApply() const;
215 /** \return true if the kernel should disconnect the dialog from
216 * a particular inset after the data has been applied to it.
217 * Clearly this makes sense only for dialogs modifying the contents
219 * In practise, only a very few dialogs (e.g. the citation dialog)
222 virtual bool disconnectOnApply() const { return false; }
226 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
227 * (Ie, it provides an interface to the Model part of the Model-Controller-
229 * In an ideal world, it will shrink as more info is passed to the
230 * Dialog::show() and Dialog::update() methods.
234 /** This method is the primary purpose of the class. It provides
235 * the "gateway" by which the dialog can send a request (of a
236 * change in the data, for more information) to the kernel.
237 * \param fr is the encoding of the request.
239 void dispatch(FuncRequest const & fr) const;
241 /** The dialog has received a request from the user
242 * (who pressed the "Restore" button) to update contents.
243 * It must, therefore, ask the kernel to provide this information.
244 * \param name is used to identify the dialog to the kernel.
246 void updateDialog() const;
248 /** A request from the Controller that future changes to the data
249 * stored by the dialog are not applied to the inset currently
250 * connected to the dialog. Instead, they will be used to generate
251 * a new inset at the cursor position.
253 void disconnect() const;
255 /** \name Kernel Wrappers
256 * Simple wrapper functions to Buffer methods.
259 bool isBufferAvailable() const;
260 bool isBufferReadonly() const;
261 QString bufferFilepath() const;
264 /// The type of the current buffer.
265 KernelDocType docType() const;
267 /** \name Kernel Nasties
268 * Unpleasantly public internals of the LyX kernel.
269 * We should aim to reduce/remove these from the interface.
272 GuiView const & lyxview() const { return *lyxview_; }
273 Buffer const & buffer() const;
274 BufferView const * bufferview() const;
279 void setTitle(QString const & title) { title_ = title; }
281 virtual void apply();
282 /// Add a widget to the list of all widgets whose validity should
283 /// be checked explicitly when the buttons are refreshed.
284 void addCheckedWidget(QLineEdit * input, QWidget * label = 0);
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