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/strfwd.h"
29 /** \enum KernelDocType used to flag the different kinds of buffer
30 * without making the kernel header files available to the
31 * dialog's Controller or View.
41 /** \c Dialog collects the different parts of a Model-Controller-View
42 * split of a generic dialog together.
47 /// \param lv is the access point for the dialog to the LyX kernel.
48 /// \param name is the identifier given to the dialog by its parent
50 Dialog(GuiView & lv, std::string const & name);
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() {}
68 /** Check whether we may apply our data.
70 * The buttons are disabled if not and (re-)enabled if yes.
72 virtual void checkStatus() {}
74 /** When applying, it's useful to know whether the dialog is about
75 * to close or not (no point refreshing the display for example).
77 virtual bool isClosing() const { return false; }
80 /** \c Button controller part
82 virtual void setButtonsValid(bool /*valid*/) {}
86 * of a Model-Controller-View split of a generic dialog.
87 * These few methods are all that a generic dialog needs of a
91 /** A request to modify the data structures stored by the
92 * accompanying Controller in preparation for their dispatch to
95 virtual void applyView() = 0;
97 /// Hide the dialog from sight
98 virtual void hideView() = 0;
100 /// Create the dialog if necessary, update it and display it.
101 virtual void showView() = 0;
103 /// Update the display of the dialog whilst it is still visible.
104 virtual void updateView() = 0;
106 /// \return true if the dialog is visible.
107 virtual bool isVisibleView() const = 0;
111 std::string name() const;
114 /** Enable the controller to initialise its data structures.
115 * \param data is a string encoding of the parameters to be displayed.
116 * \return true if the translation was successful.
118 virtual bool initialiseParams(std::string const & data) = 0;
120 /// Enable the controller to clean up its data structures.
121 virtual void clearParams() = 0;
123 /// Enable the Controller to dispatch its data back to the LyX kernel.
124 virtual void dispatchParams() = 0;
126 /** \return true if the dialog should be shown only when
129 virtual bool isBufferDependent() const = 0;
131 /** \return true if the dialog can apply data also
132 * for ReadOnly buffers.
133 * This has to be distinguished from isBufferDependent()
135 virtual bool canApplyToReadOnly() const { return false; }
137 /** The lfun that is sent for applying the data.
139 * This method is used by the default implementation of canApply()
140 * for buffer dependent dialogs that send one lfun when applying the
142 * It should be used in dispatchParams(), too for consistency reasons.
143 * \returns the lfun that is sent for applying the data.
145 virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
147 /** Check whether we may apply our data.
149 * The default implementation works for all dialogs that send one
150 * lfun when applying the data. Dialogs that send none or more than
151 * one lfun need to reimplement it.
152 * \returns whether the data can be applied or not.
154 virtual bool canApply() const;
156 /** \return true if the kernel should disconnect the dialog from
157 * a particular inset after the data has been applied to it.
158 * Clearly this makes sense only for dialogs modifying the contents
160 * In practise, only a very few dialogs (e.g. the citation dialog)
163 virtual bool disconnectOnApply() const { return false; }
165 /** \return true if Dialog::View::show() should not display the dialog
166 * after running update. Currently, only ControlSpellchecker
169 virtual bool exitEarly() const { return false; }
172 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
173 * (Ie, it provides an interface to the Model part of the Model-Controller-
175 * In an ideal world, it will shrink as more info is passed to the
176 * Dialog::show() and Dialog::update() methods.
180 /** This method is the primary purpose of the class. It provides
181 * the "gateway" by which the dialog can send a request (of a
182 * change in the data, for more information) to the kernel.
183 * \param fr is the encoding of the request.
185 void dispatch(FuncRequest const & fr) const;
187 /** The dialog has received a request from the user
188 * (who pressed the "Restore" button) to update contents.
189 * It must, therefore, ask the kernel to provide this information.
190 * \param name is used to identify the dialog to the kernel.
192 void updateDialog() const;
194 /** A request from the Controller that future changes to the data
195 * stored by the dialog are not applied to the inset currently
196 * connected to the dialog. Instead, they will be used to generate
197 * a new inset at the cursor position.
198 * \param name is used to identify the dialog to the kernel.
200 void disconnect() const;
202 /** \name Kernel Wrappers
203 * Simple wrapper functions to Buffer methods.
206 bool isBufferAvailable() const;
207 bool isBufferReadonly() const;
208 std::string const bufferFilepath() const;
211 /// The type of the current buffer.
212 KernelDocType docType() const;
214 /** \name Kernel Nasties
215 * Unpleasantly public internals of the LyX kernel.
216 * We should aim to reduce/remove these from the interface.
219 GuiView & lyxview() { return *lyxview_; }
220 GuiView const & lyxview() const { return *lyxview_; }
223 Buffer const & buffer() const;
225 BufferView * bufferview();
226 BufferView const * bufferview() const;
230 virtual void apply() {}
233 /** The Dialog's name is the means by which a dialog identifies
234 * itself to the LyXView.
236 char const * const name_;
240 /// intentionally unimplemented, therefore uncopiable
241 Dialog(Dialog const &);
242 void operator=(Dialog const &);
247 } // namespace frontend