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.
31 /** \enum KernelDocType used to flag the different kinds of buffer
32 * without making the kernel header files available to the
33 * dialog's Controller or View.
43 /** \c Dialog collects the different parts of a Model-Controller-View
44 * split of a generic dialog together.
49 /// \param lv is the access point for the dialog to the LyX kernel.
50 /// \param name is the identifier given to the dialog by its parent
52 Dialog(GuiView & lv, std::string const & name);
56 virtual QWidget * asQWidget() = 0;
57 virtual QWidget const * asQWidget() const = 0;
59 /** \name Container Access
60 * These methods are publicly accessible because they are invoked
61 * by the parent container acting on commands from the LyX kernel.
64 /// \param data is a string encoding of the data to be displayed.
65 /// It is passed to the Controller to be translated into a useable form.
66 virtual void showData(std::string const & data);
67 virtual void updateData(std::string const & data);
70 /** Check whether we may apply our data.
72 * The buttons are disabled if not and (re-)enabled if yes.
74 virtual void checkStatus();
76 /** When applying, it's useful to know whether the dialog is about
77 * to close or not (no point refreshing the display for example).
79 virtual bool isClosing() const { return false; }
82 * of a Model-Controller-View split of a generic dialog.
83 * These few methods are all that a generic dialog needs of a
87 /** A request to modify the data structures stored by the
88 * accompanying Controller in preparation for their dispatch to
91 virtual void applyView() = 0;
93 /// Hide the dialog from sight
96 /// Create the dialog if necessary, update it and display it.
99 /// Update the display of the dialog whilst it is still visible.
100 virtual void updateView() = 0;
102 // Default Implementation does nothing.
103 // Each dialog has to choose what control to enable or disable.
104 virtual void enableView(bool /*enable*/) {}
106 /// \return true if the dialog is visible.
107 virtual bool isVisibleView() const;
110 /// Dialog identifier.
111 /// FIXME for Andre': Now that Dialog is entirely within qt4/
112 /// We can use QString instead in order to avoid <string> inclusion
113 /// or we can pimpl name_.
114 std::string const & name() const;
117 /** Enable the controller to initialise its data structures.
118 * \param data is a string encoding of the parameters to be displayed.
119 * \return true if the translation was successful.
121 virtual bool initialiseParams(std::string const & data) = 0;
123 /// Enable the controller to clean up its data structures.
124 virtual void clearParams() = 0;
126 /// Enable the Controller to dispatch its data back to the LyX kernel.
127 virtual void dispatchParams() = 0;
129 /** \return true if the dialog should be shown only when
132 virtual bool isBufferDependent() const = 0;
134 /** \return true if the dialog can apply data also
135 * for ReadOnly buffers.
136 * This has to be distinguished from isBufferDependent()
138 virtual bool canApplyToReadOnly() const { return false; }
140 /** The lfun that is sent for applying the data.
142 * This method is used by the default implementation of canApply()
143 * for buffer dependent dialogs that send one lfun when applying the
145 * It should be used in dispatchParams(), too for consistency reasons.
146 * \returns the lfun that is sent for applying the data.
148 virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
150 /** Check whether we may apply our data.
152 * The default implementation works for all dialogs that send one
153 * lfun when applying the data. Dialogs that send none or more than
154 * one lfun need to reimplement it.
155 * \returns whether the data can be applied or not.
157 virtual bool canApply() const;
159 /** \return true if the kernel should disconnect the dialog from
160 * a particular inset after the data has been applied to it.
161 * Clearly this makes sense only for dialogs modifying the contents
163 * In practise, only a very few dialogs (e.g. the citation dialog)
166 virtual bool disconnectOnApply() const { return false; }
168 /** \return true if Dialog::View::show() should not display the dialog
169 * after running update. Currently, only ControlSpellchecker
172 virtual bool exitEarly() const { return false; }
175 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
176 * (Ie, it provides an interface to the Model part of the Model-Controller-
178 * In an ideal world, it will shrink as more info is passed to the
179 * Dialog::show() and Dialog::update() methods.
183 /** This method is the primary purpose of the class. It provides
184 * the "gateway" by which the dialog can send a request (of a
185 * change in the data, for more information) to the kernel.
186 * \param fr is the encoding of the request.
188 void dispatch(FuncRequest const & fr) const;
190 /** The dialog has received a request from the user
191 * (who pressed the "Restore" button) to update contents.
192 * It must, therefore, ask the kernel to provide this information.
193 * \param name is used to identify the dialog to the kernel.
195 void updateDialog() const;
197 /** A request from the Controller that future changes to the data
198 * stored by the dialog are not applied to the inset currently
199 * connected to the dialog. Instead, they will be used to generate
200 * a new inset at the cursor position.
201 * \param name is used to identify the dialog to the kernel.
203 void disconnect() const;
205 /** \name Kernel Wrappers
206 * Simple wrapper functions to Buffer methods.
209 bool isBufferAvailable() const;
210 bool isBufferReadonly() const;
211 std::string const bufferFilepath() const;
214 /// The type of the current buffer.
215 KernelDocType docType() const;
217 /** \name Kernel Nasties
218 * Unpleasantly public internals of the LyX kernel.
219 * We should aim to reduce/remove these from the interface.
222 GuiView & lyxview() { return *lyxview_; }
223 GuiView const & lyxview() const { return *lyxview_; }
226 Buffer const & buffer() const;
228 BufferView * bufferview();
229 BufferView const * bufferview() const;
233 virtual void apply();
236 /** The Dialog's name is the means by which a dialog identifies
237 * itself to the LyXView.
239 std::string const name_;
243 /// intentionally unimplemented, therefore uncopiable
244 Dialog(Dialog const &);
245 void operator=(Dialog const &);
250 } // namespace frontend