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)
40 void Dialog::ApplyButton()
47 void Dialog::OKButton()
57 void Dialog::CancelButton()
64 void Dialog::RestoreButton()
66 // Tell the kernel that a request to refresh the dialog's contents
67 // has been received. It's up to the kernel to supply the necessary
68 // info by calling Dialog::update().
69 kernel().updateDialog(name_);
74 void Dialog::show(string const & data)
76 if (controller().isBufferDependent() && !kernel().isBufferAvailable())
79 if (!controller().initialiseParams(data)) {
80 lyxerr << "Dialog \"" << name_
81 << "\" failed to translate the data "
82 "string passed to show()" << std::endl;
86 bc().readOnly(kernel().isBufferReadonly());
89 // The widgets may not be valid, so refresh the button controller
94 void Dialog::update(string const & data)
96 if (controller().isBufferDependent() && !kernel().isBufferAvailable())
99 if (!controller().initialiseParams(data)) {
100 lyxerr << "Dialog \"" << name_
101 << "\" could not be initialized" << std::endl;
105 bc().readOnly(kernel().isBufferReadonly());
108 // The widgets may not be valid, so refresh the button controller
115 if (!view().isVisible())
118 controller().clearParams();
120 kernel().disconnect(name());
126 if (controller().isBufferDependent()) {
127 if (!kernel().isBufferAvailable() ||
128 kernel().isBufferReadonly())
133 controller().dispatchParams();
135 if (controller().disconnectOnApply() && !is_closing_) {
136 kernel().disconnect(name());
137 controller().initialiseParams(string());
143 bool Dialog::isVisible() const
145 return view().isVisible();
149 void Dialog::redraw()
155 ButtonController & Dialog::bc() const
157 BOOST_ASSERT(bc_ptr_.get());
158 return *bc_ptr_.get();
162 void Dialog::setController(Controller * i)
164 BOOST_ASSERT(i && !controller_ptr_.get());
165 controller_ptr_.reset(i);
169 void Dialog::setView(View * v)
171 BOOST_ASSERT(v && !view_ptr_.get());
176 void Dialog::checkStatus()
178 // buffer independant dialogs are always active.
179 // This check allows us leave canApply unimplemented for some dialogs.
180 if (!controller().isBufferDependent())
183 // deactivate the dialog if we have no buffer
184 if (!kernel().isBufferAvailable()) {
189 // check whether this dialog may be active
190 if (controller().canApply()) {
191 bool const readonly = kernel().isBufferReadonly();
192 bc().readOnly(readonly);
193 // refreshReadOnly() is too generous in _enabling_ widgets
194 // update dialog to disable disabled widgets again
202 Dialog::Controller::Controller(Dialog & parent)
207 bool Dialog::Controller::canApply() const
209 FuncRequest const fr(getLfun(), dialog().name());
210 FuncStatus const fs(kernel().lyxview().getLyXFunc().getStatus(fr));
215 Dialog::Controller & Dialog::controller() const
217 BOOST_ASSERT(controller_ptr_.get());
218 return *controller_ptr_.get();
222 Dialog::View::View(Dialog & parent, string title) :
223 p_(parent), title_(title)
227 Dialog::View & Dialog::view() const
229 BOOST_ASSERT(view_ptr_.get());
230 return *view_ptr_.get();
234 void Dialog::View::setTitle(string const & newtitle)
240 string const & Dialog::View::getTitle() const
246 void Dialog::View::partialUpdate(int)
249 } // namespace frontend