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.
32 /** \enum KernelDocType used to flag the different kinds of buffer
33 * without making the kernel header files available to the
34 * dialog's Controller or View.
44 /** \c Dialog collects the different parts of a Model-Controller-View
45 * split of a generic dialog together.
50 /// \param lv is the access point for the dialog to the LyX kernel.
51 /// \param name is the identifier given to the dialog by its parent
53 /// \param title is the window title used for decoration.
54 Dialog(GuiView & lv, QString const & name, QString const & title);
58 virtual QWidget * asQWidget() = 0;
59 virtual QWidget const * asQWidget() const = 0;
63 * This key must be used for any session setting.
65 QString sessionKey() const;
67 /// Save session settings.
69 * This default implementation saves the geometry state.
70 * Reimplement to save more settings.
72 virtual void saveSession() const;
74 /// Restore session settings.
76 * This default implementation restores the geometry state.
77 * Reimplement to restore more settings.
79 virtual void restoreSession();
81 /** \name Container Access
82 * These methods are publicly accessible because they are invoked
83 * by the parent container acting on commands from the LyX kernel.
86 /// \param data is a string encoding of the data to be displayed.
87 /// It is passed to the Controller to be translated into a useable form.
88 virtual void showData(std::string const & data);
89 virtual void updateData(std::string const & data);
92 /** Check whether we may apply our data.
94 * The buttons are disabled if not and (re-)enabled if yes.
96 virtual void checkStatus();
98 /** When applying, it's useful to know whether the dialog is about
99 * to close or not (no point refreshing the display for example).
101 virtual bool isClosing() const { return false; }
104 * of a Model-Controller-View split of a generic dialog.
105 * These few methods are all that a generic dialog needs of a
109 /** A request to modify the data structures stored by the
110 * accompanying Controller in preparation for their dispatch to
113 virtual void applyView() = 0;
115 /// Hide the dialog from sight
118 /// Create the dialog if necessary, update it and display it.
121 /// Update the display of the dialog whilst it is still visible.
122 virtual void updateView() = 0;
124 // Default Implementation does nothing.
125 // Each dialog has to choose what control to enable or disable.
126 virtual void enableView(bool /*enable*/) {}
128 /// \return true if the dialog is visible.
129 virtual bool isVisibleView() const;
132 /// Dialog identifier.
133 QString name() const { return name_; }
136 /** Enable the controller to initialise its data structures.
137 * \param data is a string encoding of the parameters to be displayed.
138 * \return true if the translation was successful.
140 virtual bool initialiseParams(std::string const & data) = 0;
142 /// Enable the controller to clean up its data structures.
143 virtual void clearParams() = 0;
145 /// Enable the Controller to dispatch its data back to the LyX kernel.
146 virtual void dispatchParams() = 0;
148 /** \return true if the dialog should be shown only when
151 virtual bool isBufferDependent() const = 0;
153 /** \return true if the dialog can apply data also
154 * for ReadOnly buffers.
155 * This has to be distinguished from isBufferDependent()
157 virtual bool canApplyToReadOnly() const { return false; }
159 /** The lfun that is sent for applying the data.
161 * This method is used by the default implementation of canApply()
162 * for buffer dependent dialogs that send one lfun when applying the
164 * It should be used in dispatchParams(), too for consistency reasons.
165 * \returns the lfun that is sent for applying the data.
167 virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
169 /** Check whether we may apply our data.
171 * The default implementation works for all dialogs that send one
172 * lfun when applying the data. Dialogs that send none or more than
173 * one lfun need to reimplement it.
174 * \returns whether the data can be applied or not.
176 virtual bool canApply() const;
178 /** \return true if the kernel should disconnect the dialog from
179 * a particular inset after the data has been applied to it.
180 * Clearly this makes sense only for dialogs modifying the contents
182 * In practise, only a very few dialogs (e.g. the citation dialog)
185 virtual bool disconnectOnApply() const { return false; }
187 /** \return true if Dialog::View::show() should not display the dialog
188 * after running update. Currently, only ControlSpellchecker
191 virtual bool exitEarly() const { return false; }
194 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
195 * (Ie, it provides an interface to the Model part of the Model-Controller-
197 * In an ideal world, it will shrink as more info is passed to the
198 * Dialog::show() and Dialog::update() methods.
202 /** This method is the primary purpose of the class. It provides
203 * the "gateway" by which the dialog can send a request (of a
204 * change in the data, for more information) to the kernel.
205 * \param fr is the encoding of the request.
207 void dispatch(FuncRequest const & fr) const;
209 /** The dialog has received a request from the user
210 * (who pressed the "Restore" button) to update contents.
211 * It must, therefore, ask the kernel to provide this information.
212 * \param name is used to identify the dialog to the kernel.
214 void updateDialog() const;
216 /** A request from the Controller that future changes to the data
217 * stored by the dialog are not applied to the inset currently
218 * connected to the dialog. Instead, they will be used to generate
219 * a new inset at the cursor position.
220 * \param name is used to identify the dialog to the kernel.
222 void disconnect() const;
224 /** \name Kernel Wrappers
225 * Simple wrapper functions to Buffer methods.
228 bool isBufferAvailable() const;
229 bool isBufferReadonly() const;
230 std::string const bufferFilepath() const;
233 /// The type of the current buffer.
234 KernelDocType docType() const;
236 /** \name Kernel Nasties
237 * Unpleasantly public internals of the LyX kernel.
238 * We should aim to reduce/remove these from the interface.
241 GuiView & lyxview() { return *lyxview_; }
242 GuiView const & lyxview() const { return *lyxview_; }
245 Buffer const & buffer() const;
247 BufferView * bufferview();
248 BufferView const * bufferview() const;
253 void setTitle(QString const & title) { title_ = title; }
255 virtual void apply();
258 /** The Dialog's name is the means by which a dialog identifies
259 * itself to the LyXView.
267 /// intentionally unimplemented, therefore uncopiable
268 Dialog(Dialog const &);
269 void operator=(Dialog const &);
274 } // namespace frontend