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) : lyxview_(&lv) {}
53 /** \name Container Access
54 * These methods are publicly accessible because they are invoked
55 * by the parent container acting on commands from the LyX kernel.
58 /// \param data is a string encoding of the data to be displayed.
59 /// It is passed to the Controller to be translated into a useable form.
60 virtual void showData(std::string const & /*data*/) {}
61 virtual void updateData(std::string const & /*data*/) {}
63 virtual void hide() {}
67 /** Check whether we may apply our data.
69 * The buttons are disabled if not and (re-)enabled if yes.
71 virtual void checkStatus() {}
73 /** When applying, it's useful to know whether the dialog is about
74 * to close or not (no point refreshing the display for example).
76 virtual bool isClosing() const { return false; }
79 /** \c Button controller part
81 virtual void setButtonsValid(bool /*valid*/) {}
85 * of a Model-Controller-View split of a generic dialog.
86 * These few methods are all that a generic dialog needs of a
90 /** A request to modify the data structures stored by the
91 * accompanying Controller in preparation for their dispatch to
94 virtual void applyView() = 0;
96 /// Hide the dialog from sight
97 virtual void hideView() = 0;
99 /// Create the dialog if necessary, update it and display it.
100 virtual void showView() = 0;
102 /// Update the display of the dialog whilst it is still visible.
103 virtual void updateView() = 0;
105 /// \return true if the dialog is visible.
106 virtual bool isVisibleView() const = 0;
110 virtual std::string name() const = 0;
113 /** Enable the controller to initialise its data structures.
114 * \param data is a string encoding of the parameters to be displayed.
115 * \return true if the translation was successful.
117 virtual bool initialiseParams(std::string const & data) = 0;
119 /// Enable the controller to clean up its data structures.
120 virtual void clearParams() = 0;
122 /// Enable the Controller to dispatch its data back to the LyX kernel.
123 virtual void dispatchParams() = 0;
125 /** \return true if the dialog should be shown only when
128 virtual bool isBufferDependent() const = 0;
130 /** \return true if the dialog can apply data also
131 * for ReadOnly buffers.
132 * This has to be distinguished from isBufferDependent()
134 virtual bool canApplyToReadOnly() const { return false; }
136 /** The lfun that is sent for applying the data.
138 * This method is used by the default implementation of canApply()
139 * for buffer dependent dialogs that send one lfun when applying the
141 * It should be used in dispatchParams(), too for consistency reasons.
142 * \returns the lfun that is sent for applying the data.
144 virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
146 /** Check whether we may apply our data.
148 * The default implementation works for all dialogs that send one
149 * lfun when applying the data. Dialogs that send none or more than
150 * one lfun need to reimplement it.
151 * \returns whether the data can be applied or not.
153 virtual bool canApply() const;
155 /** \return true if the kernel should disconnect the dialog from
156 * a particular inset after the data has been applied to it.
157 * Clearly this makes sense only for dialogs modifying the contents
159 * In practise, only a very few dialogs (e.g. the citation dialog)
162 virtual bool disconnectOnApply() const { return false; }
164 /** \return true if Dialog::View::show() should not display the dialog
165 * after running update. Currently, only ControlSpellchecker
168 virtual bool exitEarly() const { return false; }
171 /** \c Kernel part: a wrapper making the LyX kernel available to the dialog.
172 * (Ie, it provides an interface to the Model part of the Model-Controller-
174 * In an ideal world, it will shrink as more info is passed to the
175 * Dialog::show() and Dialog::update() methods.
179 /** This method is the primary purpose of the class. It provides
180 * the "gateway" by which the dialog can send a request (of a
181 * change in the data, for more information) to the kernel.
182 * \param fr is the encoding of the request.
184 void dispatch(FuncRequest const & fr) const;
186 /** The dialog has received a request from the user
187 * (who pressed the "Restore" button) to update contents.
188 * It must, therefore, ask the kernel to provide this information.
189 * \param name is used to identify the dialog to the kernel.
191 void updateDialog(std::string const & name) const;
193 /** A request from the Controller that future changes to the data
194 * stored by the dialog are not applied to the inset currently
195 * connected to the dialog. Instead, they will be used to generate
196 * a new inset at the cursor position.
197 * \param name is used to identify the dialog to the kernel.
199 void disconnect(std::string const & name) const;
201 /** \name Kernel Wrappers
202 * Simple wrapper functions to Buffer methods.
205 bool isBufferAvailable() const;
206 bool isBufferReadonly() const;
207 std::string const bufferFilepath() const;
210 /// The type of the current buffer.
211 KernelDocType docType() const;
213 /** \name Kernel Nasties
214 * Unpleasantly public internals of the LyX kernel.
215 * We should aim to reduce/remove these from the interface.
218 GuiView & lyxview() { return *lyxview_; }
219 GuiView const & lyxview() const { return *lyxview_; }
222 Buffer const & buffer() const;
224 BufferView * bufferview();
225 BufferView const * bufferview() const;
229 virtual void apply() {}
235 /// intentionally unimplemented, therefore uncopiable
236 Dialog(Dialog const &);
237 void operator=(Dialog const &);
242 } // namespace frontend