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.
16 #include "ButtonController.h"
18 #include "insets/InsetCommandParams.h"
29 /** \c Dialog collects the different parts of a Model-Controller-View
30 * split of a generic dialog together.
32 class GuiDialog : public QDialog, public Dialog
37 /// \param lv is the access point for the dialog to the LyX kernel.
38 /// \param name is the identifier given to the dialog by its parent
40 explicit GuiDialog(LyXView & lv, std::string const & name);
45 * These methods are publicly accessible because they are invoked
46 * by the View when the user presses... guess what ;-)
48 // Restore button clicked
52 // Apply button clicked
54 // Close button clicked or closed from WindowManager
58 /** Check whether we may apply our data.
60 * The buttons are disabled if not and (re-)enabled if yes.
63 void setButtonsValid(bool valid);
65 /** \name Dialog Components
66 * Methods to access the various components making up a dialog.
69 ButtonController const & bc() const { return bc_; }
70 ButtonController & bc() { return bc_; }
73 void setViewTitle(docstring const & title);
76 /// the dialog has changed contents
77 virtual void changed();
79 /// default: do nothing
80 virtual void applyView() {}
81 /// default: do nothing
82 virtual void updateContents() {}
84 void closeEvent(QCloseEvent *);
86 void showEvent(QShowEvent *);
90 virtual void hideView();
91 /// Create the dialog if necessary, update it and display it.
92 virtual void showView();
94 virtual bool isVisibleView() const;
95 /// is the dialog currently valid ?
96 virtual bool isValid() { return true; }
99 /** \name Container Access
100 * These methods are publicly accessible because they are invoked
101 * by the parent container acting on commands from the LyX kernel.
104 /// \param data is a string encoding of the data to be displayed.
105 /// It is passed to the Controller to be translated into a useable form.
106 void showData(std::string const & data);
107 void updateData(std::string const & data);
111 /** This function is called, for example, if the GUI colours
114 void redraw() { redrawView(); }
117 /** When applying, it's useful to know whether the dialog is about
118 * to close or not (no point refreshing the display for example).
120 bool isClosing() const { return is_closing_; }
122 /** \name Dialog Specialization
123 * Methods to set the Controller and View and so specialise
124 * to a particular dialog.
127 /// \param ptr is stored and destroyed by \c Dialog.
128 void setController(Controller * ptr, bool destroy = true);
131 /** \name Dialog Components
132 * Methods to access the various components making up a dialog.
135 virtual Controller & controller() { return *controller_; }
138 /** Defaults to nothing. Can be used by the Controller, however, to
139 * indicate to the View that something has changed and that the
140 * dialog therefore needs updating.
141 * \param id identifies what should be updated.
143 virtual void partialUpdateView(int /*id*/) {}
146 std::string name() const { return name_; }
152 /// Update the display of the dialog whilst it is still visible.
153 virtual void updateView();
155 ButtonController bc_;
156 /// are we updating ?
160 /** The Dialog's name is the means by which a dialog identifies
161 * itself to the kernel.
164 Controller * controller_;
165 bool destroy_controller_;
166 LyXView * lyxview_; // FIXME: replace by moving to constructor
170 class GuiCommand : public GuiDialog, public Controller
173 /// We need to know with what sort of inset we're associated.
174 GuiCommand(LyXView &, std::string const & name);
176 bool initialiseParams(std::string const & data);
177 /// clean-up on hide.
178 void clearParams() { params_.clear(); }
179 /// clean-up on hide.
180 void dispatchParams();
182 bool isBufferDependent() const { return true; }
186 InsetCommandParams params_;
187 //FIXME It should be possible to eliminate lfun_name_
188 //now and recover that information from params().insetType().
189 //But let's not do that quite yet.
190 /// Flags what action is taken by Kernel::dispatch()
191 std::string const lfun_name_;
194 } // namespace frontend
197 #endif // GUIDIALOG_H