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 "support/docstring.h"
30 /** \enum KernelDocType used to flag the different kinds of buffer
31 * without making the kernel header files available to the
32 * dialog's Controller or View.
42 /** \c Dialog collects the different parts of a Model-Controller-View
43 * split of a generic dialog together.
48 /// \param lv is the access point for the dialog to the LyX kernel.
49 /// \param name is the identifier given to the dialog by its parent
51 Dialog(LyXView & lv) : lyxview_(&lv) {}
54 /** \name Container Access
55 * These methods are publicly accessible because they are invoked
56 * by the parent container acting on commands from the LyX kernel.
59 /// \param data is a string encoding of the data to be displayed.
60 /// It is passed to the Controller to be translated into a useable form.
61 virtual void showData(std::string const & /*data*/) {}
62 virtual void updateData(std::string const & /*data*/) {}
64 virtual void hide() {}
66 // Override in GuiDialog
67 virtual void slotOK() {}
68 virtual void slotApply() {}
69 virtual void slotRestore() {}
70 virtual void slotClose() {}
72 /** This function is called, for example, if the GUI colours
75 virtual void redraw() {}
78 /** Check whether we may apply our data.
80 * The buttons are disabled if not and (re-)enabled if yes.
82 virtual void checkStatus() {}
84 /** When applying, it's useful to know whether the dialog is about
85 * to close or not (no point refreshing the display for example).
87 virtual bool isClosing() const { return false; }
90 /** \c Button controller part
92 virtual void setButtonsValid(bool /*valid*/) {}
96 * of a Model-Controller-View split of a generic dialog.
97 * These few methods are all that a generic dialog needs of a
101 /** A request to modify the data structures stored by the
102 * accompanying Controller in preparation for their dispatch to
105 virtual void applyView() = 0;
107 /// Hide the dialog from sight
108 virtual void hideView() = 0;
110 /// Redraw the dialog (e.g. if the colors have been remapped).
111 virtual void redrawView() = 0;
113 /// Create the dialog if necessary, update it and display it.
114 virtual void showView() = 0;
116 /// Update the display of the dialog whilst it is still visible.
117 virtual void updateView() = 0;
119 /// \return true if the dialog is visible.
120 virtual bool isVisibleView() const = 0;
123 /** Defaults to nothing. Can be used by the Controller, however, to
124 * indicate to the View that something has changed and that the
125 * dialog therefore needs updating.
126 * \param id identifies what should be updated.
128 virtual void partialUpdateView(int /*id*/) = 0;
131 virtual std::string name() const = 0;
134 /** Enable the controller to initialise its data structures.
135 * \param data is a string encoding of the parameters to be displayed.
136 * \return true if the translation was successful.
138 virtual bool initialiseParams(std::string const & data) = 0;
140 /// Enable the controller to clean up its data structures.
141 virtual void clearParams() = 0;
143 /// Enable the Controller to dispatch its data back to the LyX kernel.
144 virtual void dispatchParams() = 0;
146 /** \return true if the dialog should be shown only when
149 virtual bool isBufferDependent() const = 0;
151 /** \return true if the dialog can apply data also
152 * for ReadOnly buffers.
153 * This has to be distinguished from isBufferDependent()
155 virtual bool canApplyToReadOnly() const { return false; }
157 /** The lfun that is sent for applying the data.
159 * This method is used by the default implementation of canApply()
160 * for buffer dependent dialogs that send one lfun when applying the
162 * It should be used in dispatchParams(), too for consistency reasons.
163 * \returns the lfun that is sent for applying the data.
165 virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
167 /** Check whether we may apply our data.
169 * The default implementation works for all dialogs that send one
170 * lfun when applying the data. Dialogs that send none or more than
171 * one lfun need to reimplement it.
172 * \returns whether the data can be applied or not.
174 virtual bool canApply() const;
176 /** \return true if the kernel should disconnect the dialog from
177 * a particular inset after the data has been applied to it.
178 * Clearly this makes sense only for dialogs modifying the contents
180 * In practise, only a very few dialogs (e.g. the citation dialog)
183 virtual bool disconnectOnApply() const { return false; }
185 /** \return true if Dialog::View::show() should not display the dialog
186 * after running update. Currently, only ControlSpellchecker
189 virtual bool exitEarly() const { return false; }
192 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
193 * (Ie, it provides an interface to the Model part of the Model-Controller-
195 * In an ideal world, it will shrink as more info is passed to the
196 * Dialog::show() and Dialog::update() methods.
200 /** This method is the primary purpose of the class. It provides
201 * the "gateway" by which the dialog can send a request (of a
202 * change in the data, for more information) to the kernel.
203 * \param fr is the encoding of the request.
205 void dispatch(FuncRequest const & fr) const;
207 /** The dialog has received a request from the user
208 * (who pressed the "Restore" button) to update contents.
209 * It must, therefore, ask the kernel to provide this information.
210 * \param name is used to identify the dialog to the kernel.
212 void updateDialog(std::string const & name) const;
214 /** A request from the Controller that future changes to the data
215 * stored by the dialog are not applied to the inset currently
216 * connected to the dialog. Instead, they will be used to generate
217 * a new inset at the cursor position.
218 * \param name is used to identify the dialog to the kernel.
220 void disconnect(std::string const & name) const;
222 /** \name Kernel Wrappers
223 * Simple wrapper functions to Buffer methods.
226 bool isBufferAvailable() const;
227 bool isBufferReadonly() const;
228 std::string const bufferFilepath() const;
231 /// The type of the current buffer.
232 KernelDocType docType() const;
234 /** \name Kernel Nasties
235 * Unpleasantly public internals of the LyX kernel.
236 * We should aim to reduce/remove these from the interface.
239 LyXView & lyxview() { return *lyxview_; }
240 LyXView const & lyxview() const { return *lyxview_; }
243 Buffer const & buffer() const;
245 BufferView * bufferview();
246 BufferView const * bufferview() const;
250 virtual void apply() {}
256 /// intentionally unimplemented, therefore uncopiable
257 Dialog(Dialog const &);
258 void operator=(Dialog const &);
263 } // namespace frontend