3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
15 #include "ButtonController.h"
18 #include "frontends/LyXView.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
30 Dialog::Dialog(LyXView & lv, string const & name)
31 : is_closing_(false), kernel_(lv), name_(name),
32 bc_ptr_(new ButtonController)
36 void Dialog::ApplyButton()
43 void Dialog::OKButton()
53 void Dialog::CancelButton()
60 void Dialog::RestoreButton()
62 // Tell the kernel that a request to refresh the dialog's contents
63 // has been received. It's up to the kernel to supply the necessary
64 // info by calling Dialog::update().
65 kernel().updateDialog(name_);
70 void Dialog::show(string const & data)
72 if (controller().isBufferDependent() && !kernel().isBufferAvailable())
75 if (!controller().initialiseParams(data)) {
76 lyxerr << "Dialog \"" << name_
77 << "\" failed to translate the data "
78 "string passed to show()" << std::endl;
82 bc().readOnly(kernel().isBufferReadonly());
85 // The widgets may not be valid, so refresh the button controller
90 void Dialog::update(string const & data)
92 if (controller().isBufferDependent() && !kernel().isBufferAvailable())
95 if (!controller().initialiseParams(data)) {
96 lyxerr << "Dialog \"" << name_
97 << "\" could not be initialized" << std::endl;
101 bc().readOnly(kernel().isBufferReadonly());
104 // The widgets may not be valid, so refresh the button controller
111 if (!view().isVisible())
114 controller().clearParams();
116 kernel().disconnect(name());
122 if (controller().isBufferDependent()) {
123 if (!kernel().isBufferAvailable() ||
124 (kernel().isBufferReadonly() &&
125 !controller().canApplyToReadOnly()))
130 controller().dispatchParams();
132 if (controller().disconnectOnApply() && !is_closing_) {
133 kernel().disconnect(name());
134 controller().initialiseParams(string());
140 bool Dialog::isVisible() const
142 return view().isVisible();
146 void Dialog::redraw()
152 ButtonController & Dialog::bc() const
154 BOOST_ASSERT(bc_ptr_.get());
155 return *bc_ptr_.get();
159 void Dialog::setController(Controller * i)
161 BOOST_ASSERT(i && !controller_ptr_.get());
162 controller_ptr_.reset(i);
166 void Dialog::setView(View * v)
168 BOOST_ASSERT(v && !view_ptr_.get());
173 void Dialog::checkStatus()
175 // buffer independant dialogs are always active.
176 // This check allows us leave canApply unimplemented for some dialogs.
177 if (!controller().isBufferDependent())
180 // deactivate the dialog if we have no buffer
181 if (!kernel().isBufferAvailable()) {
186 // check whether this dialog may be active
187 if (controller().canApply()) {
188 bool const readonly = kernel().isBufferReadonly();
189 bc().readOnly(readonly);
190 // refreshReadOnly() is too generous in _enabling_ widgets
191 // update dialog to disable disabled widgets again
192 if (!readonly || controller().canApplyToReadOnly())
199 Dialog::Controller::Controller(Dialog & parent)
204 bool Dialog::Controller::canApply() const
206 FuncRequest const fr(getLfun(), dialog().name());
207 FuncStatus const fs(getStatus(fr));
212 Dialog::Controller & Dialog::controller() const
214 BOOST_ASSERT(controller_ptr_.get());
215 return *controller_ptr_.get();
219 Dialog::View::View(Dialog & parent, docstring title) :
220 p_(parent), title_(title)
224 Dialog::View & Dialog::view() const
226 BOOST_ASSERT(view_ptr_.get());
227 return *view_ptr_.get();
231 void Dialog::View::setTitle(docstring const & newtitle)
237 docstring const & Dialog::View::getTitle() const
243 void Dialog::View::partialUpdate(int)
246 } // namespace frontend